2007-08-22 17:10:48 +02:00
|
|
|
/* SOGoMailForward.m - this file is part of SOGo
|
|
|
|
*
|
2020-07-06 18:17:11 +02:00
|
|
|
* Copyright (C) 2007-2020 Inverse inc.
|
2007-08-22 17:10:48 +02:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
|
2020-07-06 18:17:11 +02:00
|
|
|
#import <NGImap4/NGImap4EnvelopeAddress.h>
|
2007-08-22 17:10:48 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2009-06-25 21:18:02 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2007-08-22 17:10:48 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoDateFormatter.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2007-08-22 17:10:48 +02:00
|
|
|
|
2010-08-06 16:25:59 +02:00
|
|
|
#import "SOGoMailAccount.h"
|
2007-08-22 17:10:48 +02:00
|
|
|
#import "SOGoMailObject+Draft.h"
|
|
|
|
#import "SOGoMailForward.h"
|
2020-07-06 18:17:11 +02:00
|
|
|
#import "SOGoSentFolder.h"
|
2007-08-22 17:10:48 +02:00
|
|
|
|
|
|
|
@implementation SOGoMailForward
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-01-04 17:05:12 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
|
2007-08-22 17:10:48 +02:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2009-06-25 21:18:02 +02:00
|
|
|
ud = [[context activeUser] userDefaults];
|
2010-01-04 17:05:12 +01:00
|
|
|
htmlComposition
|
|
|
|
= [[ud mailComposeMessageType] isEqualToString: @"html"];
|
2007-08-22 17:10:48 +02:00
|
|
|
sourceMail = nil;
|
|
|
|
currentValue = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[sourceMail release];
|
|
|
|
[currentValue release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2014-01-23 20:34:14 +01:00
|
|
|
- (void) setSignaturePlacement: (NSString *) newPlacement
|
|
|
|
{
|
|
|
|
signaturePlacement = newPlacement;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) signaturePlacementOnTop
|
|
|
|
{
|
|
|
|
return [signaturePlacement isEqual: @"above"];
|
|
|
|
}
|
|
|
|
|
2008-09-05 18:50:22 +02:00
|
|
|
- (void) setSourceMail: (SOGoMailObject *) newSourceMail
|
2007-08-22 17:10:48 +02:00
|
|
|
{
|
|
|
|
ASSIGN (sourceMail, newSourceMail);
|
|
|
|
}
|
|
|
|
|
2009-06-25 21:18:02 +02:00
|
|
|
- (NSString *) newLine
|
|
|
|
{
|
2015-10-31 07:10:03 +01:00
|
|
|
NSString *rc = @" ";
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
if (htmlComposition)
|
2015-10-31 07:10:03 +01:00
|
|
|
rc = @"<br/>";
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-08-22 17:10:48 +02:00
|
|
|
- (NSString *) subject
|
|
|
|
{
|
2007-11-25 18:26:56 +01:00
|
|
|
return [sourceMail decodedSubject];
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) date
|
|
|
|
{
|
|
|
|
SOGoDateFormatter *formatter;
|
|
|
|
|
|
|
|
formatter = [[context activeUser] dateFormatterInContext: context];
|
|
|
|
|
|
|
|
return [formatter formattedDateAndTime: [sourceMail date]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) from
|
|
|
|
{
|
2012-07-12 18:47:23 +02:00
|
|
|
id rc;
|
2009-06-25 21:18:02 +02:00
|
|
|
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = [[sourceMail mailHeaders] objectForKey: @"from"];
|
|
|
|
if ([rc isKindOfClass: [NSArray class]])
|
|
|
|
rc = [rc componentsJoinedByString: @", "];
|
2009-06-25 21:18:02 +02:00
|
|
|
if (htmlComposition)
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = [rc stringByEscapingHTMLString];
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _headerField: (NSString *) fieldName
|
|
|
|
{
|
|
|
|
if (![field isEqualToString: fieldName])
|
|
|
|
{
|
|
|
|
[currentValue release];
|
|
|
|
currentValue = [[sourceMail mailHeaders] objectForKey: fieldName];
|
|
|
|
[currentValue retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasReplyTo
|
|
|
|
{
|
|
|
|
return ([[self _headerField: @"reply-to"] length] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) replyTo
|
|
|
|
{
|
2012-07-12 18:47:23 +02:00
|
|
|
id rc;
|
2009-06-25 21:18:02 +02:00
|
|
|
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = [self _headerField: @"reply-to"];
|
|
|
|
if ([rc isKindOfClass: [NSArray class]])
|
|
|
|
rc = [rc componentsJoinedByString: @", "];
|
2009-06-25 21:18:02 +02:00
|
|
|
if (htmlComposition)
|
|
|
|
rc = [NSString stringWithFormat: @"%@<br/>",
|
2012-07-12 18:47:23 +02:00
|
|
|
[rc stringByEscapingHTMLString]];
|
2009-06-25 21:18:02 +02:00
|
|
|
else
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = ([NSString stringWithFormat: @"%@\n", rc]);
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasOrganization
|
|
|
|
{
|
|
|
|
return ([[self _headerField: @"organization"] length] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) organization
|
|
|
|
{
|
2009-06-25 21:18:02 +02:00
|
|
|
NSString *rc;
|
|
|
|
|
|
|
|
if (htmlComposition)
|
|
|
|
rc = [NSString stringWithFormat: @"%@<br/>", [self _headerField: @"organization"]];
|
|
|
|
else
|
|
|
|
rc = [NSString stringWithFormat: @"%@\n", [self _headerField: @"organization"]];
|
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) to
|
|
|
|
{
|
2012-07-12 18:47:23 +02:00
|
|
|
id rc;
|
2009-06-25 21:18:02 +02:00
|
|
|
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = [self _headerField: @"to"];
|
|
|
|
if ([rc isKindOfClass: [NSArray class]])
|
|
|
|
rc = [rc componentsJoinedByString: @", "];
|
2009-06-25 21:18:02 +02:00
|
|
|
if (htmlComposition)
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = [rc stringByEscapingHTMLString];
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasCc
|
|
|
|
{
|
|
|
|
return ([[self _headerField: @"cc"] length] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) cc
|
|
|
|
{
|
2012-10-10 17:57:36 +02:00
|
|
|
id rc;
|
2012-07-12 18:47:23 +02:00
|
|
|
|
|
|
|
rc = [self _headerField: @"cc"];
|
|
|
|
if ([rc isKindOfClass: [NSArray class]])
|
|
|
|
rc = [rc componentsJoinedByString: @", "];
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
if (htmlComposition)
|
|
|
|
rc = [NSString stringWithFormat: @"%@<br/>",
|
2012-07-12 18:47:23 +02:00
|
|
|
[rc stringByEscapingHTMLString]];
|
2009-06-25 21:18:02 +02:00
|
|
|
else
|
2012-07-12 18:47:23 +02:00
|
|
|
rc = [NSString stringWithFormat: @"%@\n", rc];
|
2009-06-25 21:18:02 +02:00
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasNewsGroups
|
|
|
|
{
|
|
|
|
return ([[self _headerField: @"newsgroups"] length] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) newsgroups
|
|
|
|
{
|
2009-06-25 21:18:02 +02:00
|
|
|
NSString *rc;
|
|
|
|
|
|
|
|
if (htmlComposition)
|
|
|
|
rc = [NSString stringWithFormat: @"%@<br/>", [self _headerField: @"newsgroups"]];
|
|
|
|
else
|
|
|
|
rc = [NSString stringWithFormat: @"%@\n", [self _headerField: @"newsgroups"]];
|
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasReferences
|
|
|
|
{
|
|
|
|
return ([[self _headerField: @"references"] length] > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) references
|
|
|
|
{
|
2009-06-25 21:18:02 +02:00
|
|
|
NSString *rc;
|
|
|
|
|
|
|
|
if (htmlComposition)
|
|
|
|
rc = [NSString stringWithFormat: @"%@<br/>", [self _headerField: @"references"]];
|
|
|
|
else
|
|
|
|
rc = [NSString stringWithFormat: @"%@\n", [self _headerField: @"references"]];
|
|
|
|
|
|
|
|
return rc;
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) messageBody
|
|
|
|
{
|
2008-09-05 18:50:22 +02:00
|
|
|
return [sourceMail contentForEditing];
|
2007-08-22 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
2007-11-19 23:44:12 +01:00
|
|
|
- (NSString *) signature
|
|
|
|
{
|
2020-07-06 18:17:11 +02:00
|
|
|
BOOL fromSentMailbox;
|
|
|
|
NGImap4EnvelopeAddress *address;
|
|
|
|
NSArray *addresses;
|
|
|
|
NSDictionary *identity;
|
|
|
|
NSString *email, *signature, *mailSignature, *nl, *space;
|
|
|
|
int count, max;
|
|
|
|
|
|
|
|
fromSentMailbox = [[sourceMail container] isKindOfClass: [SOGoSentFolder class]];
|
|
|
|
if (fromSentMailbox)
|
|
|
|
addresses = [sourceMail fromEnvelopeAddresses];
|
|
|
|
else
|
|
|
|
addresses = [sourceMail toEnvelopeAddresses];
|
|
|
|
identity = nil;
|
|
|
|
mailSignature = @"";
|
|
|
|
max = [addresses count];
|
2012-11-21 02:29:27 +01:00
|
|
|
|
2020-07-06 18:17:11 +02:00
|
|
|
if (max)
|
2012-11-21 02:29:27 +01:00
|
|
|
{
|
2020-07-06 18:17:11 +02:00
|
|
|
// Pick the first email matching one of the account's identities
|
|
|
|
for (count = 0; !identity && count < max; count++)
|
|
|
|
{
|
|
|
|
address = [addresses objectAtIndex: count];
|
|
|
|
email = [address baseEMail];
|
|
|
|
identity = [[sourceMail mailAccountFolder] identityForEmail: email];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 18:17:55 +02:00
|
|
|
if (!identity)
|
|
|
|
{
|
|
|
|
identity = [[context activeUser] defaultIdentity];
|
|
|
|
}
|
|
|
|
|
2020-07-06 18:17:11 +02:00
|
|
|
if (identity)
|
|
|
|
{
|
|
|
|
signature = [identity objectForKey: @"signature"];
|
|
|
|
if ([signature length])
|
|
|
|
{
|
|
|
|
nl = (htmlComposition ? @"<br />" : @"\n");
|
|
|
|
space = (htmlComposition ? @" " : @" ");
|
|
|
|
mailSignature = [NSString stringWithFormat: @"%@--%@%@%@", nl, space, nl, signature];
|
|
|
|
}
|
2012-11-21 02:29:27 +01:00
|
|
|
}
|
2007-11-19 23:44:12 +01:00
|
|
|
|
|
|
|
return mailSignature;
|
|
|
|
}
|
|
|
|
|
2007-08-22 17:10:48 +02:00
|
|
|
@end
|
2007-08-23 18:13:24 +02:00
|
|
|
|
2013-04-08 17:05:45 +02:00
|
|
|
@implementation SOGoMailArabicForward
|
|
|
|
@end
|
|
|
|
|
2009-08-05 13:30:23 +02:00
|
|
|
@implementation SOGoMailBrazilianPortugueseForward
|
|
|
|
@end
|
|
|
|
|
2010-11-17 14:43:07 +01:00
|
|
|
@implementation SOGoMailCatalanForward
|
|
|
|
@end
|
|
|
|
|
2017-09-05 18:10:46 +02:00
|
|
|
@implementation SOGoMailChineseChinaForward
|
|
|
|
@end
|
|
|
|
|
2015-07-23 17:09:04 +02:00
|
|
|
@implementation SOGoMailChineseTaiwanForward
|
|
|
|
@end
|
|
|
|
|
2016-01-25 16:50:07 +01:00
|
|
|
@implementation SOGoMailCroatianForward
|
|
|
|
@end
|
|
|
|
|
2009-08-05 13:06:06 +02:00
|
|
|
@implementation SOGoMailCzechForward
|
|
|
|
@end
|
|
|
|
|
2011-12-19 18:16:23 +01:00
|
|
|
@implementation SOGoMailDanishForward
|
|
|
|
@end
|
|
|
|
|
2008-09-05 18:50:22 +02:00
|
|
|
@implementation SOGoMailDutchForward
|
|
|
|
@end
|
|
|
|
|
2007-08-23 18:13:24 +02:00
|
|
|
@implementation SOGoMailEnglishForward
|
|
|
|
@end
|
|
|
|
|
2013-08-26 14:59:43 +02:00
|
|
|
@implementation SOGoMailFinnishForward
|
|
|
|
@end
|
|
|
|
|
2007-08-23 18:13:24 +02:00
|
|
|
@implementation SOGoMailFrenchForward
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoMailGermanForward
|
|
|
|
@end
|
2008-03-20 14:48:17 +01:00
|
|
|
|
2017-01-27 03:40:52 +01:00
|
|
|
@implementation SOGoMailHebrewForward
|
|
|
|
@end
|
|
|
|
|
2009-08-05 13:30:23 +02:00
|
|
|
@implementation SOGoMailHungarianForward
|
|
|
|
@end
|
|
|
|
|
2019-06-14 16:47:11 +02:00
|
|
|
@implementation SOGoMailIndonesianForward
|
|
|
|
@end
|
|
|
|
|
2011-05-11 21:12:47 +02:00
|
|
|
@implementation SOGoMailIcelandicForward
|
|
|
|
@end
|
|
|
|
|
2008-03-20 14:48:17 +01:00
|
|
|
@implementation SOGoMailItalianForward
|
|
|
|
@end
|
|
|
|
|
2018-06-01 17:29:33 +02:00
|
|
|
@implementation SOGoMailJapaneseForward
|
|
|
|
@end
|
|
|
|
|
2017-05-30 22:19:44 +02:00
|
|
|
@implementation SOGoMailLatvianForward
|
|
|
|
@end
|
|
|
|
|
2016-03-14 15:08:25 +01:00
|
|
|
@implementation SOGoMailLithuanianForward
|
|
|
|
@end
|
|
|
|
|
2015-12-04 19:49:11 +01:00
|
|
|
@implementation SOGoMailMacedonianForward
|
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoMailNorwegianBokmalForward
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoMailNorwegianNynorskForward
|
|
|
|
@end
|
|
|
|
|
2015-12-15 16:05:46 +01:00
|
|
|
@implementation SOGoMailPolishForward
|
|
|
|
@end
|
|
|
|
|
2015-12-04 19:49:11 +01:00
|
|
|
@implementation SOGoMailPortugueseForward
|
|
|
|
@end
|
|
|
|
|
2018-07-30 18:05:14 +02:00
|
|
|
@implementation SOGoMailRomanianForward
|
|
|
|
@end
|
|
|
|
|
2016-05-16 19:28:12 +02:00
|
|
|
@implementation SOGoMailRussianForward
|
2011-11-17 16:22:09 +01:00
|
|
|
@end
|
|
|
|
|
2016-09-14 18:13:00 +02:00
|
|
|
@implementation SOGoMailSerbianForward
|
|
|
|
@end
|
|
|
|
|
2020-12-18 23:40:31 +01:00
|
|
|
@implementation SOGoMailSerbianLatinForward
|
|
|
|
@end
|
|
|
|
|
2016-05-16 19:28:12 +02:00
|
|
|
@implementation SOGoMailSlovakForward
|
2008-09-05 18:50:22 +02:00
|
|
|
@end
|
2009-05-23 13:12:34 +02:00
|
|
|
|
2016-05-16 19:28:12 +02:00
|
|
|
@implementation SOGoMailSlovenianForward
|
2011-08-17 18:05:49 +02:00
|
|
|
@end
|
|
|
|
|
2016-05-16 19:28:12 +02:00
|
|
|
@implementation SOGoMailSpanishSpainForward
|
2009-05-23 13:12:34 +02:00
|
|
|
@end
|
2009-08-05 13:30:23 +02:00
|
|
|
|
2016-05-16 19:28:12 +02:00
|
|
|
@implementation SOGoMailSpanishArgentinaForward
|
2013-03-05 16:22:20 +01:00
|
|
|
@end
|
|
|
|
|
2016-05-16 19:28:12 +02:00
|
|
|
@implementation SOGoMailSwedishForward
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoMailTurkishTurkeyForward
|
2015-07-22 22:41:37 +02:00
|
|
|
@end
|
|
|
|
|
2010-09-13 23:37:07 +02:00
|
|
|
@implementation SOGoMailUkrainianForward
|
|
|
|
@end
|
|
|
|
|
2009-08-05 13:30:23 +02:00
|
|
|
@implementation SOGoMailWelshForward
|
|
|
|
@end
|