Move method fetchFileAttachmentKeys from category
Moved fetchFileAttachmentKeys from SOGoDraftObjectExtensions to SOGoDraftObject. Renamed fetchAttachmentIds to fetchFileAttachmentIds for consistency.pull/17/head
parent
1f7994d1bf
commit
dc21c723f6
|
@ -28,7 +28,6 @@
|
|||
@interface SOGoMailObject (SOGoDraftObjectExtensions)
|
||||
|
||||
- (NSString *) contentForEditing;
|
||||
- (NSArray *) fetchFileAttachmentKeys;
|
||||
|
||||
- (NSString *) subjectForReply;
|
||||
- (NSString *) contentForReply;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSURL.h>
|
||||
|
||||
#import <NGObjWeb/WOApplication.h>
|
||||
#import <NGObjWeb/WOResponse.h>
|
||||
|
@ -35,7 +34,6 @@
|
|||
#import <SoObjects/SOGo/SOGoUser.h>
|
||||
#import <SoObjects/SOGo/SOGoUserDefaults.h>
|
||||
|
||||
#import "NSDictionary+Mail.h"
|
||||
#import "NSString+Mail.h"
|
||||
#import "SOGoMailForward.h"
|
||||
#import "SOGoMailObject+Draft.h"
|
||||
|
@ -272,108 +270,4 @@
|
|||
return [[page generateResponse] contentAsString];
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (void) _fetchFileAttachmentKey: (NSDictionary *) part
|
||||
intoArray: (NSMutableArray *) keys
|
||||
withPath: (NSString *) path
|
||||
andPrefix: (NSString *) prefix
|
||||
{
|
||||
NSString *filename, *mimeType;
|
||||
NSDictionary *currentFile;
|
||||
|
||||
filename = [part filename];
|
||||
|
||||
mimeType = [NSString stringWithFormat: @"%@/%@",
|
||||
[part objectForKey: @"type"],
|
||||
[part objectForKey: @"subtype"]];
|
||||
|
||||
if (!filename)
|
||||
// We might end up here because of MUA that actually strips the
|
||||
// Content-Disposition (and thus, the filename) when mails containing
|
||||
// attachments have been forwarded. Thunderbird (2.x) does just that
|
||||
// when forwarding mails with images attached to them (using cid:...).
|
||||
if ([mimeType hasPrefix: @"application/"] ||
|
||||
[mimeType hasPrefix: @"audio/"] ||
|
||||
[mimeType hasPrefix: @"image/"] ||
|
||||
[mimeType hasPrefix: @"video/"])
|
||||
filename = [NSString stringWithFormat: @"unknown_%@", path];
|
||||
|
||||
if (filename)
|
||||
{
|
||||
currentFile = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
filename, @"filename",
|
||||
[mimeType lowercaseString], @"mimetype",
|
||||
path, @"path",
|
||||
[part objectForKey: @"encoding"], @"encoding",
|
||||
[part objectForKey:@ "size"], @"size",
|
||||
[NSString stringWithFormat: @"%@/%@", prefix, [filename stringByEscapingURL]], @"url",
|
||||
nil];
|
||||
[keys addObject: currentFile];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (void) _fetchFileAttachmentKeysInPart: (NSDictionary *) part
|
||||
intoArray: (NSMutableArray *) keys
|
||||
withPath: (NSString *) path
|
||||
andPrefix: (NSString *) prefix
|
||||
{
|
||||
NSMutableDictionary *currentPart;
|
||||
NSString *newPath;
|
||||
NSArray *subparts;
|
||||
NSString *type;
|
||||
NSUInteger i;
|
||||
|
||||
type = [[part objectForKey: @"type"] lowercaseString];
|
||||
if ([type isEqualToString: @"multipart"])
|
||||
{
|
||||
subparts = [part objectForKey: @"parts"];
|
||||
for (i = 1; i <= [subparts count]; i++)
|
||||
{
|
||||
currentPart = [subparts objectAtIndex: i-1];
|
||||
if (path)
|
||||
newPath = [NSString stringWithFormat: @"%@.%d", path, i];
|
||||
else
|
||||
newPath = [NSString stringWithFormat: @"%d", i];
|
||||
[self _fetchFileAttachmentKeysInPart: currentPart
|
||||
intoArray: keys
|
||||
withPath: newPath
|
||||
andPrefix: [NSString stringWithFormat: @"%@/%i", prefix, i]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!path)
|
||||
path = @"1";
|
||||
[self _fetchFileAttachmentKey: part
|
||||
intoArray: keys
|
||||
withPath: path
|
||||
andPrefix: prefix];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
#warning we might need to handle parts with a "name" attribute
|
||||
- (NSArray *) fetchFileAttachmentKeys
|
||||
{
|
||||
NSString *prefix;
|
||||
NSMutableArray *keys;
|
||||
|
||||
prefix = [[self soURL] absoluteString];
|
||||
if ([prefix hasSuffix: @"/"])
|
||||
prefix = [prefix substringToIndex: [prefix length] - 1];
|
||||
|
||||
keys = [NSMutableArray array];
|
||||
[self _fetchFileAttachmentKeysInPart: [self bodyStructure]
|
||||
intoArray: keys withPath: nil andPrefix: prefix];
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -102,7 +102,9 @@ NSArray *SOGoMailCoreInfoKeys;
|
|||
- (NSDictionary *) fetchPlainTextParts;
|
||||
- (NSDictionary *) fetchPlainTextStrings:(NSArray *)_fetchKeys;
|
||||
|
||||
- (NSDictionary *) fetchAttachmentIds;
|
||||
- (BOOL) hasAttachment;
|
||||
- (NSDictionary *) fetchFileAttachmentIds;
|
||||
- (NSArray *) fetchFileAttachmentKeys;
|
||||
|
||||
/* flags */
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
|
||||
#import "NSString+Mail.h"
|
||||
#import "NSData+Mail.h"
|
||||
#import "NSDictionary+Mail.h"
|
||||
#import "SOGoMailFolder.h"
|
||||
#import "SOGoMailAccount.h"
|
||||
#import "SOGoMailAccounts.h"
|
||||
|
@ -705,9 +706,9 @@ static BOOL debugSoParts = NO;
|
|||
return urlToPart;
|
||||
}
|
||||
|
||||
- (void) _feedAttachmentIds: (NSMutableDictionary *) attachmentIds
|
||||
withInfos: (NSDictionary *) infos
|
||||
andPrefix: (NSString *) prefix
|
||||
- (void) _feedFileAttachmentIds: (NSMutableDictionary *) attachmentIds
|
||||
withInfos: (NSDictionary *) infos
|
||||
andPrefix: (NSString *) prefix
|
||||
{
|
||||
NSArray *parts;
|
||||
NSDictionary *currentPart;
|
||||
|
@ -727,14 +728,14 @@ static BOOL debugSoParts = NO;
|
|||
for (count = 0; count < max; count++)
|
||||
{
|
||||
currentPart = [parts objectAtIndex: count];
|
||||
[self _feedAttachmentIds: attachmentIds
|
||||
withInfos: currentPart
|
||||
andPrefix: [NSString stringWithFormat: @"%@/%d",
|
||||
prefix, count + 1]];
|
||||
[self _feedFileAttachmentIds: attachmentIds
|
||||
withInfos: currentPart
|
||||
andPrefix: [NSString stringWithFormat: @"%@/%d",
|
||||
prefix, count + 1]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary *) fetchAttachmentIds
|
||||
- (NSDictionary *) fetchFileAttachmentIds
|
||||
{
|
||||
NSMutableDictionary *attachmentIds;
|
||||
NSString *prefix;
|
||||
|
@ -745,13 +746,118 @@ static BOOL debugSoParts = NO;
|
|||
prefix = [[self soURL] absoluteString];
|
||||
if ([prefix hasSuffix: @"/"])
|
||||
prefix = [prefix substringToIndex: [prefix length] - 1];
|
||||
[self _feedAttachmentIds: attachmentIds
|
||||
[self _feedFileAttachmentIds: attachmentIds
|
||||
withInfos: [coreInfos objectForKey: @"bodystructure"]
|
||||
andPrefix: prefix];
|
||||
|
||||
return attachmentIds;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (void) _fetchFileAttachmentKey: (NSDictionary *) part
|
||||
intoArray: (NSMutableArray *) keys
|
||||
withPath: (NSString *) path
|
||||
andPrefix: (NSString *) prefix
|
||||
{
|
||||
NSString *filename, *mimeType;
|
||||
NSDictionary *currentFile;
|
||||
|
||||
filename = [part filename];
|
||||
|
||||
mimeType = [NSString stringWithFormat: @"%@/%@",
|
||||
[part objectForKey: @"type"],
|
||||
[part objectForKey: @"subtype"]];
|
||||
|
||||
if (!filename)
|
||||
// We might end up here because of MUA that actually strips the
|
||||
// Content-Disposition (and thus, the filename) when mails containing
|
||||
// attachments have been forwarded. Thunderbird (2.x) does just that
|
||||
// when forwarding mails with images attached to them (using cid:...).
|
||||
if ([mimeType hasPrefix: @"application/"] ||
|
||||
[mimeType hasPrefix: @"audio/"] ||
|
||||
[mimeType hasPrefix: @"image/"] ||
|
||||
[mimeType hasPrefix: @"video/"])
|
||||
filename = [NSString stringWithFormat: @"unknown_%@", path];
|
||||
|
||||
if (filename)
|
||||
{
|
||||
currentFile = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
filename, @"filename",
|
||||
[mimeType lowercaseString], @"mimetype",
|
||||
path, @"path",
|
||||
[part objectForKey: @"encoding"], @"encoding",
|
||||
[part objectForKey:@ "size"], @"size",
|
||||
[NSString stringWithFormat: @"%@/%@", prefix, [filename stringByEscapingURL]], @"url",
|
||||
[NSString stringWithFormat: @"%@/asAttachment/%@", prefix, [filename stringByEscapingURL]], @"urlAsAttachment",
|
||||
nil];
|
||||
[keys addObject: currentFile];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (void) _fetchFileAttachmentKeysInPart: (NSDictionary *) part
|
||||
intoArray: (NSMutableArray *) keys
|
||||
withPath: (NSString *) path
|
||||
andPrefix: (NSString *) prefix
|
||||
{
|
||||
NSMutableDictionary *currentPart;
|
||||
NSString *newPath;
|
||||
NSArray *subparts;
|
||||
NSString *type;
|
||||
NSUInteger i;
|
||||
|
||||
type = [[part objectForKey: @"type"] lowercaseString];
|
||||
if ([type isEqualToString: @"multipart"])
|
||||
{
|
||||
subparts = [part objectForKey: @"parts"];
|
||||
for (i = 1; i <= [subparts count]; i++)
|
||||
{
|
||||
currentPart = [subparts objectAtIndex: i-1];
|
||||
if (path)
|
||||
newPath = [NSString stringWithFormat: @"%@.%d", path, i];
|
||||
else
|
||||
newPath = [NSString stringWithFormat: @"%d", i];
|
||||
[self _fetchFileAttachmentKeysInPart: currentPart
|
||||
intoArray: keys
|
||||
withPath: newPath
|
||||
andPrefix: [NSString stringWithFormat: @"%@/%i", prefix, i]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!path)
|
||||
path = @"1";
|
||||
[self _fetchFileAttachmentKey: part
|
||||
intoArray: keys
|
||||
withPath: path
|
||||
andPrefix: prefix];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
#warning we might need to handle parts with a "name" attribute
|
||||
- (NSArray *) fetchFileAttachmentKeys
|
||||
{
|
||||
NSString *prefix;
|
||||
NSMutableArray *keys;
|
||||
|
||||
prefix = [[self soURL] absoluteString];
|
||||
if ([prefix hasSuffix: @"/"])
|
||||
prefix = [prefix substringToIndex: [prefix length] - 1];
|
||||
|
||||
keys = [NSMutableArray array];
|
||||
[self _fetchFileAttachmentKeysInPart: [self bodyStructure]
|
||||
intoArray: keys withPath: nil andPrefix: prefix];
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
/* convert parts to strings */
|
||||
- (NSString *) stringForData: (NSData *) _data
|
||||
partInfo: (NSDictionary *) _info
|
||||
|
@ -1353,7 +1459,7 @@ static BOOL debugSoParts = NO;
|
|||
|
||||
- (BOOL) hasAttachment
|
||||
{
|
||||
return ([[self fetchAttachmentIds] count] > 0);
|
||||
return ([[self fetchFileAttachmentKeys] count] > 0);
|
||||
}
|
||||
|
||||
- (BOOL) isNewMail
|
||||
|
|
|
@ -839,7 +839,7 @@ static NSData* _sanitizeContent(NSData *theData)
|
|||
createXMLReaderForMimeType: @"text/html"];
|
||||
|
||||
handler = [_UIxHTMLMailContentHandler new];
|
||||
[handler setAttachmentIds: [mail fetchAttachmentIds]];
|
||||
[handler setAttachmentIds: [mail fetchFileAttachmentIds]];
|
||||
|
||||
// We check if we got an unsupported charset. If so
|
||||
// we convert everything to UTF-16{LE,BE} so it passes
|
||||
|
@ -947,7 +947,7 @@ static NSData* _sanitizeContent(NSData *theData)
|
|||
encoding = @"us-ascii";
|
||||
|
||||
handler = [_UIxHTMLMailContentHandler new];
|
||||
[handler setAttachmentIds: [mail fetchAttachmentIds]];
|
||||
[handler setAttachmentIds: [mail fetchFileAttachmentIds]];
|
||||
|
||||
// We check if we got an unsupported charset. If so
|
||||
// we convert everything to UTF-16{LE,BE} so it passes
|
||||
|
|
Loading…
Reference in New Issue