Skip to content

Commit

Permalink
feat(notification): add enotify sieve script
Browse files Browse the repository at this point in the history
  • Loading branch information
QHivert committed Aug 29, 2023
1 parent 4f7c731 commit 82b69d1
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 21 deletions.
7 changes: 7 additions & 0 deletions Documentation/SOGoInstallationGuide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,13 @@ SOGoForwardConstraintsDomains = ("gmail.com", "googlemail.com");
will allow users to forward emails to only `gmail.com` and `googlemail.com` domains.
When empty or undefined, no constraints are imposed.
|D |SOGoNotificationEnabled
|Parameter used to activate the edition from the preferences window of
notifications for emails. Requires Sieve script support on the IMAP
host.
Defaults to `NO` when unset.
|D |SOGoSieveScriptsEnabled
|Parameter used to activate the edition from the preferences windows of
server-side mail filters. Requires Sieve script support on the IMAP
Expand Down
1 change: 1 addition & 0 deletions SoObjects/SOGo/SOGoDomainDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- (BOOL) forwardEnabled;
- (int) forwardConstraints;
- (NSArray *) forwardConstraintsDomains;
- (BOOL) notificationEnabled;
- (BOOL) vacationEnabled;
- (BOOL) vacationPeriodEnabled;
- (NSString *) vacationDefaultSubject;
Expand Down
5 changes: 5 additions & 0 deletions SoObjects/SOGo/SOGoDomainDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ - (NSArray *) forwardConstraintsDomains
return [self stringArrayForKey: @"SOGoForwardConstraintsDomains"];
}

- (BOOL) notificationEnabled
{
return [self boolForKey: @"SOGoNotificationEnabled"];
}

- (BOOL) vacationEnabled
{
return [self boolForKey: @"SOGoVacationEnabled"];
Expand Down
44 changes: 42 additions & 2 deletions SoObjects/SOGo/SOGoSieveManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ + (void) initialize
@"imapflags", @"removeflag",
@"imapflags", @"flag",
@"vacation", @"vacation",
@"notify", @"notify",
@"notify", @"enotify",
@"fileinto", @"fileinto",
@"reject", @"reject",
@"regex", @"regex",
Expand Down Expand Up @@ -543,6 +543,12 @@ - (NSString *) _extractSieveAction: (NSDictionary *) action
else if ([method isEqualToString: @"redirect"])
sieveAction = [NSString stringWithFormat: @"%@ %@",
method, [argument asSieveQuotedString]];
else if ([method isEqualToString: @"notify"])
{
argument = [NSString stringWithFormat: @"mailto:%@", argument];
sieveAction = [NSString stringWithFormat: @"%@ %@",
method, [argument asSieveQuotedString]];
}
else if ([method isEqualToString: @"reject"])
sieveAction = [NSString stringWithFormat: @"%@ %@",
method, [argument asSieveQuotedString]];
Expand Down Expand Up @@ -863,7 +869,7 @@ - (NSException *) updateFiltersForAccount: (SOGoMailAccount *) theAccount

error = nil;
dd = [user domainDefaults];
if (!([dd sieveScriptsEnabled] || [dd vacationEnabled] || [dd forwardEnabled]))
if (!([dd sieveScriptsEnabled] || [dd vacationEnabled] || [dd forwardEnabled] || [dd notificationEnabled]))
return error;

req = [NSMutableArray arrayWithCapacity: 15];
Expand Down Expand Up @@ -1207,6 +1213,40 @@ - (NSException *) updateFiltersForAccount: (SOGoMailAccount *) theAccount
}
}

// We handle mail notification
values = [ud notificationOptions];

if (values && [[values objectForKey: @"enabled"] boolValue])
{
// BOOL alwaysSend;
NSString *notify;
id addresses;
int i;

// alwaysSend = [[values objectForKey: @"alwaysSend"] boolValue];
b = YES;

[req addObjectUniquely: @"enotify"];

addresses = [values objectForKey: @"notificationAddress"];
if ([addresses isKindOfClass: [NSString class]])
addresses = [addresses componentsSeparatedByString: @","];

for (i = 0; i < [addresses count]; i++)
{
v = [addresses objectAtIndex: i];
if (v && [v length] > 0)
{
notify = [NSString stringWithFormat: @"notify \"mailto:%@\";\r\n", v];

// if (alwaysSend)
// [script insertString: notify atIndex: 0];
// else
[script appendString: notify];
}
}
}

