Monotone-Parent: f537b5805052d9a9bfb04e2f651abef055885f53

Monotone-Revision: a1a53ca320391ca2cdd308cc1662af84b36a2e2c

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2008-09-10T20:35:28
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau 2008-09-10 20:35:28 +00:00
parent c966b00c70
commit a2750fb020
2 changed files with 77 additions and 42 deletions

View file

@ -1,5 +1,9 @@
2008-09-10 Wolfgang Sourdeau <wsourdeau@inverse.ca> 2008-09-10 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* UI/MailPartViewers/UIxMailPartAlternativeViewer.m
([UIxMailPartAlternativeViewer -selectChildInfo]): give precedence
on multipart/mixed parts over text/* parts.
* SoObjects/Mailer/SOGoDraftObject.m ([SOGoDraftObject * SoObjects/Mailer/SOGoDraftObject.m ([SOGoDraftObject
-isValidAttachmentName:filename]): accept all filenames except -isValidAttachmentName:filename]): accept all filenames except
".", ".." and those that contain "/". Any other is valid and will ".", ".." and those that contain "/". Any other is valid and will

View file

@ -49,14 +49,16 @@
@implementation UIxMailPartAlternativeViewer @implementation UIxMailPartAlternativeViewer
- (void)dealloc { - (void) dealloc
{
[childInfo release]; [childInfo release];
[super dealloc]; [super dealloc];
} }
/* caches */ /* caches */
- (void)resetBodyInfoCaches { - (void) resetBodyInfoCaches
{
[childInfo release]; childInfo = nil; [childInfo release]; childInfo = nil;
childIndex = 0; childIndex = 0;
[super resetBodyInfoCaches]; [super resetBodyInfoCaches];
@ -64,7 +66,8 @@
/* part selection */ /* part selection */
- (NSArray *)childPartTypes { - (NSArray *) childPartTypes
{
NSMutableArray *types; NSMutableArray *types;
unsigned i, count; unsigned i, count;
NSArray *childParts; NSArray *childParts;
@ -85,45 +88,66 @@
return types; return types;
} }
- (int)selectPartIndexFromTypes:(NSArray *)_types { - (unsigned int) _preferredTypesPart: (NSArray *) types
/* returns the index of the selected part or NSNotFound */ {
unsigned i, count; unsigned int count, max;
unsigned int part;
const NSString *priorities[] = { @"multipart/related", @"multipart/mixed",
@"text/calendar", @"text/html",
@"text/plain" };
if ((count = [_types count]) == 0) part = NSNotFound;
return NSNotFound;
if ((i = [_types indexOfObject:@"multipart/related"]) != NSNotFound)
return i;
if ((i = [_types indexOfObject:@"text/calendar"]) != NSNotFound)
return i;
if ((i = [_types indexOfObject:@"text/html"]) != NSNotFound)
return i;
if ((i = [_types indexOfObject:@"text/plain"]) != NSNotFound)
return i;
/* then we scan for other text types and choose the first one found */ max = sizeof (priorities) / sizeof (NSString *);
for (i = 0; i < count; i++) { for (count = 0; count < max; count++)
if ([(NSString *)[_types objectAtIndex:i] hasPrefix:@"text/"]) {
return i; part = [types indexOfObject: priorities[count]];
} if (part != NSNotFound)
break;
/* as a fallback, we select the first available part */ }
return 0;
return part;
} }
- (void)selectChildInfo { - (int) _selectPartIndexFromTypes: (NSArray *) _types
{
/* returns the index of the selected part or NSNotFound */
unsigned count, max, part;
part = [self _preferredTypesPart: _types];
if (part == NSNotFound)
{
max = [_types count];
/* then we scan for other text types and choose the first one found */
for (count = 0; count < max; count++)
if ([[_types objectAtIndex: count] hasPrefix:@"text/"])
{
part = count;
break;
}
}
if (part == NSNotFound)
part = 0; /* as a fallback, we select the first available part */
return part;
}
- (void) selectChildInfo
{
unsigned idx; unsigned idx;
[childInfo release]; childInfo = nil; [childInfo release]; childInfo = nil;
childIndex = 0; childIndex = 0;
idx = [self selectPartIndexFromTypes:[self childPartTypes]]; idx = [self _selectPartIndexFromTypes: [self childPartTypes]];
if (idx == NSNotFound) { if (idx == NSNotFound)
[self errorWithFormat:@"could not select a part of types: %@", {
[self errorWithFormat:@"could not select a part of types: %@",
[self childPartTypes]]; [self childPartTypes]];
return; return;
} }
childIndex = idx + 1; childIndex = idx + 1;
childInfo = childInfo =
[[[[self bodyInfo] valueForKey:@"parts"] objectAtIndex:idx] retain]; [[[[self bodyInfo] valueForKey:@"parts"] objectAtIndex:idx] retain];
@ -131,27 +155,33 @@
/* accessors */ /* accessors */
- (id)childInfo { - (id) childInfo
if (childInfo == nil) {
if (!childInfo)
[self selectChildInfo]; [self selectChildInfo];
return childInfo; return childInfo;
} }
- (unsigned int) childIndex { - (unsigned int) childIndex
if (childIndex == 0) {
if (!childIndex)
[self selectChildInfo]; [self selectChildInfo];
return childIndex - 1; return childIndex - 1;
} }
- (NSString *)childPartName { - (NSString *) childPartName
char buf[8]; {
sprintf(buf, "%d", [self childIndex] + 1); char buf[8]
sprintf (buf, "%d", [self childIndex] + 1);
return [NSString stringWithCString:buf]; return [NSString stringWithCString:buf];
} }
- (id)childPartPath { - (id) childPartPath
{
NSArray *pp; NSArray *pp;
pp = [self partPath]; pp = [self partPath];
@ -162,7 +192,8 @@
/* nested viewers */ /* nested viewers */
- (id)contentViewerComponent { - (id) contentViewerComponent
{
id info; id info;
info = [self childInfo]; info = [self childInfo];