mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-02-17 07:33:57 +00:00
feat(mail): Deletion of mail older than x. Closes #6023.
This commit is contained in:
@@ -431,7 +431,7 @@ See `memcached_servers_parse(3)` for details on the syntax.
|
||||
|
||||
|S |SOGoCacheCleanupInterval
|
||||
|Parameter used to set the expiration (in seconds) of each object in the
|
||||
cache.
|
||||
cache. Default value is `NO`.
|
||||
|
||||
Defaults to `300`.
|
||||
|
||||
@@ -1678,6 +1678,9 @@ URL could be set to something like:
|
||||
|
||||
See the "EMail reminders" section in this document for more information.
|
||||
|
||||
|S |SOGoDisableMailCleaning
|
||||
|Parameter used to disable the feature 'remove mails older than X days' introduced in 5.12
|
||||
|
||||
|S |SOGoDisableOrganizerEventCheck
|
||||
|Parameter used to disable organizer's calendar event check
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ typedef enum {
|
||||
- (NSArray *) toManyRelationshipKeysWithNamespaces: (BOOL) withNSs;
|
||||
|
||||
- (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode;
|
||||
- (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode onlyRoot: (BOOL) onlyRoot;
|
||||
- (NSArray *) allFoldersMetadata: (SOGoMailListingMode) theListingMode;
|
||||
|
||||
- (NSDictionary *) imapFolderGUIDs;
|
||||
|
||||
@@ -378,14 +378,21 @@ static NSString *inboxFolderName = @"INBOX";
|
||||
return folders;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode
|
||||
- (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode
|
||||
{
|
||||
NSMutableArray *folderPaths, *namespaces;
|
||||
return [self allFolderPaths: theListingMode onlyRoot: NO];
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode onlyRoot: (BOOL) onlyRoot
|
||||
{
|
||||
NSMutableArray *folderPaths, *namespaces, *filteredFolders;
|
||||
NSArray *folders, *mainFolders;
|
||||
NSString *namespace;
|
||||
NSString *folder;
|
||||
NSUInteger slashCount;
|
||||
|
||||
BOOL subscribedOnly;
|
||||
int count, max;
|
||||
@@ -401,10 +408,10 @@ static NSString *inboxFolderName = @"INBOX";
|
||||
onlySubscribedFolders: YES];
|
||||
max = [folders count];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
[subscribedFolders setObject: [NSNull null]
|
||||
forKey: [folders objectAtIndex: count]];
|
||||
}
|
||||
{
|
||||
[subscribedFolders setObject: [NSNull null]
|
||||
forKey: [folders objectAtIndex: count]];
|
||||
}
|
||||
[[self imap4Connection] flushFolderHierarchyCache];
|
||||
}
|
||||
|
||||
@@ -418,6 +425,17 @@ static NSString *inboxFolderName = @"INBOX";
|
||||
nil] stringsWithFormat: @"/%@"];
|
||||
folders = [[self imap4Connection] allFoldersForURL: [self imap4URL]
|
||||
onlySubscribedFolders: subscribedOnly];
|
||||
if (onlyRoot) {
|
||||
filteredFolders = [[NSMutableArray alloc] init];
|
||||
for (folder in folders) {
|
||||
slashCount = [[folder componentsSeparatedByString:@"/"] count] - 1;
|
||||
if (slashCount <= 1) {
|
||||
[filteredFolders addObject: folder];
|
||||
}
|
||||
}
|
||||
folders = [NSArray arrayWithArray: filteredFolders];
|
||||
[filteredFolders release];
|
||||
}
|
||||
folderPaths = [folders mutableCopy];
|
||||
[folderPaths autorelease];
|
||||
|
||||
|
||||
@@ -142,6 +142,8 @@ NSComparisonResult languageSort(id el1, id el2, void *context);
|
||||
|
||||
- (NSString *)urlCreateAccount;
|
||||
|
||||
- (BOOL)disableMailCleaning;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SOGOSYSTEMDEFAULTS_H */
|
||||
|
||||
@@ -933,4 +933,9 @@ NSComparisonResult languageSort(id el1, id el2, void *context)
|
||||
return [self stringForKey: @"SOGoURLCreateAccount"];
|
||||
}
|
||||
|
||||
- (BOOL) disableMailCleaning
|
||||
{
|
||||
return [self boolForKey: @"SOGoDisableMailCleaning"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -516,4 +516,16 @@
|
||||
"hotkey_forward" = "f";
|
||||
|
||||
/* Email deletion */
|
||||
"Removal of old emails..." = "Removal of old emails...";
|
||||
"Clean folder" = "Clean folder";
|
||||
"Clean mailbox" = "Clean mailbox";
|
||||
"Delete permanently (do not use trash)" = "Delete permanently (do not use trash)";
|
||||
"Apply to subfolders" = "Apply to subfolders";
|
||||
"Delete e-mails older than" = "Delete e-mails older than";
|
||||
"3 months" = "3 months";
|
||||
"6 months" = "6 months";
|
||||
"9 months" = "9 months";
|
||||
"1 year" = "1 year";
|
||||
"Custom" = "Custom";
|
||||
"You are about to permanently delete some messages. Are you sure you want to proceed with this action?" = "You are about to permanently delete some messages. Are you sure you want to proceed with this action?";
|
||||
"Apply" = "Apply";
|
||||
"%{0} message(s) deleted" = "%{0} message(s) deleted";
|
||||
@@ -516,4 +516,16 @@
|
||||
"hotkey_forward" = "f";
|
||||
|
||||
/* Email deletion */
|
||||
"Removal of old emails..." = "Suppression des anciens emails...";
|
||||
"Clean folder" = "Nettoyer le dossier";
|
||||
"Clean mailbox" = "Nettoyer la boite mail";
|
||||
"Delete permanently (do not use trash)" = "Supprimer définitivement (ne pas utiliser la corbeille)";
|
||||
"Apply to subfolders" = "Appliquer aux sous-dossiers";
|
||||
"Delete e-mails older than" = "Supprimer les e-mails plus vieux de";
|
||||
"3 months" = "3 mois";
|
||||
"6 months" = "6 mois";
|
||||
"9 months" = "9 mois";
|
||||
"1 year" = "1 an";
|
||||
"Custom" = "Personnalisé";
|
||||
"You are about to permanently delete some messages. Are you sure you want to proceed with this action?" = "Vous êtes sur le point de supprimer définitivement certains messages. Êtes-vous certain de vouloir effectuer cette action ?";
|
||||
"Apply" = "Appliquer";
|
||||
"%{0} message(s) deleted" = "%{0} message(s) supprimés";
|
||||
@@ -21,6 +21,7 @@
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSURL.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <NGObjWeb/WOContext+SoObjects.h>
|
||||
#import <NGObjWeb/WORequest.h>
|
||||
@@ -1300,20 +1301,125 @@
|
||||
return [self _markMessagesAsJunkOrNotJunk: NO];
|
||||
}
|
||||
|
||||
- (WOResponse *) cleanMailboxAction
|
||||
{
|
||||
NSString *searchString;
|
||||
EOQualifier *searchQualifier;
|
||||
- (BOOL)isDateStringValid: (NSString *)dateString {
|
||||
NSString *dateRegex = @"^\\d{4}-\\d{2}-\\d{2}$";
|
||||
NSPredicate *dateTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", dateRegex];
|
||||
return [dateTest evaluateWithObject:dateString];
|
||||
}
|
||||
|
||||
searchString = [NSString stringWithFormat: @"(date >= (NSCalendarDate)\"%@\")", @"2020-01-12"];
|
||||
searchQualifier = [EOQualifier qualifierWithQualifierFormat: searchString];
|
||||
- (void) cleanFolderWithFolder: (SOGoMailFolder *)folder
|
||||
withQualifier: (EOQualifier *)qualifier
|
||||
recursive: (BOOL)isRecursive
|
||||
withTrashFolder: (BOOL)useTrashFolder
|
||||
exception: (NSException **)exception
|
||||
counter: (NSUInteger *)counter {
|
||||
NSArray *results, *subfolders;
|
||||
NSUInteger i;
|
||||
SOGoMailFolder *newFolder;
|
||||
NSString *folderName;
|
||||
NSException *e;
|
||||
|
||||
id foo;
|
||||
foo = [[self clientObject] fetchUIDsMatchingQualifier: searchQualifier
|
||||
sortOrdering: @"date"
|
||||
results = [folder fetchUIDsMatchingQualifier: qualifier
|
||||
sortOrdering: @"REVERSE DATE"
|
||||
threaded: NO];
|
||||
|
||||
return [self responseWithStatus: 200];
|
||||
if (results && [results count] > 0) {
|
||||
e = [folder deleteUIDs: results
|
||||
useTrashFolder: &useTrashFolder
|
||||
inContext: [self context]];
|
||||
[folder expunge];
|
||||
[self logWithFormat: @"Removed %d messages in %@ (%@)", [results count], [folder nameInContainer], results];
|
||||
*counter += [results count];
|
||||
if (e) {
|
||||
[self errorWithFormat: @"Error while cleaning mailbox : %@", e];
|
||||
*exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRecursive) {
|
||||
subfolders = [folder subfolders];
|
||||
for (i = 0 ; i < [subfolders count] ; i++) {
|
||||
folderName = [NSString stringWithFormat:@"%@/%@", [folder nameInContainer], [subfolders objectAtIndex: i]];
|
||||
newFolder = [[SOGoMailFolder alloc] initWithName: folderName inContainer: [folder container]];
|
||||
[self cleanFolderWithFolder: newFolder
|
||||
withQualifier: qualifier
|
||||
recursive: isRecursive
|
||||
withTrashFolder: useTrashFolder
|
||||
exception: exception
|
||||
counter: counter];
|
||||
[newFolder release];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (WOResponse *) cleanMailboxAction
|
||||
{
|
||||
NSDictionary *jsonRequest, *jsonResponse;
|
||||
WORequest *request;
|
||||
NSString *searchString, *folderName;
|
||||
EOQualifier *searchQualifier;
|
||||
BOOL isRecursive, useTrashFolder;
|
||||
NSException *exception;
|
||||
SOGoMailFolder *folder;
|
||||
SOGoMailAccount *account;
|
||||
NSUInteger i, counter;
|
||||
NSArray *folderNames;
|
||||
|
||||
request = [[self context] request];
|
||||
jsonRequest = [[request contentAsString] objectFromJSONString];
|
||||
|
||||
if ([[SOGoSystemDefaults sharedSystemDefaults] disableMailCleaning])
|
||||
return [self responseWithStatus: 401];
|
||||
|
||||
if (![self isDateStringValid: [jsonRequest objectForKey: @"date"]]) {
|
||||
[self errorWithFormat: @"Error while cleaning mailbox, invalid date : %@", [jsonRequest objectForKey: @"date"]];
|
||||
return [self responseWithStatus: 502];
|
||||
}
|
||||
|
||||
searchString = [NSString stringWithFormat: @"(NOT (flags = 'deleted') AND (DATE <= (NSCalendarDate)\"%@\"))", [jsonRequest objectForKey: @"date"]];
|
||||
searchQualifier = [EOQualifier qualifierWithQualifierFormat: searchString];
|
||||
isRecursive = [[jsonRequest objectForKey: @"applyToSubfolders"] boolValue];
|
||||
useTrashFolder = ![[jsonRequest objectForKey: @"permanentlyDelete"] boolValue];
|
||||
counter = 0;
|
||||
exception = nil;
|
||||
|
||||
if ([[self clientObject] isKindOfClass: [SOGoMailFolder class]]) {
|
||||
folder = [self clientObject];
|
||||
[self cleanFolderWithFolder: folder
|
||||
withQualifier: searchQualifier
|
||||
recursive: isRecursive
|
||||
withTrashFolder: useTrashFolder
|
||||
exception: &exception
|
||||
counter: &counter];
|
||||
} else if ([[self clientObject] isKindOfClass: [SOGoMailAccount class]]) {
|
||||
account = [self clientObject];
|
||||
folderNames = [account allFolderPaths: SOGoMailStandardListing onlyRoot: YES];
|
||||
for (i = 0 ; i < [folderNames count] ; i ++) {
|
||||
folderName = [folderNames objectAtIndex: i];
|
||||
if ([folderName hasPrefix:@"/"]) {
|
||||
folderName = [folderName substringFromIndex:1];
|
||||
}
|
||||
folder = [account folderWithTraversal: folderName andClassName: nil];
|
||||
// Disable clean for trash folder
|
||||
if (![folderName isEqualToString: [account trashFolderNameInContext: [self context]]])
|
||||
[self cleanFolderWithFolder: folder
|
||||
withQualifier: searchQualifier
|
||||
recursive: isRecursive
|
||||
withTrashFolder: useTrashFolder
|
||||
exception: &exception
|
||||
counter: &counter];
|
||||
}
|
||||
|
||||
[[account imap4Connection] flushMailCaches];
|
||||
}
|
||||
|
||||
if (exception) {
|
||||
return [self responseWithStatus: 500];
|
||||
}
|
||||
|
||||
jsonResponse = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: counter]
|
||||
forKey: @"nbMessageDeleted"];
|
||||
return [self responseWithStatus: 200 andJSONRepresentation: jsonResponse];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -611,6 +611,17 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) isCleanMailboxEnabled {
|
||||
BOOL result;
|
||||
SOGoSystemDefaults *sd;
|
||||
|
||||
sd = [SOGoSystemDefaults sharedSystemDefaults];
|
||||
|
||||
result = ![sd disableMailCleaning];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end /* UIxMailMainFrame */
|
||||
|
||||
@interface UIxMailFolderTemplate : UIxComponent
|
||||
|
||||
@@ -422,6 +422,11 @@
|
||||
protectedBy = "View";
|
||||
pageName = "UIxMailUserDelegationEditor";
|
||||
};
|
||||
cleanMailbox = {
|
||||
protectedBy = "View";
|
||||
actionClass = "UIxMailFolderActions";
|
||||
actionName = "cleanMailbox";
|
||||
};
|
||||
addDelegate = {
|
||||
protectedBy = "View";
|
||||
actionClass = "UIxMailAccountActions";
|
||||
|
||||
@@ -633,12 +633,18 @@
|
||||
</md-dialog>
|
||||
</script>
|
||||
<!-- Remove old emails -->
|
||||
<script type="text/ng-template" id="removeOldEmails">
|
||||
<script type="text/ng-template" id="CleanMailbox">
|
||||
<md-dialog flex="50" flex-sm="80" flex-xs="100">
|
||||
<!-- Toolbar -->
|
||||
<md-toolbar>
|
||||
<div class="md-toolbar-tools">
|
||||
<div class="md-title">Manage Folders</div>
|
||||
<md-icon class="material-icons sg-icon-toolbar-bg">delete</md-icon>
|
||||
<div class="pseudo-input-container md-flex" ng-if="::!dialogCtrl.isMailbox">
|
||||
<var:string label:value="Clean folder"/>
|
||||
</div>
|
||||
<div class="pseudo-input-container md-flex" ng-if="::dialogCtrl.isMailbox">
|
||||
<var:string label:value="Clean mailbox"/>
|
||||
</div>
|
||||
<md-button class="md-icon-button" ng-click="dialogCtrl.closeDialog()">
|
||||
<md-icon aria-label="Close dialog">close</md-icon>
|
||||
</md-button>
|
||||
@@ -648,45 +654,63 @@
|
||||
<!-- Dialog Content -->
|
||||
<md-dialog-content class="md-dialog-content">
|
||||
<div class="md-dialog-content">
|
||||
<!-- Folder Name Input -->
|
||||
<md-input-container class="md-block">
|
||||
<label>Folder</label>
|
||||
<input type="text" class="sg-readonly" ng-model="dialogCtrl.folderName" readonly="true" />
|
||||
</md-input-container>
|
||||
<h4>
|
||||
{{ dialogCtrl.name }}
|
||||
</h4>
|
||||
|
||||
<!-- Checkboxes -->
|
||||
<md-input-container class="md-block">
|
||||
<md-checkbox ng-model="dialogCtrl.form.moveToTrash" aria-label="Move emails to trash">
|
||||
Move emails to trash
|
||||
<md-checkbox ng-model="dialogCtrl.form.permanentlyDelete" label:aria-label="Delete permanently (do not use trash)">
|
||||
<var:string label:value="Delete permanently (do not use trash)"/>
|
||||
</md-checkbox>
|
||||
</md-input-container>
|
||||
|
||||
<md-input-container class="md-block">
|
||||
<md-checkbox ng-model="dialogCtrl.form.applyToSubfolders" aria-label="Apply to subfolders">
|
||||
Apply to subfolders
|
||||
<md-checkbox ng-model="dialogCtrl.form.applyToSubfolders" label:aria-label="Apply to subfolders">
|
||||
<var:string label:value="Apply to subfolders"/>
|
||||
</md-checkbox>
|
||||
</md-input-container>
|
||||
|
||||
<!-- Dropdown List -->
|
||||
<md-input-container class="md-block">
|
||||
<label>Filter Emails</label>
|
||||
<label><var:string label:value="Delete e-mails older than"/></label>
|
||||
<md-select ng-model="dialogCtrl.form.filterDuration">
|
||||
<md-option value="3m">≥ 3 months</md-option>
|
||||
<md-option value="6m">≥ 6 months</md-option>
|
||||
<md-option value="9m">≥ 9 months</md-option>
|
||||
<md-option value="1y">≥ 1 year</md-option>
|
||||
<md-option value="3m"><var:string label:value="3 months"/></md-option>
|
||||
<md-option value="6m"><var:string label:value="6 months"/></md-option>
|
||||
<md-option value="9m"><var:string label:value="9 months"/></md-option>
|
||||
<md-option value="1y"><var:string label:value="1 year"/></md-option>
|
||||
<md-option value="custom"><var:string label:value="Custom"/></md-option>
|
||||
</md-select>
|
||||
</md-input-container>
|
||||
|
||||
<md-input-container class="md-block" ng-show="['custom'].indexOf(dialogCtrl.form.filterDuration) != -1">
|
||||
<label><var:string label:value="Date"/></label>
|
||||
<md-datepicker class="md-text"
|
||||
ng-model="dialogCtrl.form.filterDurationDate"
|
||||
md-hide-icons="calendar"
|
||||
md-max-date="dialogCtrl.maxDate"
|
||||
ng-change="dialogCtrl.mainController.changeDate()">
|
||||
</md-datepicker>
|
||||
</md-input-container>
|
||||
|
||||
<md-input-container class="md-block" ng-show="dialogCtrl.isWarningDisplayed()">
|
||||
<md-checkbox ng-model="dialogCtrl.form.confirmDelete" label:aria-label="You are about to permanently delete some messages. Are you sure you want to proceed with this action?">
|
||||
<span class="clean-mailbox-warn"><var:string label:value="You are about to permanently delete some messages. Are you sure you want to proceed with this action?" /></span>
|
||||
</md-checkbox>
|
||||
</md-input-container>
|
||||
</div>
|
||||
</md-dialog-content>
|
||||
|
||||
<!-- Dialog Actions -->
|
||||
<md-dialog-actions>
|
||||
<md-button class="md-warn" ng-click="dialogCtrl.closeDialog()">
|
||||
Cancel
|
||||
<var:string label:value="Cancel" />
|
||||
</md-button>
|
||||
<md-button class="md-primary" ng-click="dialogCtrl.apply()">
|
||||
Apply
|
||||
<div class="sg-progress-linear-bottom"
|
||||
ng-show="dialogCtrl.isLoading()">
|
||||
<md-progress-linear class="md-accent"
|
||||
md-mode="indeterminate"><!-- progress --></md-progress-linear>
|
||||
</div>
|
||||
<md-button class="md-primary" ng-disabled="dialogCtrl.isApplyDisabled()" ng-click="dialogCtrl.apply()">
|
||||
<var:string label:value="Apply" />
|
||||
</md-button>
|
||||
</md-dialog-actions>
|
||||
</md-dialog>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<var:string label:value="New Folder..."/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<var:if condition="isCleanMailboxEnabled">
|
||||
<md-menu-item>
|
||||
<md-button type="button" ng-click="app.showCleanMailboxPanel(null, account)">
|
||||
<var:string label:value="Clean mailbox"/>...
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
</var:if>
|
||||
<md-menu-item ng-show="::account.id == 0">
|
||||
<md-button
|
||||
label:aria-label="Search"
|
||||
@@ -179,11 +186,13 @@
|
||||
<var:string label:value="Compact"/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<md-menu-item>
|
||||
<md-button type="button" ng-click="$menuCtrl.removeOldEmails()">
|
||||
<var:string label:value="Removal of old emails ..."/>
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
<var:if condition="isCleanMailboxEnabled">
|
||||
<md-menu-item ng-show="::($menuCtrl.folder.type != 'trash')">
|
||||
<md-button type="button" ng-click="$menuCtrl.cleanMailbox()">
|
||||
<var:string label:value="Clean folder"/>...
|
||||
</md-button>
|
||||
</md-menu-item>
|
||||
</var:if>
|
||||
<md-menu-item ng-show="::$menuCtrl.folder.$isEditable">
|
||||
<md-button type="button" ng-click="$menuCtrl.confirmDelete()">
|
||||
<var:string label:value="Delete"/>
|
||||
|
||||
@@ -1313,9 +1313,20 @@
|
||||
return this.$highlightWords;
|
||||
};
|
||||
|
||||
/* TODO */
|
||||
Mailbox.prototype.cleanMailbox = function () {
|
||||
Mailbox.$$resource.post(this.id, 'cleanMailbox');
|
||||
/**
|
||||
* @function cleanMailbox
|
||||
* @memberof Mailbox.prototype
|
||||
* @desc Cleans up the mailbox by applying the specified parameters.
|
||||
* This can include operations such as moving emails to trash,
|
||||
* filtering emails based on a duration, and applying actions to subfolders.
|
||||
* @param {Object} parameters - An object containing the parameters for cleaning the mailbox.
|
||||
* @param {boolean} [parameters.applyToSubfolders=false] - Whether to apply the cleaning operation to subfolders.
|
||||
* @param {boolean} [parameters.moveToTrash=false] - Whether to move the emails to the trash folder.
|
||||
* @param {string|null} [parameters.filterDuration=null] - A duration filter (e.g., "3m", "6m") to select emails older than the specified duration.
|
||||
* @returns {Promise} A promise that resolves when the cleaning operation is completed, or rejects with an error if the operation fails.
|
||||
*/
|
||||
Mailbox.prototype.cleanMailbox = function (parameters) {
|
||||
return parameters.folders.length > 0 ? Mailbox.$$resource.post(this.id.split("/")[0], 'cleanMailbox', parameters) : Mailbox.$$resource.post(this.id, 'cleanMailbox', parameters);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -54,8 +54,8 @@
|
||||
vm.reset();
|
||||
});
|
||||
|
||||
$rootScope.$on('showRemoveOldEmailsPanel', function (e, d) {
|
||||
vm.showRemoveOldEmailsPanel(d.folder);
|
||||
$rootScope.$on('showCleanMailboxPanel', function (e, d) {
|
||||
vm.showCleanMailboxPanel(d.folder, d.account);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -451,32 +451,119 @@
|
||||
});
|
||||
};
|
||||
|
||||
this.showRemoveOldEmailsPanel = function (folder) {
|
||||
this.showCleanMailboxPanel = function (folder, account) {
|
||||
// Close sidenav on small devices
|
||||
if (!$mdMedia(sgConstant['gt-md']))
|
||||
$mdSidenav('left').close();
|
||||
|
||||
$mdDialog.show({
|
||||
template: document.getElementById('removeOldEmails').innerHTML,
|
||||
template: document.getElementById('CleanMailbox').innerHTML,
|
||||
parent: angular.element(document.body),
|
||||
controller: function () {
|
||||
var dialogCtrl = this;
|
||||
|
||||
this.$onInit = function () {
|
||||
// Pass main controller
|
||||
this.mainController = vm;
|
||||
this.folder = folder;
|
||||
this.folderName = folder.$displayName;
|
||||
this.isMailbox = (folder ? false : true);
|
||||
this.name = folder ? folder.$displayName : account.name;
|
||||
this.loading = false;
|
||||
this.date = null;
|
||||
this.form = {
|
||||
filterDuration: "3m",
|
||||
permanentlyDelete: false,
|
||||
confirmDelete: false,
|
||||
filterDurationDate: null
|
||||
};
|
||||
|
||||
var today = new Date();
|
||||
var maxDate = new Date(today);
|
||||
maxDate.setMonth(today.getMonth() - 3);
|
||||
this.maxDate = maxDate;
|
||||
};
|
||||
|
||||
dialogCtrl.closeDialog = function () {
|
||||
$mdDialog.hide();
|
||||
};
|
||||
|
||||
|
||||
dialogCtrl.isLoading = function () {
|
||||
return this.loading;
|
||||
}
|
||||
|
||||
dialogCtrl.isWarningDisplayed = function () {
|
||||
return (this.form && this.form.permanentlyDelete);
|
||||
}
|
||||
|
||||
dialogCtrl.isApplyDisabled = function () {
|
||||
return !(!this.loading
|
||||
&& (!this.form.permanentlyDelete || (this.form.permanentlyDelete && this.form.confirmDelete))
|
||||
&& (this.form.filterDuration != 'custom' || (this.form.filterDuration == 'custom' && this.form.filterDurationDate))
|
||||
);
|
||||
}
|
||||
|
||||
dialogCtrl.apply = function () {
|
||||
console.log(this.mailbox);
|
||||
this.folder.cleanMailbox();
|
||||
// $mdDialog.hide();
|
||||
var folders = [];
|
||||
var i;
|
||||
if (account) {
|
||||
for (i = 0; i < account.$mailboxes.length ; i++) {
|
||||
folders.push(account.$mailboxes[i].id);
|
||||
}
|
||||
this.folder = account.$mailboxes[0];
|
||||
}
|
||||
var date = '';
|
||||
var durationMonth = 12;
|
||||
var date = new Date();
|
||||
switch (this.form.filterDuration) {
|
||||
case '3m':
|
||||
durationMonth = 3;
|
||||
date.setMonth(date.getMonth() - durationMonth);
|
||||
break;
|
||||
case '6m':
|
||||
durationMonth = 6;
|
||||
date.setMonth(date.getMonth() - durationMonth);
|
||||
break;
|
||||
case '9m':
|
||||
durationMonth = 9;
|
||||
date.setMonth(date.getMonth() - durationMonth);
|
||||
break;
|
||||
case '1y':
|
||||
durationMonth = 12;
|
||||
date.setMonth(date.getMonth() - durationMonth);
|
||||
break;
|
||||
case 'custom':
|
||||
date = this.form.filterDurationDate;
|
||||
break;
|
||||
}
|
||||
var year = date.getFullYear();
|
||||
var month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
var day = String(date.getDate()).padStart(2, '0');
|
||||
this.date = `${year}-${month}-${day}`;
|
||||
this.folder.cleanMailbox({
|
||||
'applyToSubfolders': (this.form && this.form.applyToSubfolders) ? this.form.applyToSubfolders : false,
|
||||
'permanentlyDelete': (this.form && this.form.permanentlyDelete) ? this.form.permanentlyDelete : false,
|
||||
'date': this.date,
|
||||
'folders': folders
|
||||
}).then(function (data) {
|
||||
dialogCtrl.loading = true;
|
||||
Mailbox.selectedFolder.$filter({
|
||||
"sort": "date",
|
||||
"asc": false,
|
||||
"match": "OR"
|
||||
}).then(function () {
|
||||
$state.go('mail.account.mailbox', { accountId: vm.accounts[0].id, mailboxId: encodeUriFilter(Mailbox.selectedFolder.path) });
|
||||
dialogCtrl.loading = false;
|
||||
$mdDialog.hide();
|
||||
|
||||
$mdToast.show(
|
||||
$mdToast.simple()
|
||||
.textContent(l('%{0} message(s) deleted', data.nbMessageDeleted))
|
||||
.position(sgConstant.toastPosition)
|
||||
.hideDelay(2000));
|
||||
});
|
||||
}).catch(function () {
|
||||
dialogCtrl.loading = false;
|
||||
$mdDialog.hide();
|
||||
});
|
||||
};
|
||||
},
|
||||
controllerAs: 'dialogCtrl',
|
||||
|
||||
@@ -271,12 +271,12 @@
|
||||
});
|
||||
};
|
||||
|
||||
this.removeOldEmails = function () {
|
||||
this.cleanMailbox = function () {
|
||||
// Close sidenav on small devices
|
||||
if (!$mdMedia(sgConstant['gt-md']))
|
||||
$mdSidenav('left').close();
|
||||
|
||||
$rootScope.$broadcast('showRemoveOldEmailsPanel', {folder: this.folder}); // Show remove old emails panel (broadcast event to MailboxesController)
|
||||
$rootScope.$broadcast('showCleanMailboxPanel', {folder: this.folder, account: null}); // Show remove old emails panel (broadcast event to MailboxesController)
|
||||
};
|
||||
|
||||
this.emptyJunkFolder = function() {
|
||||
|
||||
@@ -531,4 +531,10 @@ mark {
|
||||
cursor: pointer;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
/* Clean mailbox */
|
||||
|
||||
.clean-mailbox-warn {
|
||||
color: #f44336;
|
||||
}
|
||||
Reference in New Issue
Block a user