// We handle header/footer Sieve scripts
if ((v = [dd sieveScriptHeaderTemplateFile]))
{
Expand Down
3 changes: 3 additions & 0 deletions SoObjects/SOGo/SOGoUserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ extern NSString *SOGoPasswordRecoverySecondaryEmail;
- (void) setForwardOptions: (NSDictionary *) newValue;
- (NSDictionary *) forwardOptions;

- (void) setNotificationOptions: (NSDictionary *) newValue;
- (NSDictionary *) notificationOptions;

- (void) setMailLabelsColors: (NSDictionary *) newValues;
- (NSDictionary *) mailLabelsColors;

Expand Down
10 changes: 10 additions & 0 deletions SoObjects/SOGo/SOGoUserDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,16 @@ - (NSDictionary *) forwardOptions
return [self dictionaryForKey: @"Forward"];
}

- (void) setNotificationOptions: (NSDictionary *) newValue
{
[self setObject: newValue forKey: @"Notification"];
}

- (NSDictionary *) notificationOptions
{
return [self dictionaryForKey: @"Notification"];
}

- (void) setContactsCategories: (NSArray *) newValues
{
[self setObject: newValues forKey: @"SOGoContactsCategories"];
Expand Down
4 changes: 4 additions & 0 deletions UI/PreferencesUI/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
"You are not allowed to forward your messages to an internal email address." = "You are not allowed to forward your messages to an internal email address.";
"You are not allowed to forward your messages to this domain:" = "You are not allowed to forward your messages to this domain:";

/* notification */
"Notify incoming messsages" = "Notify incoming messsages";

/* d & t */
"Time Zone" = "Time Zone";
"Short Date Format" = "Short Date Format";
Expand Down Expand Up @@ -411,6 +414,7 @@

"Keep the message" = "Keep the message";
"Forward the message to" = "Forward the message to";
"Notify the message to" = "Notify the message to";

/* Input field label of "forward" mail filter action */
"Email" = "Email";
Expand Down
6 changes: 5 additions & 1 deletion UI/PreferencesUI/French.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
= "La date de fin de la réponse automatique doit être dans le futur.";

/* forward messages */
"Forward incoming messages" = "Transférer les messages entrant";
"Forward incoming messages" = "Transférer les messages entrants";
"Always forward" = "Toujours transférer";
"Incoming messages are forwarded prior to apply your filters." = "Le courrier entrant est transféré d'appliquer vos filtres.";
"Keep a copy" = "Garder une copie";
Expand All @@ -80,6 +80,9 @@
"You are not allowed to forward your messages to an internal email address." = "Il est interdit de renvoyer vos messages vers une adresse interne.";
"You are not allowed to forward your messages to this domain:" = "Vous ne pouvez pas transférer vos messages à ce domaine :";

/* notify messages */
"Notify incoming messsages" = "Notifier les messages entrants";

/* d & t */
"Time Zone" = "Fuseau horaire";
"Short Date Format" = "Style de date courte";
Expand Down Expand Up @@ -411,6 +414,7 @@

"Keep the message" = "Conserver le message";
"Forward the message to" = "Faire suivre le message à";
"Notify the message to" = "Notifier le message à";

/* Input field label of "forward" mail filter action */
"Email" = "Email";
Expand Down
11 changes: 8 additions & 3 deletions UI/PreferencesUI/UIxJSONPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,14 @@ - (NSString *) jsonDefaults
}

if ([domainDefaults forwardEnabled] && ![defaults forwardOptions])
{
[defaults setForwardOptions: [NSDictionary new]];
}
{
[defaults setForwardOptions: [NSDictionary new]];
}

if ([domainDefaults notificationEnabled] && ![defaults notificationOptions])
{
[defaults setNotificationOptions: [NSDictionary new]];
}

