Skip to content

Commit

Permalink
feat(mail(web)): Templates folder for pre-defined drafts
Browse files Browse the repository at this point in the history
To create a template, the user needs to:

 - define a mailbox as the Templates folder;
 - move a draft to this special folder.

Fixes #4320
Fixes #5363
  • Loading branch information
cgx committed Feb 11, 2022
1 parent 02b0a41 commit c986422
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 9 deletions.
1 change: 1 addition & 0 deletions SoObjects/Mailer/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Mailer_OBJC_FILES += \
SOGoDraftsFolder.m \
SOGoTrashFolder.m \
SOGoJunkFolder.m \
SOGoTemplatesFolder.m \
\
SOGoMailBodyPart.m \
SOGoHTMLMailBodyPart.m \
Expand Down
4 changes: 4 additions & 0 deletions SoObjects/Mailer/SOGoMailAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
@class SOGoSentFolder;
@class SOGoTrashFolder;
@class SOGoJunkFolder;
@class SOGoTemplatesFolder;

typedef enum {
undefined = -1,
Expand All @@ -63,6 +64,7 @@ typedef enum {
SOGoSentFolder *sentFolder;
SOGoTrashFolder *trashFolder;
SOGoJunkFolder *junkFolder;
SOGoTemplatesFolder *templatesFolder;
SOGoIMAPAclStyle imapAclStyle;
NSMutableArray *identities;
NSString *otherUsersFolderName;
Expand Down Expand Up @@ -117,12 +119,14 @@ typedef enum {
- (NSString *) otherUsersFolderNameInContext: (id)_ctx;
- (NSString *) sharedFoldersNameInContext: (id)_ctx;
- (NSString *) junkFolderNameInContext: (id)_ctx;
- (NSString *) templatesFolderNameInContext: (id)_ctx;

- (SOGoMailFolder *) inboxFolderInContext: (id)_ctx;
- (SOGoDraftsFolder *) draftsFolderInContext: (id)_ctx;
- (SOGoSentFolder *) sentFolderInContext: (id)_ctx;
- (SOGoTrashFolder *) trashFolderInContext: (id)_ctx;
- (SOGoJunkFolder *) junkFolderInContext: (id)_ctx;
- (SOGoTemplatesFolder *) templatesFolderInContext: (id)_ctx;

/* namespaces */

Expand Down
33 changes: 33 additions & 0 deletions SoObjects/Mailer/SOGoMailAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#import "SOGoSentFolder.h"
#import "SOGoTrashFolder.h"
#import "SOGoJunkFolder.h"
#import "SOGoTemplatesFolder.h"
#import "SOGoUser+Mailer.h"

#import "SOGoMailAccount.h"
Expand All @@ -70,6 +71,7 @@ - (id) init
sentFolder = nil;
trashFolder = nil;
junkFolder = nil;
templatesFolder = nil;
imapAclStyle = undefined;
identities = nil;
otherUsersFolderName = nil;
Expand All @@ -88,6 +90,7 @@ - (void) dealloc
[sentFolder release];
[trashFolder release];
[junkFolder release];
[templatesFolder release];
[identities release];
[otherUsersFolderName release];
[sharedFoldersName release];
Expand All @@ -100,6 +103,11 @@ - (BOOL) isInDraftsFolder
return NO;
}

- (BOOL) isInTemplatesFolder
{
return NO;
}

- (void) _appendNamespace: (NSArray *) namespace
toFolders: (NSMutableArray *) folders
{
Expand Down Expand Up @@ -406,6 +414,7 @@ - (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode
[self sentFolderNameInContext: context],
[self trashFolderNameInContext: context],
[self junkFolderNameInContext: context],
[self templatesFolderNameInContext: context],
nil] stringsWithFormat: @"/%@"];
folders = [[self imap4Connection] allFoldersForURL: [self imap4URL]
onlySubscribedFolders: subscribedOnly];
Expand Down Expand Up @@ -479,6 +488,9 @@ - (NSString *) _folderType: (NSString *) folderName
else if ([flags containsObject: [self junkFolderNameInContext: context]] ||
[folderName isEqualToString: [self junkFolderNameInContext: context]])
folderType = @"junk";
else if ([flags containsObject: [self templatesFolderNameInContext: context]] ||
[folderName isEqualToString: [self templatesFolderNameInContext: context]])
folderType = @"templates";
else if ([folderName isEqualToString: otherUsersFolderName])
folderType = @"otherUsers";
else if ([folderName isEqualToString: sharedFoldersName])
Expand Down Expand Up @@ -1012,6 +1024,9 @@ - (id) lookupName: (NSString *) _key
else if ([folderName
isEqualToString: [self junkFolderNameInContext: _ctx]])
klazz = [SOGoJunkFolder class];
else if ([folderName
isEqualToString: [self templatesFolderNameInContext: _ctx]])
klazz = [SOGoTemplatesFolder class];
else
klazz = [SOGoMailFolder class];

Expand Down Expand Up @@ -1081,6 +1096,11 @@ - (NSString *) junkFolderNameInContext: (id)_ctx
return [self _userFolderNameWithPurpose: @"Junk"];
}

- (NSString *) templatesFolderNameInContext: (id)_ctx
{
return [self _userFolderNameWithPurpose: @"Templates"];
}

- (NSString *) otherUsersFolderNameInContext: (id)_ctx
{
return otherUsersFolderName;
Expand Down Expand Up @@ -1192,6 +1212,19 @@ - (SOGoJunkFolder *) junkFolderInContext: (id) _ctx
return junkFolder;
}

- (SOGoTemplatesFolder *) templatesFolderInContext: (id) _ctx
{
if (!templatesFolder)
{
templatesFolder
= [self folderWithTraversal: [self templatesFolderNameInContext: _ctx]
andClassName: @"SOGoTemplatesFolder"];
[templatesFolder retain];
}

return templatesFolder;
}

/* account delegation */
- (NSArray *) delegates
{
Expand Down
1 change: 1 addition & 0 deletions SoObjects/Mailer/SOGoMailBaseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- (SOGoMailAccount *) mailAccountFolder;
- (SOGoMailAccounts *) mailAccountsFolder;
- (BOOL) isInDraftsFolder;
- (BOOL) isInTemplatesFolder;

/* IMAP4 */

Expand Down
5 changes: 5 additions & 0 deletions SoObjects/Mailer/SOGoMailBaseObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ - (BOOL) isInDraftsFolder
return [container isInDraftsFolder];
}

- (BOOL) isInTemplatesFolder
{
return [container isInTemplatesFolder];
}

/* IMAP4 */

- (NGImap4ConnectionManager *) mailManager
Expand Down
4 changes: 4 additions & 0 deletions SoObjects/Mailer/SOGoMailFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ - (id) lookupName: (NSString *) _key
isEqualToString:
[mailAccount junkFolderNameInContext: _ctx]])
className = @"SOGoJunkFolder";
else if ([fullFolderName
isEqualToString:
[mailAccount templatesFolderNameInContext: _ctx]])
className = @"SOGoTemplatesFolder";
/* else if ([folderName isEqualToString:
[mailAccount sieveFolderNameInContext: _ctx]])
obj = [self lookupFiltersFolder: _key inContext: _ctx]; */
Expand Down
32 changes: 32 additions & 0 deletions SoObjects/Mailer/SOGoTemplatesFolder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright (C) 2022 Inverse inc.
This file is part of SOGo.
SOGo is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OGo; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/

