2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2015-03-26 18:54:17 +01:00
|
|
|
Copyright (C) 2008-2015 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
This file is part of SOGo.
|
2008-09-28 16:02:40 +02:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
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.
|
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
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
|
2014-09-10 17:58:47 +02:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-09 21:13:42 +02:00
|
|
|
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <NGHttp/NGHttpRequest.h>
|
2007-05-09 21:13:42 +02:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2010-01-22 17:33:35 +01:00
|
|
|
#define COMPILING_NGOBJWEB 1 /* we want httpRequest for parsing multi-part
|
|
|
|
form data */
|
2007-08-17 04:42:17 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2010-01-22 17:33:35 +01:00
|
|
|
#undef COMPILING_NGOBJWEB
|
2007-05-09 21:13:42 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
#import <NGExtensions/NSException+misc.h>
|
2007-07-27 22:03:05 +02:00
|
|
|
#import <NGMime/NGMimeBodyPart.h>
|
|
|
|
#import <NGMime/NGMimeHeaderFields.h>
|
|
|
|
#import <NGMime/NGMimeMultipartBody.h>
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <NGMime/NGMimeType.h>
|
2007-05-09 21:13:42 +02:00
|
|
|
|
2013-06-11 17:21:58 +02:00
|
|
|
#import <SOGo/SOGoCache.h>
|
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
2011-02-03 17:12:22 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
2014-12-11 17:24:22 +01:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2011-02-03 17:12:22 +01:00
|
|
|
#import <SOGo/WOResourceManager+SOGo.h>
|
2006-10-12 18:42:59 +02:00
|
|
|
#import <SOGoUI/UIxComponent.h>
|
2011-12-02 08:22:47 +01:00
|
|
|
#import <Mailer/SOGoDraftObject.h>
|
2013-12-18 22:36:49 +01:00
|
|
|
#import <Mailer/SOGoMailObject+Draft.h>
|
2011-12-02 08:22:47 +01:00
|
|
|
#import <Mailer/SOGoMailFolder.h>
|
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
#import <UI/MailPartViewers/UIxMailSizeFormatter.h>
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
UIxMailEditor
|
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
A mail editor component which works on SOGoDraftObject's.
|
2006-06-15 21:34:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
@interface UIxMailEditor : UIxComponent
|
|
|
|
{
|
|
|
|
NSArray *to;
|
|
|
|
NSArray *cc;
|
|
|
|
NSArray *bcc;
|
|
|
|
NSString *subject;
|
2010-06-25 21:58:30 +02:00
|
|
|
NSString *sourceUID;
|
|
|
|
NSString *sourceFolder;
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *text;
|
2010-04-08 17:27:46 +02:00
|
|
|
NSMutableArray *fromEMails;
|
2014-12-12 03:11:20 +01:00
|
|
|
NSString *from;
|
2006-06-15 21:34:10 +02:00
|
|
|
SOGoMailFolder *sentFolder;
|
2010-11-23 14:53:54 +01:00
|
|
|
BOOL isHTML;
|
2017-12-23 13:20:08 +01:00
|
|
|
BOOL sign;
|
|
|
|
BOOL encrypt;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
NSString *priority;
|
2010-08-31 15:49:31 +02:00
|
|
|
NSString *receipt;
|
2008-09-28 16:02:40 +02:00
|
|
|
id item;
|
2011-12-02 08:22:47 +01:00
|
|
|
id currentFolder;
|
2008-09-28 16:02:40 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* these are for the inline attachment list */
|
2013-12-18 22:36:49 +01:00
|
|
|
NSDictionary *attachment;
|
|
|
|
NSArray *attachmentAttrs;
|
|
|
|
NSString *currentAttachment;
|
2007-12-06 17:27:28 +01:00
|
|
|
NSMutableArray *attachedFiles;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation UIxMailEditor
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
static NSArray *infoKeys = nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
if (!infoKeys)
|
|
|
|
infoKeys = [[NSArray alloc] initWithObjects:
|
|
|
|
@"subject", @"to", @"cc", @"bcc",
|
2010-08-31 15:49:31 +02:00
|
|
|
@"from", @"inReplyTo",
|
2012-04-20 15:27:21 +02:00
|
|
|
@"replyTo",
|
2014-12-16 21:47:34 +01:00
|
|
|
@"priority", @"receipt", @"isHTML",
|
2017-12-23 13:20:08 +01:00
|
|
|
@"text", @"sign", @"encrypt", nil];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2008-10-23 17:55:56 +02:00
|
|
|
priority = @"NORMAL";
|
2010-08-31 15:49:31 +02:00
|
|
|
receipt = nil;
|
2011-12-02 08:22:47 +01:00
|
|
|
currentFolder = nil;
|
2013-12-18 22:36:49 +01:00
|
|
|
currentAttachment = nil;
|
|
|
|
attachmentAttrs = nil;
|
|
|
|
attachedFiles = nil;
|
2008-09-28 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2008-09-28 16:02:40 +02:00
|
|
|
[item release];
|
|
|
|
[priority release];
|
2010-08-31 15:49:31 +02:00
|
|
|
[receipt release];
|
2007-05-09 21:13:42 +02:00
|
|
|
[sentFolder release];
|
|
|
|
[fromEMails release];
|
2007-08-17 04:42:17 +02:00
|
|
|
[from release];
|
|
|
|
[text release];
|
2007-05-09 21:13:42 +02:00
|
|
|
[subject release];
|
2007-08-17 04:42:17 +02:00
|
|
|
[to release];
|
|
|
|
[cc release];
|
|
|
|
[bcc release];
|
2010-06-25 21:58:30 +02:00
|
|
|
[sourceUID release];
|
|
|
|
[sourceFolder release];
|
2013-12-18 22:36:49 +01:00
|
|
|
[attachment release];
|
|
|
|
[currentAttachment release];
|
|
|
|
[attachmentAttrs release];
|
2007-12-06 17:27:28 +01:00
|
|
|
[attachedFiles release];
|
2011-12-02 08:22:47 +01:00
|
|
|
[currentFolder release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
2008-09-28 16:02:40 +02:00
|
|
|
- (void) setItem: (id) _item
|
|
|
|
{
|
|
|
|
ASSIGN (item, _item);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) item
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2013-12-20 21:37:01 +01:00
|
|
|
- (NSString *) uid
|
|
|
|
{
|
|
|
|
return [[self clientObject] nameInContainer];
|
|
|
|
}
|
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
- (NSArray *) priorityClasses
|
|
|
|
{
|
|
|
|
static NSArray *priorities = nil;
|
|
|
|
|
|
|
|
if (!priorities)
|
|
|
|
{
|
|
|
|
priorities = [NSArray arrayWithObjects: @"HIGHEST", @"HIGH",
|
|
|
|
@"NORMAL", @"LOW", @"LOWEST", nil];
|
|
|
|
[priorities retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return priorities;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPriority: (NSString *) _priority
|
|
|
|
{
|
2010-08-31 15:49:31 +02:00
|
|
|
ASSIGN (priority, _priority);
|
2008-09-28 16:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) priority
|
|
|
|
{
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
2010-08-31 15:49:31 +02:00
|
|
|
- (void) setReceipt: (NSString *) newReceipt
|
|
|
|
{
|
|
|
|
ASSIGN (receipt, newReceipt);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) receipt
|
|
|
|
{
|
|
|
|
return receipt;
|
|
|
|
}
|
|
|
|
|
2010-11-23 14:53:54 +01:00
|
|
|
- (void) setIsHTML: (BOOL) aBool
|
|
|
|
{
|
|
|
|
isHTML = aBool;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isHTML
|
|
|
|
{
|
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
|
|
|
|
return [[ud mailComposeMessageType] isEqualToString: @"html"];
|
|
|
|
}
|
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
- (NSString *) editorClass
|
|
|
|
{
|
|
|
|
return ([self isHTML]? @"ck-editor" : @"plain-text");
|
|
|
|
}
|
|
|
|
|
2008-09-28 16:02:40 +02:00
|
|
|
- (NSString *) itemPriorityText
|
|
|
|
{
|
|
|
|
return [self labelForKey: [NSString stringWithFormat: @"%@", [item lowercaseString]]];
|
|
|
|
}
|
|
|
|
|
2008-04-15 17:01:16 +02:00
|
|
|
- (NSString *) isMailReply
|
|
|
|
{
|
|
|
|
return ([to count] > 0 ? @"true" : @"false");
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-06-30 20:37:12 +02:00
|
|
|
- (NSString *) localeCode
|
|
|
|
{
|
|
|
|
// WARNING : NSLocaleCode is not defined in <Foundation/NSUserDefaults.h>
|
2015-03-19 13:32:37 +01:00
|
|
|
// Region subtag must be separated by a dash
|
2015-03-26 18:54:17 +01:00
|
|
|
NSMutableString *s = [NSMutableString stringWithString: [locale objectForKey: @"NSLocaleCode"]];
|
|
|
|
|
|
|
|
[s replaceOccurrencesOfString: @"_"
|
|
|
|
withString: @"-"
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(0, [s length])];
|
|
|
|
|
|
|
|
return s;
|
2010-06-30 20:37:12 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) setFrom: (NSString *) newFrom
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
ASSIGN (from, newFrom);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2014-12-12 03:11:20 +01:00
|
|
|
- (NSString *) _emailFromIdentity: (NSDictionary *) identity
|
2010-04-08 17:27:46 +02:00
|
|
|
{
|
2014-12-12 03:11:20 +01:00
|
|
|
NSString *fullName, *format;
|
2010-04-08 17:27:46 +02:00
|
|
|
|
2014-12-12 03:11:20 +01:00
|
|
|
fullName = [identity objectForKey: @"fullName"];
|
|
|
|
if ([fullName length])
|
|
|
|
format = @"%{fullName} <%{email}>";
|
|
|
|
else
|
|
|
|
format = @"%{email}";
|
2010-04-08 17:27:46 +02:00
|
|
|
|
2014-12-12 03:11:20 +01:00
|
|
|
return [identity keysWithFormat: format];
|
2010-04-08 17:27:46 +02:00
|
|
|
}
|
|
|
|
|
2014-12-12 03:11:20 +01:00
|
|
|
- (NSString *) from
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2016-05-10 20:41:24 +02:00
|
|
|
NSArray *identities;
|
2018-07-09 21:49:36 +02:00
|
|
|
NSEnumerator *allIdentities;
|
|
|
|
NSDictionary *identity;
|
|
|
|
NSRange r;
|
|
|
|
BOOL valid;
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2018-07-09 21:49:36 +02:00
|
|
|
identities = [[[self clientObject] mailAccountFolder] identities];
|
|
|
|
if ([identities count])
|
2007-08-17 04:42:17 +02:00
|
|
|
{
|
2018-07-09 21:49:36 +02:00
|
|
|
if (from)
|
|
|
|
{
|
|
|
|
allIdentities = [identities objectEnumerator];
|
|
|
|
valid = NO;
|
|
|
|
while ((identity = [allIdentities nextObject]) && !valid)
|
|
|
|
{
|
|
|
|
// from ivar must contain a valid email address surrounded by pointy brackets
|
|
|
|
r = [[from lowercaseString] rangeOfString: [NSString stringWithFormat: @"<%@>", [[identity objectForKey: @"email"] lowercaseString]]];
|
|
|
|
if (r.length > 0)
|
|
|
|
{
|
|
|
|
valid = YES;
|
|
|
|
[from release];
|
|
|
|
from = [self _emailFromIdentity: identity];
|
|
|
|
[from retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!valid)
|
|
|
|
{
|
|
|
|
[from release];
|
|
|
|
from = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!from)
|
2016-05-10 20:41:24 +02:00
|
|
|
{
|
|
|
|
from = [self _emailFromIdentity: [identities objectAtIndex: 0]];
|
|
|
|
[from retain];
|
|
|
|
}
|
2007-08-17 04:42:17 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2007-05-09 21:13:42 +02:00
|
|
|
return from;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
- (NSString *) replyTo
|
|
|
|
{
|
2013-11-19 17:39:45 +01:00
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
value = nil;
|
|
|
|
|
|
|
|
//
|
|
|
|
// We add the correct replyTo here. That is, the one specified in the defaults
|
|
|
|
// for the main "SOGo mail account" versus the one specified in the auxiliary
|
|
|
|
// IMAP accounts.
|
|
|
|
//
|
|
|
|
if ([[[[self clientObject] mailAccountFolder] nameInContainer] intValue] == 0)
|
|
|
|
{
|
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
value = [ud mailReplyTo];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSArray *identities;
|
|
|
|
|
|
|
|
identities = [[[self clientObject] mailAccountFolder] identities];
|
2012-04-20 15:27:21 +02:00
|
|
|
|
2013-11-19 17:39:45 +01:00
|
|
|
if ([identities count])
|
|
|
|
value = [[identities objectAtIndex: 0] objectForKey: @"replyTo"];
|
|
|
|
}
|
2012-04-20 15:27:21 +02:00
|
|
|
|
2013-11-19 17:39:45 +01:00
|
|
|
return value;
|
2012-04-20 15:27:21 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) setSubject: (NSString *) newSubject
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
ASSIGN (subject, newSubject);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
- (NSString *) subject
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
return subject;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) setText: (NSString *) newText
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
ASSIGN (text, newText);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
- (NSString *) text
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
return text;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2010-06-25 21:58:30 +02:00
|
|
|
- (void) setSourceUID: (int) newSourceUID
|
|
|
|
{
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [NSString stringWithFormat: @"%i", newSourceUID];
|
|
|
|
ASSIGN (sourceUID, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) sourceUID
|
|
|
|
{
|
|
|
|
return sourceUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSourceFolder: (NSString *) newSourceFolder
|
|
|
|
{
|
|
|
|
ASSIGN (sourceFolder, newSourceFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) sourceFolder
|
|
|
|
{
|
|
|
|
return sourceFolder;
|
|
|
|
}
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) setTo: (NSArray *) newTo
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
if ([newTo isKindOfClass: [NSNull class]])
|
|
|
|
newTo = nil;
|
|
|
|
|
|
|
|
ASSIGN (to, newTo);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
- (NSArray *) to
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
return to;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) setCc: (NSArray *) newCc
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
if ([newCc isKindOfClass: [NSNull class]])
|
|
|
|
newCc = nil;
|
|
|
|
|
|
|
|
ASSIGN (cc, newCc);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
- (NSArray *) cc
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
return cc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) setBcc: (NSArray *) newBcc
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
if ([newBcc isKindOfClass: [NSNull class]])
|
|
|
|
newBcc = nil;
|
|
|
|
|
|
|
|
ASSIGN (bcc, newBcc);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
- (NSArray *) bcc
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
return bcc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
- (BOOL) hasOneOrMoreRecipients
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
return (([to count] + [cc count] + [bcc count]) > 0);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
- (void) setAttachment: (NSDictionary *) newAttachment
|
|
|
|
{
|
|
|
|
ASSIGN (attachment, newAttachment);
|
|
|
|
}
|
|
|
|
|
2013-12-20 21:37:01 +01:00
|
|
|
- (NSDictionary *) attachment
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2013-12-20 21:37:01 +01:00
|
|
|
return attachment;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2013-12-20 21:37:01 +01:00
|
|
|
- (NSFormatter *) sizeFormatter
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2013-12-20 21:37:01 +01:00
|
|
|
return [UIxMailSizeFormatter sharedMailSizeFormatter];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* from addresses */
|
|
|
|
|
2007-05-09 21:13:42 +02:00
|
|
|
- (NSArray *) fromEMails
|
|
|
|
{
|
2010-08-06 16:27:06 +02:00
|
|
|
NSArray *identities;
|
2010-04-08 17:27:46 +02:00
|
|
|
int count, max;
|
2014-12-12 03:11:20 +01:00
|
|
|
NSString *email;
|
2010-08-06 16:27:06 +02:00
|
|
|
SOGoMailAccount *account;
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2007-05-09 21:13:42 +02:00
|
|
|
if (!fromEMails)
|
|
|
|
{
|
2010-08-06 16:27:06 +02:00
|
|
|
account = [[self clientObject] mailAccountFolder];
|
|
|
|
identities = [account identities];
|
|
|
|
max = [identities count];
|
|
|
|
fromEMails = [[NSMutableArray alloc] initWithCapacity: max];
|
2010-04-08 17:27:46 +02:00
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
2014-12-11 17:24:22 +01:00
|
|
|
email = [self _emailFromIdentity: [identities objectAtIndex: count]];
|
2010-04-08 17:27:46 +02:00
|
|
|
[fromEMails addObjectUniquely: email];
|
|
|
|
}
|
2007-05-09 21:13:42 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:13:42 +02:00
|
|
|
return fromEMails;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* info loading */
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
- (void) loadInfo: (NSDictionary *) _info
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
if (![_info isNotNull]) return;
|
|
|
|
[self debugWithFormat:@"loading info ..."];
|
2016-05-10 20:41:24 +02:00
|
|
|
[self setValuesForKeysWithDictionary: _info];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
- (NSDictionary *) infoFromRequest
|
2007-08-17 04:42:17 +02:00
|
|
|
{
|
2014-12-11 17:24:22 +01:00
|
|
|
WORequest *request;
|
|
|
|
NSDictionary *params, *filteredParams;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
params = [[request contentAsString] objectFromJSONString];
|
|
|
|
filteredParams = [NSDictionary dictionaryWithObjects: [params objectsForKeys: infoKeys notFoundMarker: [NSNull null]]
|
|
|
|
forKeys: infoKeys];
|
|
|
|
|
2016-05-10 20:41:24 +02:00
|
|
|
[self setFrom: [filteredParams objectForKey: @"from"]];
|
2014-12-11 17:24:22 +01:00
|
|
|
[self setTo: [filteredParams objectForKey: @"to"]];
|
|
|
|
[self setCc: [filteredParams objectForKey: @"cc"]];
|
|
|
|
[self setBcc: [filteredParams objectForKey: @"bcc"]];
|
2014-12-16 21:47:34 +01:00
|
|
|
[self setIsHTML: [[filteredParams objectForKey: @"isHTML"] boolValue]];
|
2014-12-12 03:11:20 +01:00
|
|
|
[self setText: [filteredParams objectForKey: @"text"]];
|
2014-12-11 17:24:22 +01:00
|
|
|
|
2017-12-23 13:20:08 +01:00
|
|
|
// S/MIME parameters
|
|
|
|
sign = [[filteredParams objectForKey: @"sign"] boolValue];
|
|
|
|
encrypt = [[filteredParams objectForKey: @"encrypt"] boolValue];
|
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
return filteredParams;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:22:47 +01:00
|
|
|
/* contacts search */
|
2014-12-11 17:24:22 +01:00
|
|
|
// - (NSArray *) contactFolders
|
|
|
|
// {
|
|
|
|
// SOGoContactFolders *folderContainer;
|
2011-12-02 08:22:47 +01:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
// folderContainer = (SOGoContactFolders *) [[[self clientObject] lookupUserFolder] privateContacts: @"Contacts"
|
|
|
|
// inContext: nil];
|
2011-12-02 08:22:47 +01:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
// return [folderContainer subFolders];
|
|
|
|
// }
|
2011-12-02 08:22:47 +01:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
// - (NSArray *) personalContactInfos
|
|
|
|
// {
|
|
|
|
// SOGoContactFolders *folderContainer;
|
|
|
|
// id <SOGoContactFolder> folder;
|
|
|
|
// NSArray *contactInfos;
|
2011-12-02 08:22:47 +01:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
// folderContainer = (SOGoContactFolders *) [[[self clientObject] lookupUserFolder] privateContacts: @"Contacts"
|
|
|
|
// inContext: nil];
|
2012-05-31 16:51:18 +02:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
// folder = [folderContainer lookupPersonalFolder: @"personal" ignoringRights: YES];
|
|
|
|
|
|
|
|
// // If the folder doesn't exist anymore or if the database is down, we
|
|
|
|
// // return an empty array.
|
|
|
|
// if ([folder isKindOfClass: [NSException class]])
|
|
|
|
// return [NSArray array];
|
|
|
|
|
|
|
|
// contactInfos = [folder lookupContactsWithFilter: nil
|
|
|
|
// onCriteria: nil
|
|
|
|
// sortBy: @"c_cn"
|
|
|
|
// ordering: NSOrderedAscending
|
|
|
|
// inDomain: nil];
|
2011-12-02 08:22:47 +01:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
// return contactInfos;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (void) setCurrentFolder: (id) _currentFolder
|
|
|
|
// {
|
|
|
|
// ASSIGN (currentFolder, _currentFolder);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) currentContactFolderId
|
|
|
|
// {
|
|
|
|
// return [NSString stringWithFormat: @"/%@", [currentFolder nameInContainer]];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) currentContactFolderName
|
|
|
|
// {
|
|
|
|
// return [currentFolder displayName];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) currentContactFolderOwner
|
|
|
|
// {
|
|
|
|
// return [currentFolder ownerInContext: context];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) currentContactFolderClass
|
|
|
|
// {
|
|
|
|
// return ([currentFolder isKindOfClass: [SOGoContactSourceFolder class]]
|
|
|
|
// ? @"remote" : @"local");
|
|
|
|
// }
|
2011-12-02 08:22:47 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* actions */
|
2007-12-06 17:27:28 +01:00
|
|
|
- (NSString *) _fixedFilename: (NSString *) filename
|
|
|
|
{
|
|
|
|
NSString *newFilename, *baseFilename, *extension;
|
|
|
|
unsigned int variation;
|
|
|
|
|
|
|
|
if (!attachedFiles)
|
|
|
|
attachedFiles = [NSMutableArray new];
|
|
|
|
|
2016-05-31 21:34:48 +02:00
|
|
|
newFilename = [filename stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\""]; /* to real filename */
|
|
|
|
baseFilename = [newFilename stringByDeletingPathExtension];
|
|
|
|
extension = [newFilename pathExtension];
|
2007-12-06 17:27:28 +01:00
|
|
|
variation = 0;
|
|
|
|
while ([attachedFiles containsObject: newFilename])
|
|
|
|
{
|
|
|
|
variation++;
|
|
|
|
newFilename = [NSString stringWithFormat: @"%@-%d.%@", baseFilename,
|
|
|
|
variation, extension];
|
|
|
|
}
|
|
|
|
[attachedFiles addObject: newFilename];
|
|
|
|
|
|
|
|
return newFilename;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-27 22:03:05 +02:00
|
|
|
- (NSDictionary *) _scanAttachmentFilenamesInRequest: (id) httpBody
|
|
|
|
{
|
2013-12-18 22:36:49 +01:00
|
|
|
NSMutableDictionary *files;
|
|
|
|
NSDictionary *file;
|
2007-07-27 22:03:05 +02:00
|
|
|
NSArray *parts;
|
|
|
|
unsigned int count, max;
|
|
|
|
NGMimeBodyPart *part;
|
|
|
|
NGMimeContentDispositionHeaderField *header;
|
2007-12-06 17:27:28 +01:00
|
|
|
NSString *mimeType, *filename;
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
parts = [httpBody parts];
|
|
|
|
max = [parts count];
|
2013-12-18 22:36:49 +01:00
|
|
|
files = [NSMutableDictionary dictionaryWithCapacity: max];
|
2007-07-27 22:03:05 +02:00
|
|
|
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
part = [parts objectAtIndex: count];
|
2013-12-18 22:36:49 +01:00
|
|
|
header = (NGMimeContentDispositionHeaderField *)[part headerForKey: @"content-disposition"];
|
|
|
|
if ([[header name] hasPrefix: @"attachments"])
|
|
|
|
{
|
|
|
|
mimeType = [(NGMimeType *)[part headerForKey: @"content-type"] stringValue];
|
|
|
|
filename = [self _fixedFilename: [header filename]];
|
|
|
|
file = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
filename, @"filename",
|
|
|
|
mimeType, @"mimetype",
|
|
|
|
[part body], @"body",
|
|
|
|
nil];
|
|
|
|
[files setObject: file forKey: [NSString stringWithFormat: @"%@_%@", [header name], filename]];
|
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
return files;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
- (NSException *) _saveAttachments
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2013-12-18 22:36:49 +01:00
|
|
|
NSException *error;
|
2007-07-27 22:03:05 +02:00
|
|
|
WORequest *request;
|
2013-12-18 22:36:49 +01:00
|
|
|
NSEnumerator *allAttachments;
|
|
|
|
NSDictionary *attrs, *filenames;
|
2007-07-27 22:03:05 +02:00
|
|
|
id httpBody;
|
|
|
|
SOGoDraftObject *co;
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
error = nil;
|
2007-07-27 22:03:05 +02:00
|
|
|
request = [context request];
|
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
httpBody = [[request httpRequest] body];
|
2016-02-17 14:24:32 +01:00
|
|
|
|
|
|
|
// We got an exception from SOPE - most likely due to
|
|
|
|
// WOMaxUploadSize being reached.
|
|
|
|
if ([httpBody isKindOfClass: [NSException class]])
|
|
|
|
return httpBody;
|
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
filenames = [self _scanAttachmentFilenamesInRequest: httpBody];
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
co = [self clientObject];
|
|
|
|
allAttachments = [filenames objectEnumerator];
|
|
|
|
while ((attrs = [allAttachments nextObject]) && !error)
|
|
|
|
{
|
|
|
|
error = [co saveAttachment: (NSData *) [attrs objectForKey: @"body"]
|
|
|
|
withMetadata: attrs];
|
|
|
|
// Keep the name of the last attachment saved
|
|
|
|
ASSIGN(currentAttachment, [attrs objectForKey: @"filename"]);
|
2013-12-18 22:36:49 +01:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
return error;
|
2007-07-27 22:03:05 +02:00
|
|
|
}
|
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
/**
|
|
|
|
* Save received data to the filesystem, either the attached files or the message itself.
|
|
|
|
*/
|
|
|
|
- (NSException *) _saveRequestInfo
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSDictionary *info;
|
2007-07-27 22:03:05 +02:00
|
|
|
NSException *error;
|
2016-02-11 22:45:58 +01:00
|
|
|
NSString *fontSize, *content;
|
2014-12-16 21:47:34 +01:00
|
|
|
NGMimeType *mimeType;
|
|
|
|
WORequest *request;
|
2007-08-17 04:42:17 +02:00
|
|
|
SOGoDraftObject *co;
|
2016-02-11 22:45:58 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
error = nil;
|
|
|
|
request = [context request];
|
|
|
|
mimeType = [[request httpRequest] contentType];
|
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
[co fetchInfo];
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
if ([[mimeType type] isEqualToString: @"multipart"])
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2014-12-16 21:47:34 +01:00
|
|
|
error = [self _saveAttachments];
|
|
|
|
}
|
|
|
|
else if ([[mimeType subType] isEqualToString: @"json"])
|
|
|
|
{
|
|
|
|
info = [self infoFromRequest];
|
2007-08-17 04:42:17 +02:00
|
|
|
[co setHeaders: info];
|
2015-12-08 20:14:46 +01:00
|
|
|
[co setIsHTML: isHTML];
|
2017-12-23 13:20:08 +01:00
|
|
|
[co setSign: sign];
|
|
|
|
[co setEncrypt: encrypt];
|
2016-02-11 22:45:58 +01:00
|
|
|
if (isHTML)
|
|
|
|
{
|
|
|
|
// Set a base font size if mail is HTML and user has set a default font-size
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
fontSize = [ud mailComposeFontSize];
|
|
|
|
if ([fontSize intValue] > 0)
|
|
|
|
content = [NSString stringWithFormat: @"<html><span style=\"font-size: %@px;\">%@</span></html>",
|
|
|
|
fontSize, text];
|
|
|
|
else
|
|
|
|
content = [NSString stringWithFormat: @"<html>%@</html>", text];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
content = text;
|
|
|
|
}
|
|
|
|
[co setText: content];
|
2007-08-17 04:42:17 +02:00
|
|
|
error = [co storeInfo];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
return error;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-27 22:03:05 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
- (id) failedToSaveFormResponse: (NSString *) msg
|
2007-07-30 20:39:55 +02:00
|
|
|
{
|
2013-12-18 22:36:49 +01:00
|
|
|
NSDictionary *d;
|
|
|
|
|
2017-01-06 22:17:05 +01:00
|
|
|
d = [NSDictionary dictionaryWithObjectsAndKeys: msg, @"message", nil];
|
2013-12-18 22:36:49 +01:00
|
|
|
|
2017-01-06 22:17:05 +01:00
|
|
|
return [self responseWithStatus: 500 andJSONRepresentation: d];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attachment helper */
|
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
- (NSArray *) attachmentAttrs
|
2007-07-30 20:39:55 +02:00
|
|
|
{
|
2013-12-18 22:36:49 +01:00
|
|
|
SOGoDraftObject *co;
|
|
|
|
SOGoMailObject *mail;
|
2014-05-30 19:53:20 +02:00
|
|
|
NSArray *a;
|
2013-12-18 22:36:49 +01:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
if (!attachmentAttrs || ![co imap4URL])
|
|
|
|
{
|
|
|
|
[co fetchInfo];
|
2014-06-12 15:09:08 +02:00
|
|
|
if ((![co inReplyTo] || currentAttachment) && [co IMAP4ID] > -1)
|
2013-12-18 22:36:49 +01:00
|
|
|
{
|
2014-06-12 15:09:08 +02:00
|
|
|
// When currentAttachment is defined, it means we just attached a new file to the mail
|
2013-12-18 22:36:49 +01:00
|
|
|
mail = [[[SOGoMailObject alloc] initWithImap4URL: [co imap4URL] inContainer: [co container]] autorelease];
|
|
|
|
a = [mail fetchFileAttachmentKeys];
|
|
|
|
ASSIGN (attachmentAttrs, a);
|
|
|
|
}
|
|
|
|
}
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
if (currentAttachment)
|
2007-12-06 17:27:28 +01:00
|
|
|
{
|
2013-12-18 22:36:49 +01:00
|
|
|
// When currentAttachment is defined, only return the attributes of the last
|
|
|
|
// attachment saved
|
|
|
|
NSEnumerator *allAttachments;
|
|
|
|
NSDictionary* attrs;
|
|
|
|
|
|
|
|
allAttachments = [attachmentAttrs objectEnumerator];
|
|
|
|
while ((attrs = [allAttachments nextObject]))
|
|
|
|
{
|
|
|
|
if ([[attrs objectForKey: @"filename"] isEqualToString: currentAttachment])
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObject: attrs];
|
|
|
|
}
|
|
|
|
}
|
2007-12-06 17:27:28 +01:00
|
|
|
}
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2013-12-18 22:36:49 +01:00
|
|
|
return attachmentAttrs;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-30 20:39:55 +02:00
|
|
|
|
|
|
|
- (BOOL) hasAttachments
|
|
|
|
{
|
2013-12-18 22:36:49 +01:00
|
|
|
return [[self attachmentAttrs] count] > 0 ? YES : NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
- (id <WOActionResults>) editAction
|
2007-07-27 22:03:05 +02:00
|
|
|
{
|
2014-12-11 17:24:22 +01:00
|
|
|
id <WOActionResults> response;
|
2007-08-17 04:42:17 +02:00
|
|
|
SOGoDraftObject *co;
|
2014-12-11 17:24:22 +01:00
|
|
|
NSMutableDictionary *data;
|
|
|
|
id value;
|
2007-08-17 04:42:17 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
[co fetchInfo];
|
|
|
|
[self loadInfo: [co headers]];
|
|
|
|
[self setText: [co text]];
|
2010-06-25 21:58:30 +02:00
|
|
|
[self setSourceUID: [co IMAP4ID]];
|
|
|
|
[self setSourceFolder: [co sourceFolder]];
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
2014-12-16 21:47:34 +01:00
|
|
|
[self from], @"from",
|
2014-12-11 17:24:22 +01:00
|
|
|
[self localeCode], @"locale",
|
2014-12-16 21:47:34 +01:00
|
|
|
[NSNumber numberWithBool: [self isHTML]], @"isHTML",
|
2014-12-12 03:11:20 +01:00
|
|
|
text, @"text",
|
2014-12-11 17:24:22 +01:00
|
|
|
nil];
|
|
|
|
if ((value = [self replyTo]))
|
|
|
|
[data setObject: value forKey: @"replyTo"];
|
|
|
|
if ((value = [self to]))
|
|
|
|
[data setObject: value forKey: @"to"];
|
|
|
|
if ((value = [self cc]))
|
|
|
|
[data setObject: value forKey: @"cc"];
|
|
|
|
if ((value = [self bcc]))
|
|
|
|
[data setObject: value forKey: @"bcc"];
|
|
|
|
if ((value = [self subject]))
|
|
|
|
[data setObject: value forKey: @"subject"];
|
|
|
|
if ((value = [self attachmentAttrs]))
|
|
|
|
[data setObject: value forKey: @"attachmentAttrs"];
|
2017-12-23 13:20:08 +01:00
|
|
|
|
2014-12-11 17:24:22 +01:00
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andString: [data jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) saveAction
|
2007-07-30 20:39:55 +02:00
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
id result;
|
2014-12-11 17:24:22 +01:00
|
|
|
NSArray *attrs;
|
2014-12-16 21:47:34 +01:00
|
|
|
NSDictionary *data;
|
|
|
|
SOGoDraftObject *co;
|
2007-08-17 04:42:17 +02:00
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
co = [self clientObject];
|
2014-12-11 17:24:22 +01:00
|
|
|
[self setIsHTML: [self isHTML]];
|
2014-12-16 21:47:34 +01:00
|
|
|
|
|
|
|
result = [self _saveRequestInfo];
|
2013-12-18 22:36:49 +01:00
|
|
|
if (!result)
|
2007-08-17 04:42:17 +02:00
|
|
|
{
|
2014-12-16 21:47:34 +01:00
|
|
|
// Save message to IMAP server
|
|
|
|
result = [co save];
|
2013-12-18 22:36:49 +01:00
|
|
|
}
|
|
|
|
if (!result)
|
|
|
|
{
|
2014-12-16 21:47:34 +01:00
|
|
|
// Save new UID to plist
|
|
|
|
[self setSourceUID: [co IMAP4ID]];
|
|
|
|
[co storeInfo];
|
|
|
|
|
|
|
|
// Prepare response
|
2013-12-18 22:36:49 +01:00
|
|
|
attachmentAttrs = nil;
|
2014-12-11 17:24:22 +01:00
|
|
|
attrs = [self attachmentAttrs];
|
2014-12-16 21:47:34 +01:00
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[self sourceUID], @"uid",
|
|
|
|
attrs, @"lastAttachmentAttrs",
|
|
|
|
nil];
|
2013-12-18 22:36:49 +01:00
|
|
|
result = [self responseWithStatus: 200
|
2014-12-16 21:47:34 +01:00
|
|
|
andString: [data jsonRepresentation]];
|
2007-08-17 04:42:17 +02:00
|
|
|
}
|
|
|
|
else
|
2013-12-18 22:36:49 +01:00
|
|
|
result = [self failedToSaveFormResponse: [result reason]];
|
2007-08-17 04:42:17 +02:00
|
|
|
|
|
|
|
return result;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-07-30 20:39:55 +02:00
|
|
|
- (NSException *) validateForSend
|
|
|
|
{
|
2007-08-17 04:42:17 +02:00
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
if (![self hasOneOrMoreRecipients])
|
|
|
|
error = [NSException exceptionWithHTTPStatus: 400 /* Bad Request */
|
2012-05-29 16:20:06 +02:00
|
|
|
reason: [self labelForKey: @"error_missingrecipients"]];
|
2007-08-17 04:42:17 +02:00
|
|
|
else
|
|
|
|
error = nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-17 04:42:17 +02:00
|
|
|
return error;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2013-06-11 17:21:58 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2010-08-23 22:58:41 +02:00
|
|
|
- (WOResponse *) sendAction
|
2006-10-12 18:42:59 +02:00
|
|
|
{
|
2010-06-25 21:58:30 +02:00
|
|
|
SOGoDraftObject *co;
|
2010-08-23 22:58:41 +02:00
|
|
|
NSDictionary *jsonResponse;
|
|
|
|
NSException *error;
|
2010-11-10 21:12:18 +01:00
|
|
|
NSMutableArray *errorMsg;
|
2013-06-11 17:21:58 +02:00
|
|
|
NSDictionary *messageSubmissions;
|
|
|
|
SOGoSystemDefaults *dd;
|
2015-12-09 15:44:33 +01:00
|
|
|
id <WOActionResults> response;
|
2013-06-11 17:21:58 +02:00
|
|
|
|
2017-07-04 15:57:05 +02:00
|
|
|
NSUInteger messages_count, recipients_count;
|
2013-06-11 17:21:58 +02:00
|
|
|
|
|
|
|
messageSubmissions = [[SOGoCache sharedCache] messageSubmissionsCountForLogin: [[context activeUser] login]];
|
|
|
|
dd = [SOGoSystemDefaults sharedSystemDefaults];
|
|
|
|
messages_count = recipients_count = 0;
|
|
|
|
|
|
|
|
if (messageSubmissions)
|
|
|
|
{
|
|
|
|
unsigned int current_time, start_time, delta, block_time;
|
|
|
|
|
|
|
|
current_time = [[NSCalendarDate date] timeIntervalSince1970];
|
|
|
|
start_time = [[messageSubmissions objectForKey: @"InitialDate"] unsignedIntValue];
|
|
|
|
delta = current_time - start_time;
|
|
|
|
|
|
|
|
block_time = [dd messageSubmissionBlockInterval];
|
|
|
|
messages_count = [[messageSubmissions objectForKey: @"MessagesCount"] intValue];
|
|
|
|
recipients_count = [[messageSubmissions objectForKey: @"RecipientsCount"] intValue];
|
|
|
|
|
|
|
|
if ((messages_count >= [dd maximumMessageSubmissionCount] || recipients_count >= [dd maximumRecipientCount]) &&
|
2013-12-16 23:48:23 +01:00
|
|
|
delta <= block_time)
|
2013-06-11 17:21:58 +02:00
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"failure", @"status",
|
2013-12-16 23:48:23 +01:00
|
|
|
[self labelForKey: @"Tried to send too many mails. Please wait."],
|
2013-06-11 17:21:58 +02:00
|
|
|
@"message",
|
|
|
|
nil];
|
|
|
|
return [self responseWithStatus: 200
|
|
|
|
andString: [jsonResponse jsonRepresentation]];
|
|
|
|
}
|
|
|
|
|
2013-12-16 23:48:23 +01:00
|
|
|
if (delta > block_time ||
|
|
|
|
(delta >= [dd maximumSubmissionInterval] && messages_count < [dd maximumMessageSubmissionCount] && recipients_count < [dd maximumRecipientCount]))
|
2013-06-11 17:21:58 +02:00
|
|
|
{
|
|
|
|
[[SOGoCache sharedCache] setMessageSubmissionsCount: 0
|
|
|
|
recipientsCount: 0
|
|
|
|
forLogin: [[context activeUser] login]];
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 22:58:41 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2006-10-12 18:42:59 +02:00
|
|
|
|
2014-12-16 21:47:34 +01:00
|
|
|
// First, save form data to filesystem
|
|
|
|
error = [self _saveRequestInfo];
|
2010-08-23 22:58:41 +02:00
|
|
|
if (!error)
|
2007-08-17 04:42:17 +02:00
|
|
|
{
|
2014-12-11 17:24:22 +01:00
|
|
|
error = [self validateForSend];
|
2013-12-18 22:36:49 +01:00
|
|
|
if (!error)
|
2016-08-12 17:38:05 +02:00
|
|
|
error = [co sendMail];
|
2007-08-17 04:42:17 +02:00
|
|
|
else
|
2013-12-18 22:36:49 +01:00
|
|
|
error = [self failedToSaveFormResponse: [error reason]];
|
2007-08-17 04:42:17 +02:00
|
|
|
}
|
2006-10-12 18:42:59 +02:00
|
|
|
|
2010-08-23 22:58:41 +02:00
|
|
|
if (error)
|
2010-11-10 21:12:18 +01:00
|
|
|
{
|
|
|
|
// Only the first line is translated
|
|
|
|
errorMsg = [NSMutableArray arrayWithArray: [[error reason] componentsSeparatedByString: @"\n"]];
|
|
|
|
[errorMsg replaceObjectAtIndex: 0
|
|
|
|
withObject: [self labelForKey: [errorMsg objectAtIndex: 0]]];
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"failure", @"status",
|
|
|
|
[errorMsg componentsJoinedByString: @"\n"],
|
|
|
|
@"message",
|
|
|
|
nil];
|
2015-12-09 15:44:33 +01:00
|
|
|
response = [self responseWithStatus: 405
|
|
|
|
andJSONRepresentation: jsonResponse];
|
2010-11-10 21:12:18 +01:00
|
|
|
}
|
2010-08-23 22:58:41 +02:00
|
|
|
else
|
2013-06-11 17:21:58 +02:00
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"success", @"status",
|
|
|
|
[co sourceFolder], @"sourceFolder",
|
2014-07-09 17:17:36 +02:00
|
|
|
[NSNumber numberWithInt: [co sourceIMAP4ID]], @"sourceMessageID",
|
2013-06-11 17:21:58 +02:00
|
|
|
nil];
|
2015-12-09 15:44:33 +01:00
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andJSONRepresentation: jsonResponse];
|
2013-06-11 17:21:58 +02:00
|
|
|
|
|
|
|
recipients_count += [[co allRecipients] count];
|
|
|
|
messages_count += 1;
|
|
|
|
|
2015-07-24 17:19:57 +02:00
|
|
|
if ([dd maximumMessageSubmissionCount] > 0 || [dd maximumRecipientCount] > 0)
|
2013-06-11 17:21:58 +02:00
|
|
|
{
|
|
|
|
[[SOGoCache sharedCache] setMessageSubmissionsCount: messages_count
|
|
|
|
recipientsCount: recipients_count
|
|
|
|
forLogin: [[context activeUser] login]];
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 22:58:41 +02:00
|
|
|
|
2015-12-09 15:44:33 +01:00
|
|
|
return response;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxMailEditor */
|