if ([[defaults source] dirty])
[defaults synchronize];
Expand Down
2 changes: 1 addition & 1 deletion UI/PreferencesUI/UIxPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Sieve filtering
NSArray *daysOfWeek, *daysBetweenResponsesList;
NSArray *sieveFilters;
NSMutableDictionary *vacationOptions, *forwardOptions;
NSMutableDictionary *vacationOptions, *forwardOptions, *notificationOptions;

BOOL mailCustomFromEnabled;
BOOL forwardEnabled;
Expand Down
22 changes: 20 additions & 2 deletions UI/PreferencesUI/UIxPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,20 @@ - (id) init
vacationOptions = [NSMutableDictionary new];
}

if ([dd forwardEnabled])
if ([dd forwardEnabled])
{
forwardOptions = [[userDefaults forwardOptions] mutableCopy];
if (!forwardOptions)
forwardOptions = [NSMutableDictionary new];
}

if ([dd notificationEnabled])
{
notificationOptions = [[userDefaults notificationOptions] mutableCopy];
if (!notificationOptions)
notificationOptions = [NSMutableDictionary new];
}

mailCustomFromEnabled = [dd mailCustomFromEnabled];
forwardEnabled = [dd forwardEnabled];

Expand All @@ -160,6 +167,7 @@ - (void) dealloc
[sieveFilters release];
[vacationOptions release];
[forwardOptions release];
[notificationOptions release];
[daysOfWeek release];
[addressBooksIDWithDisplayName release];
[client release];
Expand Down Expand Up @@ -989,6 +997,15 @@ - (NSString *) forwardConstraintsDomains
return [domains jsonRepresentation];
}

/* mail notifications */
//
// Used by templates
//
- (BOOL) isNotificationEnabled
{
return [[user domainDefaults] notificationEnabled];
}

//
// Used by templates
//
Expand Down Expand Up @@ -1727,7 +1744,8 @@ - (NSString *) forwardEnabled
dd = [[context activeUser] domainDefaults];