#ifndef __Mailer_SOGoTemplatesFolder_H__
#define __Mailer_SOGoTemplatesFolder_H__

#import "SOGoDraftsFolder.h"

@class SOGoDraftsFolder;

@interface SOGoTemplatesFolder : SOGoDraftsFolder
@end

#endif /* __Mailer_SOGoTemplatesFolder_H__ */
31 changes: 31 additions & 0 deletions SoObjects/Mailer/SOGoTemplatesFolder.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (C) 2022 Inverse inc.
This file is part of SOGo.
SOGo is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OGo; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/

#import "SOGoTemplatesFolder.h"

@implementation SOGoTemplatesFolder

- (BOOL) isInTemplatesFolder
{
return YES;
}

@end /* SOGoTemplatesFolder */
1 change: 1 addition & 0 deletions SoObjects/SOGo/SOGoDefaults.plist
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
SOGoDraftsFolderName = "Drafts";
SOGoTrashFolderName = "Trash";
SOGoJunkFolderName = "Junk";
SOGoTemplatesFolderName = "Templates";
SOGoMailComposeMessageType = "html";
SOGoMailComposeFontSize = "0";
SOGoMailDisplayRemoteInlineImages = "never";
Expand Down
2 changes: 2 additions & 0 deletions SoObjects/SOGo/SOGoUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ - (void) _appendSystemMailAccountWithDelegatedIdentities: (BOOL) appendDeletegat
forKey: @"Trash"];
[mailboxes setObject: [_defaults junkFolderName]
forKey: @"Junk"];
[mailboxes setObject: [_defaults templatesFolderName]
forKey: @"Templates"];
[mailAccount setObject: mailboxes forKey: @"specialMailboxes"];
[mailboxes release];

Expand Down
3 changes: 3 additions & 0 deletions SoObjects/SOGo/SOGoUserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ extern NSString *SOGoWeekStartFirstFullWeek;
- (void) setJunkFolderName: (NSString *) newValue;
- (NSString *) junkFolderName;

- (void) setTemplatesFolderName: (NSString *) newValue;
- (NSString *) templatesFolderName;

- (void) setFirstDayOfWeek: (int) newValue;
- (int) firstDayOfWeek;

