X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=UI%2FMailerUI%2FUIxMailAccountActions.m;h=69fe254d95b79f8ce65d07b69502e8377b4ccc93;hb=c6c01229291a89caf24a6a11b25bcdefee5f6246;hp=56b9a0d8771f805dd3d787f974b6adf2225784d3;hpb=dfde332148ad83ce9a842844eb04992383923670;p=scalable-opengroupware.org diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index 56b9a0d8..69fe254d 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -24,27 +24,75 @@ #import #import -#import +#import +#import #import #import + #import +#import +#import +#import #import +#import +#import + +#import "../Common/WODirectAction+SOGo.h" #import "UIxMailAccountActions.h" @implementation UIxMailAccountActions -- (NSString *) _folderType: (NSString *) baseName +- (id) init +{ + if ((self = [super init])) + { + inboxFolderName = nil; + draftsFolderName = nil; + sentFolderName = nil; + trashFolderName = nil; + } + + return self; +} + +- (void) dealloc +{ + [inboxFolderName release]; + [draftsFolderName release]; + [sentFolderName release]; + [trashFolderName release]; + [super dealloc]; +} + +- (NSString *) _folderType: (NSString *) folderName { NSString *folderType; + SOGoMailAccount *co; + NSArray *specialFolders; + + if (!inboxFolderName) + { + co = [self clientObject]; + specialFolders = [[NSArray arrayWithObjects: + [co inboxFolderNameInContext: context], + [co draftsFolderNameInContext: context], + [co sentFolderNameInContext: context], + [co trashFolderNameInContext: context], + nil] stringsWithFormat: @"/%@"]; + ASSIGN (inboxFolderName, [specialFolders objectAtIndex: 0]); + ASSIGN (draftsFolderName, [specialFolders objectAtIndex: 1]); + ASSIGN (sentFolderName, [specialFolders objectAtIndex: 2]); + ASSIGN (trashFolderName, [specialFolders objectAtIndex: 3]); + } - if ([baseName isEqualToString: @"INBOX"]) + if ([folderName isEqualToString: inboxFolderName]) folderType = @"inbox"; - else if ([baseName isEqualToString: draftFolderName]) + else if ([folderName isEqualToString: draftsFolderName]) folderType = @"draft"; - else if ([baseName isEqualToString: sentFolderName]) + else if ([folderName isEqualToString: sentFolderName]) folderType = @"sent"; - else if ([baseName isEqualToString: trashFolderName]) + else if ([folderName isEqualToString: trashFolderName]) folderType = @"trash"; else folderType = @"folder"; @@ -52,34 +100,20 @@ return folderType; } -- (NSDictionary *) _lineForFolder: (NSString *) folder -{ - NSArray *parts; - NSMutableDictionary *folderData; - NSString *baseName; - - folderData = [NSMutableDictionary dictionary]; - parts = [folder componentsSeparatedByString: @"/"]; - baseName = [parts lastObject]; - [folderData setObject: folder forKey: @"path"]; - [folderData setObject: [self _folderType: baseName] - forKey: @"type"]; - - return folderData; -} - - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders { NSMutableArray *folders; NSString *currentFolder; + NSDictionary *folderData; folders = [NSMutableArray array]; - - currentFolder = [rawFolders nextObject]; - while (currentFolder) + while ((currentFolder = [rawFolders nextObject])) { - [folders addObject: [self _lineForFolder: currentFolder]]; - currentFolder = [rawFolders nextObject]; + folderData = [NSDictionary dictionaryWithObjectsAndKeys: + currentFolder, @"path", + [self _folderType: currentFolder], @"type", + nil]; + [folders addObject: folderData]; } return folders; @@ -88,24 +122,64 @@ - (WOResponse *) listMailboxesAction { SOGoMailAccount *co; - NSArray *rawFolders, *folders; + NSEnumerator *rawFolders; + NSArray *folders; WOResponse *response; co = [self clientObject]; - draftFolderName = [[co draftsFolderNameInContext: context] - substringFromIndex: 6]; - sentFolderName = [[co sentFolderNameInContext: context] - substringFromIndex: 6]; - trashFolderName = [[co trashFolderNameInContext: context] - substringFromIndex: 6]; - rawFolders = [co allFolderPaths]; - folders = [self _jsonFolders: [rawFolders objectEnumerator]]; + rawFolders = [[co allFolderPaths] objectEnumerator]; + folders = [self _jsonFolders: rawFolders]; - response = [context response]; + response = [self responseWithStatus: 200]; + [response setHeader: @"text/plain; charset=utf-8" + forKey: @"content-type"]; [response appendContentString: [folders jsonRepresentation]]; return response; } +/* compose */ + +- (WOResponse *) composeAction +{ + SOGoDraftsFolder *drafts; + SOGoDraftObject *newDraftMessage; + NSString *urlBase, *url, *value, *signature; + NSArray *mailTo; + BOOL save; + + drafts = [[self clientObject] draftsFolderInContext: context]; + newDraftMessage = [drafts newDraft]; + + save = NO; + + value = [[self request] formValueForKey: @"mailto"]; + if ([value length] > 0) + { + mailTo = [NSArray arrayWithObject: value]; + [newDraftMessage + setHeaders: [NSDictionary dictionaryWithObject: mailTo + forKey: @"to"]]; + save = YES; + } + + signature = [[context activeUser] signature]; + if ([signature length]) + { + [newDraftMessage + setText: [NSString stringWithFormat: @"\r\n--\r\n%@", signature]]; + save = YES; + } + if (save) + [newDraftMessage storeInfo]; + + urlBase = [newDraftMessage baseURLInContext: context]; + url = [urlBase composeURLWithAction: @"edit" + parameters: nil + andHash: NO]; + + return [self redirectToLocation: url]; +} + @end