// We check if the Sieve server is available *ONLY* if at least one of the option is enabled
if (!([dd sieveScriptsEnabled] || [dd vacationEnabled] || [dd forwardEnabled]) || [self _isSieveServerAvailable])
if (([dd sieveScriptsEnabled] || [dd vacationEnabled] || [dd forwardEnabled] || [dd notificationEnabled])
|| [self _isSieveServerAvailable])
{
BOOL forceActivation = ![[v objectForKey: @"hasActiveExternalSieveScripts"] boolValue];

Expand Down
6 changes: 6 additions & 0 deletions UI/Templates/PreferencesUI/UIxFilterEditor.wox
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
<input type="text" ng-model="action.argument" required="required"/>
</md-input-container>

<!-- NOTIFY MESSAGE TO -->
<md-input-container class="md-block" flex="50" ng-if="action.method == 'notify'" >
<label><var:string label:value="Email"/></label>
<input type="text" ng-model="action.argument" required="required"/>
</md-input-container>

<!-- DISCARD -->
<!-- nada -->

Expand Down
75 changes: 68 additions & 7 deletions UI/Templates/PreferencesUI/UIxPreferences.wox
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script type="text/javascript">
var mailCustomFromEnabled = <var:string value="mailCustomFromEnabled" const:escapeHTML="NO"/>;
var forwardEnabled = <var:string value="forwardEnabled" const:escapeHTML="NO"/>;
var notificationEnabled = <var:string value="notificationEnabled" const:escapeHTML="NO"/>;
var vacationEnabled = <var:string value="isVacationEnabled" const:escapeHTML="NO"/>;
var timeZonesList = <var:string value="timeZonesList" const:escapeHTML="NO"/>;
var defaultEmailAddresses = <var:string value="defaultEmailAddresses" const:escapeHTML="NO"/>;
Expand Down Expand Up @@ -1325,7 +1326,7 @@
id="forwardAddress"
name="forwardAddress"
ng-model="app.preferences.defaults.Forward.forwardAddress"
md-transform-chip="app.addRecipient($chip)"
md-transform-chip="app.addRecipient($chip, 'forward')"
ng-required="app.preferences.defaults.Forward.enabled == 1"
md-separator-keys="app.emailSeparatorKeys"
md-add-on-blur="true"
Expand All @@ -1334,10 +1335,9 @@
<md-autocomplete
ng-keydown="app.ignoreReturn($event)"
md-menu-class="md-2-line"
md-search-text="app.autocompleteForward.searchText"
md-selected-item="app.autocompleteForward.selected"
md-items="user in app.contactFilter(app.autocompleteForward.searchText)"
md-item-text="app.addRecipient(user)"
md-search-text="app.autocomplete.forward.searchText"
md-selected-item="app.autocomplete.forward.selected"
md-items="user in app.contactFilter(app.autocomplete.forward.searchText)"
var:md-min-length="minimumSearchLength"
md-delay="150"
md-no-cache="true"
Expand All @@ -1346,8 +1346,8 @@
<md-item-template>
<div class="sg-tile-content">
<div class="sg-md-subhead">
<div md-highlight-text="app.autocompleteForward.searchText"
md-highlight-flags="gi">{{ user.$shortFormat(app.autocompleteForward.searchText) }}</div>
<div md-highlight-text="app.autocomplete.forward.searchText"
md-highlight-flags="gi">{{ user.$shortFormat(app.autocomplete.forward.searchText) }}</div>
</div>
<div class="sg-md-body"
md-colors="::{color: 'default-background-500'}">{{ user.containername }}</div>
Expand Down Expand Up @@ -1382,6 +1382,67 @@
</var:if>
<!-- END OF MAIL > FORWARD -->

<!-- MAIL > NOTIFICATIONS -->
<var:if condition="isNotificationEnabled">
<md-tab id="mailNotificationTab" aria-controls="mailNotificationTab-content" label:label="Notification">
<md-content class="md-padding"
ng-include="'hasActiveExternalSieveScripts.html'"
ng-show="app.preferences.defaults.hasActiveExternalSieveScripts">
<!-- external Sieve script detected -->
</md-content>
<div role="tabpanel" aria-labelledby="mailNotificationView"
id="mailNotificationView-content" class="md-padding">

<md-checkbox
ng-model="app.preferences.defaults.Notification.enabled"
ng-true-value="1"
ng-false-value="0">
<var:string label:value="Notify incoming messsages"/>
</md-checkbox>

<div flex-offset="5" ng-show="app.preferences.defaults.Notification.enabled == 1">
<md-input-container class="md-block md-flex">
<label><var:string label:value="Email addresses"/></label>
<md-chips
id="notificationAddress"
name="notificationAddress"
ng-model="app.preferences.defaults.Notification.notificationAddress"
md-transform-chip="app.addRecipient($chip, 'notification')"
ng-required="app.preferences.defaults.Notification.enabled == 1"
md-separator-keys="app.emailSeparatorKeys"
md-add-on-blur="true"
md-autocomplete-snap="width">
<!-- notifications addresses -->
<md-autocomplete
ng-keydown="app.ignoreReturn($event)"
md-menu-class="md-2-line"
md-search-text="app.autocomplete.notification.searchText"
md-selected-item="app.autocomplete.notification.selected"
md-items="user in app.contactFilter(app.autocomplete.notification.searchText)"
var:md-min-length="minimumSearchLength"
md-delay="150"
md-no-cache="true"
label:placeholder="Enter an email"
label:secondary-placeholder="Add another email">
<md-item-template>
<div class="sg-tile-content">
<div class="sg-md-subhead">
<div md-highlight-text="app.autocomplete.notification.searchText"
md-highlight-flags="gi">{{ user.$shortFormat(app.autocomplete.notification.searchText) }}</div>
</div>
<div class="sg-md-body"
md-colors="::{color: 'default-background-500'}">{{ user.containername }}</div>
</div>
</md-item-template>
</md-autocomplete>
</md-chips>
</md-input-container>
</div>
</div>
</md-tab>
</var:if>
<!-- END OF MAIL > FORWARD -->

</md-tabs>
</var:if>
</script>
Expand Down
Loading

0 comments on commit 82b69d1

Please sign in to comment.