Expand Down
11 changes: 11 additions & 0 deletions SoObjects/SOGo/SOGoUserDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ - (NSString *) junkFolderName
stringByEncodingImap4FolderName];
}

- (void) setTemplatesFolderName: (NSString *) newValue
{
[self setObject: newValue forKey: @"SOGoTemplatesFolderName"];
}

- (NSString *) templatesFolderName
{
return [[self stringForKey: @"SOGoTemplatesFolderName"]
stringByEncodingImap4FolderName];
}

- (void) setFirstDayOfWeek: (int) newValue
{
[self setInteger: newValue forKey: @"SOGoFirstDayOfWeek"];
Expand Down
7 changes: 7 additions & 0 deletions UI/MailerUI/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"InboxFolderName" = "Inbox";
"DraftsFolderName" = "Drafts";
"JunkFolderName" = "Junk";
"TemplatesFolderName" = "Templates";
"SieveFolderName" = "Filters";
"Folders" = "Folders"; /* title line */

Expand Down Expand Up @@ -432,6 +433,9 @@
"Set as Sent" = "Set as Sent";
"Set as Trash" = "Set as Trash";

/* Set the folder as the one holding the Templates */
"Set as Templates" = "Set as Templates";

/* Set the folder as the one holding Junk mails */
"Set as Junk" = "Set as Junk";

Expand All @@ -454,6 +458,9 @@
"Your email has been sent" = "Your email has been sent";
"Folder compacted" = "Folder compacted";

"New draft" = "New draft";
"Create new draft with this template" = "Create new draft with this template";

/* Advanced search */
"Enter Subject" = "Enter Subject";
"Enter From" = "Enter From";
Expand Down
30 changes: 30 additions & 0 deletions UI/MailerUI/UIxMailActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,36 @@ - (WOResponse *) forwardAction
andString: [data jsonRepresentation]];
}

- (WOResponse *) composeAction
{
SOGoMailAccount *account;
SOGoMailObject *co;
SOGoDraftsFolder *drafts;
SOGoDraftObject *newMail;
NSString *accountName, *mailboxName, *messageName;
NSDictionary *data;

co = [self clientObject];
account = [co mailAccountFolder];
drafts = [account draftsFolderInContext: context];
newMail = [drafts newDraft];
[newMail fetchMailForEditing: co];
[newMail storeInfo];

accountName = [account nameInContainer];
mailboxName = [drafts absoluteImap4Name];
mailboxName = [mailboxName substringWithRange: NSMakeRange(1, [mailboxName length] -2)];
messageName = [newMail nameInContainer];

data = [NSDictionary dictionaryWithObjectsAndKeys:
accountName, @"accountId",
mailboxName, @"mailboxPath",
messageName, @"draftId", nil];

return [self responseWithStatus: 201
andString: [data jsonRepresentation]];
}

- (WOResponse *) viewPlainAction
{
BOOL htmlContent;
Expand Down
7 changes: 7 additions & 0 deletions UI/MailerUI/UIxMailView.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ @interface UIxMailView : UIxComponent
}

- (BOOL) mailIsDraft;
- (BOOL) mailIsTemplate;
- (NSNumber *) shouldAskReceipt;
- (NSString *) formattedDate;
- (NSString *) _matchingIdentityEMailOrDefault: (BOOL) useDefault;
Expand Down Expand Up @@ -340,6 +341,7 @@ those are the IMAP4 flags (and annotations, which we do not use).
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[self shouldAskReceipt], @"shouldAskReceipt",
[NSNumber numberWithBool: [self mailIsDraft]], @"isDraft",
[NSNumber numberWithBool: [self mailIsTemplate]], @"isTemplate",
renderedPart, @"parts",
nil];
if ([self formattedDate])
Expand Down Expand Up @@ -803,6 +805,11 @@ - (BOOL) mailIsDraft
return [[self clientObject] isInDraftsFolder];
}

- (BOOL) mailIsTemplate
{
return [[self clientObject] isInTemplatesFolder];
}

- (id) redirectToParentFolder
{
id url;
Expand Down
10 changes: 10 additions & 0 deletions UI/MailerUI/product.plist
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
actionClass = "UIxMailFolderActions";
actionName = "setAsJunkFolder";
};
setAsTemplatesFolder = {
protectedBy = "View";
actionClass = "UIxMailFolderActions";
actionName = "setAsTemplatesFolder";
};
markMessagesAsJunk = {
protectedBy = "View";
actionClass = "UIxMailFolderActions";
Expand Down Expand Up @@ -237,6 +242,11 @@
actionClass = "UIxMailActions";
actionName = "edit";
};
compose = {
protectedBy = "View";
actionClass = "UIxMailActions";
actionName = "compose";
};
reply = {
protectedBy = "View";
actionClass = "UIxMailActions";
Expand Down
Loading

0 comments on commit c986422

Please sign in to comment.