2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo 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.
|
|
|
|
|
|
|
|
OGo 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
UIxMailPartTextViewer
|
|
|
|
|
2006-09-19 23:09:11 +02:00
|
|
|
Show plaintext mail parts correctly formatted.
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
TODO: add server side wrapping.
|
|
|
|
TODO: add contained link detection.
|
|
|
|
*/
|
|
|
|
|
2007-07-30 16:12:21 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2007-05-15 22:52:38 +02:00
|
|
|
|
2007-07-30 16:12:21 +02:00
|
|
|
#import <SoObjects/SOGo/NSString+Utilities.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-19 23:09:11 +02:00
|
|
|
#import "UIxMailPartTextViewer.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-05 23:41:48 +01:00
|
|
|
@interface NSString (SOGoMailUIExtension)
|
|
|
|
|
|
|
|
- (NSString *) stringByConvertingCRLNToHTML;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSString (SOGoMailUIExtension)
|
|
|
|
|
|
|
|
- (NSString *) stringByConvertingCRLNToHTML
|
|
|
|
{
|
|
|
|
NSString *convertedString;
|
|
|
|
const char *oldString, *currentChar;
|
|
|
|
char *newString, *destChar;
|
|
|
|
unsigned int oldLength, length, delta;
|
|
|
|
|
|
|
|
oldString = [self cStringUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
oldLength = [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
length = oldLength;
|
|
|
|
newString = malloc (length + 500);
|
|
|
|
destChar = newString;
|
|
|
|
currentChar = oldString;
|
|
|
|
while (currentChar < (oldString + oldLength))
|
|
|
|
{
|
|
|
|
if (*currentChar != '\r')
|
|
|
|
{
|
|
|
|
if (*currentChar == '\n')
|
|
|
|
{
|
|
|
|
strcpy (destChar, "<br />");
|
|
|
|
destChar += 6;
|
|
|
|
delta = (destChar - newString);
|
|
|
|
if (delta > length)
|
|
|
|
{
|
|
|
|
length += 500;
|
|
|
|
newString = realloc (newString, length + 500);
|
|
|
|
destChar = newString + delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*destChar = *currentChar;
|
|
|
|
destChar++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentChar++;
|
|
|
|
}
|
|
|
|
*destChar = 0;
|
|
|
|
|
|
|
|
convertedString = [[NSString alloc] initWithBytes: newString
|
2007-11-12 16:24:49 +01:00
|
|
|
length: (destChar - newString)
|
2007-11-05 23:41:48 +01:00
|
|
|
encoding: NSUTF8StringEncoding];
|
|
|
|
[convertedString autorelease];
|
|
|
|
free (newString);
|
|
|
|
|
|
|
|
return convertedString;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@implementation UIxMailPartTextViewer
|
|
|
|
|
2006-09-19 23:06:59 +02:00
|
|
|
- (NSString *) flatContentAsString
|
2006-09-19 23:06:47 +02:00
|
|
|
{
|
2007-05-22 20:41:02 +02:00
|
|
|
NSString *superContent;
|
2007-05-15 22:52:38 +02:00
|
|
|
|
|
|
|
superContent = [[super flatContentAsString] stringByEscapingHTMLString];
|
|
|
|
|
2007-11-05 23:41:48 +01:00
|
|
|
return [[superContent stringByDetectingURLs] stringByConvertingCRLNToHTML];
|
2006-09-19 23:06:47 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* UIxMailPartTextViewer */
|