2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 Show plaintext mail parts correctly formatted.
27 TODO: add server side wrapping.
28 TODO: add contained link detection.
31 #import <Foundation/NSException.h>
33 #import <NGExtensions/NSString+misc.h>
35 #import <SoObjects/SOGo/NSString+Utilities.h>
37 #import "UIxMailPartTextViewer.h"
39 @interface NSString (SOGoMailUIExtension)
41 - (NSString *) stringByConvertingCRLNToHTML;
45 @implementation NSString (SOGoMailUIExtension)
48 convertChars (const char *oldString, unsigned int oldLength,
49 unsigned int *newLength)
51 const char *currentChar, *upperLimit;
52 char *newString, *destChar, *reallocated;
53 unsigned int length, maxLength, iteration;
55 maxLength = oldLength + 500;
56 newString = malloc (maxLength);
58 currentChar = oldString;
63 upperLimit = oldString + oldLength;
64 while ((unsigned int) currentChar < (unsigned int) upperLimit)
66 if (*currentChar != '\r')
68 if (*currentChar == '\n')
70 length = (unsigned int) destChar - (unsigned int) newString;
71 if ((length + (6 * iteration) + 500) > maxLength)
73 maxLength = length + (iteration * 6) + 500;
74 reallocated = realloc (newString, maxLength);
76 newString = reallocated;
78 [NSException raise: NSMallocException
79 format: @"reallocation failed in %s",
81 destChar = newString + length;
83 strcpy (destChar, "<br />");
89 *destChar = *currentChar;
96 *newLength = (unsigned int) destChar - (unsigned int) newString;
101 - (NSString *) stringByConvertingCRLNToHTML
103 NSString *convertedString;
105 unsigned int newLength;
108 = convertChars ([self cStringUsingEncoding: NSUTF8StringEncoding],
109 [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding],
111 convertedString = [[NSString alloc] initWithBytes: newString
113 encoding: NSUTF8StringEncoding];
114 [convertedString autorelease];
117 return convertedString;
122 @implementation UIxMailPartTextViewer
124 - (NSString *) flatContentAsString
126 NSString *superContent;
128 superContent = [[super flatContentAsString] stringByEscapingHTMLString];
130 return [[superContent stringByDetectingURLs] stringByConvertingCRLNToHTML];
133 @end /* UIxMailPartTextViewer */