diff --git a/ChangeLog b/ChangeLog index 3b2f47d0d..e695c03f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2009-06-23 Cyril Robert + + * SoObjects/Mailer/NSString+Mail.m (stringByConvertingCRLNToHTML): Added + * UI/MailPartViewers/UIxMailPartTextViewer.m (stringByConvertingCRLNToHTML): + Removed + * SoObjects/Mailer/SOGoDraftObject.m: Added support for html content type + * SoObjects/Mailer/SOGoMailObject+Draft.m: Added support for html content + type in mail reply + * SoObjects/Mailer/SOGoMailReply.m: Added support for html in mail editor + * UI/PreferencesUI/UIxPreferences.m: Added option to se content type for + mail editing + * UI/WebServerResources/GNUmakefile: Added fckeditor entry + * UI/WebServerResources/UIxMailEditor.js: Plugged-in FCKEditor + * UI/WebServerResources/UIxPreferences.js: Plugged-in FCKEditor, handle html + toggle for signature box + 2009-06-19 Wolfgang Sourdeau * SoObjects/SOGo/SOGoGCSFolder.m (-davSyncCollection:): deleted diff --git a/SoObjects/Mailer/NSString+Mail.h b/SoObjects/Mailer/NSString+Mail.h index a4bcb1b7d..7ed44b549 100644 --- a/SoObjects/Mailer/NSString+Mail.h +++ b/SoObjects/Mailer/NSString+Mail.h @@ -28,6 +28,7 @@ @interface NSString (SOGoExtension) - (NSString *) htmlToText; +- (NSString *) stringByConvertingCRLNToHTML; - (int) indexOf: (unichar) _c; - (NSString *) decodedSubject; diff --git a/SoObjects/Mailer/NSString+Mail.m b/SoObjects/Mailer/NSString+Mail.m index f02c9ac69..3fb62d899 100644 --- a/SoObjects/Mailer/NSString+Mail.m +++ b/SoObjects/Mailer/NSString+Mail.m @@ -23,6 +23,7 @@ #import #import #import +#import #import #import #import @@ -350,6 +351,79 @@ return [handler result]; } +#define paddingBuffer 8192 + +static inline char * +convertChars (const char *oldString, unsigned int oldLength, + unsigned int *newLength) +{ + const char *currentChar, *upperLimit; + char *newString, *destChar, *reallocated; + unsigned int length, maxLength; + + maxLength = oldLength + paddingBuffer; + newString = NSZoneMalloc (NULL, maxLength + 1); + destChar = newString; + currentChar = oldString; + + length = 0; + + upperLimit = oldString + oldLength; + while (currentChar < upperLimit) + { + switch (*currentChar) + { + case '\r': break; + case '\n': + length = destChar - newString; + if (length + paddingBuffer > maxLength - 6) + { + maxLength += paddingBuffer; + reallocated = NSZoneRealloc (NULL, newString, maxLength + 1); + if (reallocated) + { + newString = reallocated; + destChar = newString + length; + } + else + [NSException raise: NSMallocException + format: @"reallocation failed in %s", + __PRETTY_FUNCTION__]; + } + strcpy (destChar, "
"); + destChar += 6; + break; + default: + *destChar = *currentChar; + destChar++; + } + currentChar++; + } + *destChar = 0; + *newLength = destChar - newString; + + return newString; +} + +- (NSString *) stringByConvertingCRLNToHTML +{ + NSString *convertedString; + char *newString; + unsigned int newLength; + + newString + = convertChars ([self cStringUsingEncoding: NSUTF8StringEncoding], + [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding], + &newLength); + convertedString = [[NSString alloc] initWithBytes: newString + length: newLength + encoding: NSUTF8StringEncoding]; + [convertedString autorelease]; + NSZoneFree (NULL, newString); + + return convertedString; +} + - (int) indexOf: (unichar) _c { int i, len; diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index b9b713aaf..9b94914fa 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -70,6 +70,7 @@ #import "SOGoDraftObject.h" static NSString *contentTypeValue = @"text/plain; charset=utf-8"; +static NSString *htmlContentTypeValue = @"text/html; charset=utf-8"; static NSString *headerKeys[] = {@"subject", @"to", @"cc", @"bcc", @"from", @"replyTo", @"message-id", nil}; @@ -879,17 +880,24 @@ static BOOL showTextAttachmentsInline = NO; - (NGMimeMessage *) mimeMessageForContentWithHeaderMap: (NGMutableHashMap *) map { NGMimeMessage *message; + NSUserDefaults *ud; // BOOL addSuffix; id body; + ud = [[context activeUser] userDefaults]; + [map setObject: @"text/plain" forKey: @"content-type"]; body = text; if (body) { // if ([body isKindOfClass:[NSString class]]) /* Note: just 'utf8' is displayed wrong in Mail.app */ - [map setObject: contentTypeValue - forKey: @"content-type"]; + if ([[ud stringForKey: @"ComposeMessagesType"] isEqualToString: @"html"]) + [map setObject: htmlContentTypeValue + forKey: @"content-type"]; + else + [map setObject: contentTypeValue + forKey: @"content-type"]; // body = [body dataUsingEncoding:NSUTF8StringEncoding]; // else if ([body isKindOfClass:[NSData class]] && addSuffix) { // body = [[body mutableCopy] autorelease]; diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.m b/SoObjects/Mailer/SOGoMailObject+Draft.m index b78f62749..f81f58734 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.m +++ b/SoObjects/Mailer/SOGoMailObject+Draft.m @@ -88,6 +88,26 @@ return newSubject; } +- (NSString *) _convertRawContentForEditing: (NSString *) raw + rawHtml: (BOOL) html +{ + NSString *rc; + NSUserDefaults *ud; + BOOL htmlComposition; + + ud = [[context activeUser] userDefaults]; + htmlComposition = [[ud stringForKey: @"ComposeMessagesType"] + isEqualToString: @"html"]; + + if (html && !htmlComposition) + rc = [raw htmlToText]; + else if (!html && htmlComposition) + rc = [raw stringByConvertingCRLNToHTML]; + else + rc = raw; + + return rc; +} - (NSString *) _contentForEditingFromKeys: (NSArray *) keys { @@ -104,29 +124,27 @@ types = [keys objectsForKey: @"mimeType" notFoundMarker: @""]; index = [types indexOfObject: @"text/plain"]; if (index == NSNotFound) - { - index = [types indexOfObject: @"text/html"]; - htmlContent = YES; - } + { + index = [types indexOfObject: @"text/html"]; + htmlContent = YES; + } else - htmlContent = NO; - + htmlContent = NO; + if (index != NSNotFound) - { - contentKey = [keys objectAtIndex: index]; - parts = [self fetchPlainTextStrings: - [NSArray arrayWithObject: contentKey]]; - if ([parts count] > 0) - { - rawPart = [[parts allValues] objectAtIndex: 0]; - if (htmlContent) - content = [rawPart htmlToText]; - else - content = rawPart; - } - } + { + contentKey = [keys objectAtIndex: index]; + parts = [self fetchPlainTextStrings: + [NSArray arrayWithObject: contentKey]]; + if ([parts count] > 0) + { + rawPart = [[parts allValues] objectAtIndex: 0]; + content = [self _convertRawContentForEditing: rawPart + rawHtml: htmlContent]; + } + } } - + return content; } diff --git a/SoObjects/Mailer/SOGoMailReply.m b/SoObjects/Mailer/SOGoMailReply.m index df5ce7a6b..22b7b7ac5 100644 --- a/SoObjects/Mailer/SOGoMailReply.m +++ b/SoObjects/Mailer/SOGoMailReply.m @@ -25,6 +25,7 @@ #import #import +#import #import "SOGoMailObject+Draft.h" #import "SOGoMailReply.h" @@ -74,20 +75,32 @@ - (NSString *) messageBody { NSString *s; + NSUserDefaults *ud; + + ud = [[context activeUser] userDefaults]; s = [sourceMail contentForEditing]; if (s) { - NSRange r; + if ([[ud objectForKey: @"ComposeMessagesType"] isEqualToString: @"html"]) + { + s = [NSString stringWithFormat: @"
%@
", s]; + } + else + { + NSRange r; - r = [s rangeOfString: @"\n-- \n" options: NSBackwardsSearch]; + r = [s rangeOfString: @"\n-- \n" options: NSBackwardsSearch]; - if (r.length) - s = [s substringToIndex: r.location]; + if (r.length) + s = [s substringToIndex: r.location]; + + s = [s stringByApplyingMailQuoting]; //adds "> " on each line + } } - return [s stringByApplyingMailQuoting]; + return s; } @end diff --git a/UI/MailPartViewers/UIxMailPartTextViewer.m b/UI/MailPartViewers/UIxMailPartTextViewer.m index b2cbe9ecf..eb978d4cc 100644 --- a/UI/MailPartViewers/UIxMailPartTextViewer.m +++ b/UI/MailPartViewers/UIxMailPartTextViewer.m @@ -33,92 +33,10 @@ #import #import +#import #import "UIxMailPartTextViewer.h" -@interface NSString (SOGoMailUIExtension) - -- (NSString *) stringByConvertingCRLNToHTML; - -@end - -@implementation NSString (SOGoMailUIExtension) - -#define paddingBuffer 8192 - -static inline char * -convertChars (const char *oldString, unsigned int oldLength, - unsigned int *newLength) -{ - const char *currentChar, *upperLimit; - char *newString, *destChar, *reallocated; - unsigned int length, maxLength; - - maxLength = oldLength + paddingBuffer; - newString = NSZoneMalloc (NULL, maxLength + 1); - destChar = newString; - currentChar = oldString; - - length = 0; - - upperLimit = oldString + oldLength; - while (currentChar < upperLimit) - { - switch (*currentChar) - { - case '\r': break; - case '\n': - length = destChar - newString; - if (length + paddingBuffer > maxLength - 6) - { - maxLength += paddingBuffer; - reallocated = NSZoneRealloc (NULL, newString, maxLength + 1); - if (reallocated) - { - newString = reallocated; - destChar = newString + length; - } - else - [NSException raise: NSMallocException - format: @"reallocation failed in %s", - __PRETTY_FUNCTION__]; - } - strcpy (destChar, "
"); - destChar += 6; - break; - default: - *destChar = *currentChar; - destChar++; - } - currentChar++; - } - *destChar = 0; - *newLength = destChar - newString; - - return newString; -} - -- (NSString *) stringByConvertingCRLNToHTML -{ - NSString *convertedString; - char *newString; - unsigned int newLength; - - newString - = convertChars ([self cStringUsingEncoding: NSUTF8StringEncoding], - [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding], - &newLength); - convertedString = [[NSString alloc] initWithBytes: newString - length: newLength - encoding: NSUTF8StringEncoding]; - [convertedString autorelease]; - NSZoneFree (NULL, newString); - - return convertedString; -} - -@end - @implementation UIxMailPartTextViewer - (NSString *) flatContentAsString diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 971466427..0108237d0 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -584,6 +584,27 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; return [userDefaults stringForKey: @"SignaturePlacement"]; } +- (NSArray *) composeMessagesType +{ + return [NSArray arrayWithObjects: @"text", @"html", nil]; +} + +- (NSString *) itemComposeMessagesText +{ + return [self labelForKey: [NSString stringWithFormat: @"composemessagestype_%@", item]]; +} + +- (NSString *) userComposeMessagesType +{ + return [userDefaults stringForKey: @"ComposeMessagesType"]; +} + +- (void) setUserComposeMessagesType: (NSString *) newType +{ + [userDefaults setObject: newType forKey: @"ComposeMessagesType"]; +} + + - (void) setUserSignaturePlacement: (NSString *) newSignaturePlacement { [userDefaults setObject: newSignaturePlacement forKey: @"SignaturePlacement"]; diff --git a/UI/Templates/MailerUI/UIxMailEditor.wox b/UI/Templates/MailerUI/UIxMailEditor.wox index 4a593ec9f..ab3e3f680 100644 --- a/UI/Templates/MailerUI/UIxMailEditor.wox +++ b/UI/Templates/MailerUI/UIxMailEditor.wox @@ -10,7 +10,7 @@ className="UIxPageFrame" title="panelTitle" const:popup="YES" - const:jsFiles="UIxMailToSelection.js"> + const:jsFiles="UIxMailToSelection.js,fckeditor/fckeditor.js"> diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 914ab996b..e23ed241a 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -10,6 +10,7 @@ className="UIxPageFrame" title="title" const:popup="YES" + const:jsFiles="fckeditor/fckeditor.js" >
@@ -118,6 +119,11 @@ const:id="signaturePlacementList" string="itemSignaturePlacementText" selection="userSignaturePlacement"/> +
+