-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQSAppleMailPlugIn_Source.m
More file actions
583 lines (496 loc) · 21.4 KB
/
QSAppleMailPlugIn_Source.m
File metadata and controls
583 lines (496 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
//
// QSAppleMailPlugIn_Source.m
// QSAppleMailPlugIn
//
// Created by Nicholas Jitkoff on 9/28/04.
// Copyright __MyCompanyName__ 2004. All rights reserved.
//
#import "QSAppleMailPlugIn_Source.h"
#import "QSAppleMailMediator.h"
#import "Mail.h"
#define kAllowLoadChildren @"allowLoadChildren"
@interface QSAppleMailPlugIn_Source (hidden)
- (QSObject *)makeMailboxObject:(NSString *)mailbox withAccountName:(NSString *)accountName withAccountId:(NSString *)accountId withFile:(NSString *)file withChildren:(BOOL)allowLoadChildren;
- (NSArray *)mailsForMailbox:(QSObject *)object;
- (NSArray *)mailContent:(QSObject *)object;
@end
@implementation QSAppleMailPlugIn_Source
{
MailApplication *_cachedMailApp;
NSMutableDictionary *_accountNameCache;
}
- (BOOL)indexIsValidFromDate:(NSDate *)indexDate forEntry:(NSDictionary *)theEntry{
return YES;
}
- (NSImage *) iconForEntry:(NSDictionary *)dict{
return nil;
}
- (NSString *)identifierForObject:(id <QSObject>)object{
return nil;
}
- (void)setQuickIconForObject:(QSObject *)object{
if ([[object primaryType]isEqualToString:kQSAppleMailMailboxType]){
NSString *mailboxName = [object objectForType:kQSAppleMailMailboxType];
if ([mailboxName rangeOfString:@"Junk" options:NSCaseInsensitiveSearch].location != NSNotFound ||
[mailboxName rangeOfString:@"Spam" options:NSCaseInsensitiveSearch].location != NSNotFound) {
[object setIcon:[QSResourceManager imageNamed:@"MailMailbox-Junk"]];
} else if ([mailboxName rangeOfString:@"Drafts" options:NSCaseInsensitiveSearch].location != NSNotFound){
[object setIcon:[QSResourceManager imageNamed:@"MailMailbox-Drafts"]];
} else if ([mailboxName rangeOfString:@"Sent" options:NSCaseInsensitiveSearch].location != NSNotFound){
[object setIcon:[QSResourceManager imageNamed:@"MailMailbox-Sent"]];
} else if ([mailboxName rangeOfString:@"Trash" options:NSCaseInsensitiveSearch].location != NSNotFound ||
[mailboxName rangeOfString:@"Deleted" options:NSCaseInsensitiveSearch].location != NSNotFound){
[object setIcon:[QSResourceManager imageNamed:@"TrashIcon"]];
} else if ([mailboxName rangeOfString:@"Inbox" options:NSCaseInsensitiveSearch].location != NSNotFound){
[object setIcon:[QSResourceManager imageNamed:@"MailMailbox-Inbox"]];
} else {
[object setIcon:[QSResourceManager imageNamed:@"MailMailbox"]];
}
return;
}
if ([[object primaryType]isEqualToString:kQSAppleMailMessageType]){
[object setIcon:[QSResourceManager imageNamed:@"MailMessage"]];
return;
}
}
- (BOOL)loadIconForObject:(QSObject *)object{
return NO;
}
- (BOOL)objectHasChildren:(QSObject *)object{
// when mailbox appears in third pane, you can't arrow into it
if ([object objectForMeta:kAllowLoadChildren] != nil) {
return [[object objectForMeta:kAllowLoadChildren] boolValue];
}
return NO;
}
- (BOOL)loadChildrenForObject:(QSObject *)object{
// when mailbox appears in third pane, you can't arrow into it
if ([object objectForMeta:kAllowLoadChildren] != nil && ![[object objectForMeta:kAllowLoadChildren] boolValue]) {
return NO;
}
if ([[object primaryType]isEqualToString:QSFilePathType]){
[object setChildren:[self objectsForEntry:nil]];
return YES;
}
if ([[object primaryType] isEqualToString:kQSAppleMailMailboxType]){
// Check if we have a cached mailbox reference for loading sub-mailboxes
MailMailbox *mailboxRef = [object objectForMeta:@"mailboxReference"];
if (mailboxRef) {
NSArray *mailboxes = [mailboxRef mailboxes];
NSMutableArray *children = [NSMutableArray array];
if ([mailboxes count]) {
NSString *accountName = [object details];
NSString *accountId = [object objectForMeta:@"accountId"];
NSString *mailboxName = [object objectForMeta:@"mailboxName"];
NSString *parentPath = [NSString stringWithFormat:@"%@/%@", accountName, mailboxName];
@try {
// Load sub-mailboxes on demand using scripting bridge
NSString *mailboxPath = [self buildMailboxPathForMailbox:mailboxRef];
[self addMailboxesFromArray:[mailboxRef mailboxes]
toArray:children
accountName:accountName
accountId:accountId
allowLoadChildren:YES
parentPath:parentPath
mailboxPath:mailboxPath
recursive:NO];
} @catch (NSException *e) {
NSLog(@"AppleMailPlugin loadChildrenForObject: Error loading sub-mailboxes: %@", e);
}
}
// Load messages via filesystem/Spotlight (much faster for many messages)
[children addObjectsFromArray:[self mailsForMailbox:object]];
[object setChildren:children];
} else {
// Fallback to loading messages only via filesystem
[object setChildren:[self mailsForMailbox:object]];
}
return YES;
}
// if ([[object primaryType]isEqualToString:kQSAppleMailMessageType]){
// [object setChildren:[self mailContent:object]];
// return YES;
// }
return NO;
}
- (NSArray *) objectsForEntry:(NSDictionary *)theEntry{
return [self allMailboxes];
}
- (NSArray *)allMailboxes {
return [self allMailboxes:YES recursive:NO];
}
- (NSArray *)allMailboxes:(BOOL)allowLoadChildren recursive:(BOOL)recursive {
NSMutableArray *objects=[NSMutableArray arrayWithCapacity:1];
// Get Mail app instance
MailApplication *mailApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.mail"];
if (!mailApp) {
return objects;
}
// Batch fetch all accounts at once to minimize inter-process calls
NSArray *accounts = [mailApp accounts];
for (MailAccount *account in accounts) {
// Cache these properties - they're expensive IPC calls
NSString *accountName = [account name];
NSString *accountId = [account id];
if (!accountName || !accountId) {
continue;
}
// Process mailboxes for this account
[self addMailboxesFromArray:[account mailboxes]
toArray:objects
accountName:accountName
accountId:accountId
allowLoadChildren:allowLoadChildren
parentPath:nil
mailboxPath:nil
recursive:recursive];
}
return objects;
}
- (NSString *)buildMailboxPathForMailbox:(MailMailbox *)mailbox {
// Walk up the container hierarchy and build the complete filesystem path
NSMutableArray *pathComponents = [NSMutableArray array];
MailMailbox *currentMailbox = mailbox;
while (currentMailbox) {
NSString *name = [currentMailbox name];
if (name) {
[pathComponents insertObject:[NSString stringWithFormat:@"%@.mbox", name] atIndex:0];
} else {
break;
}
currentMailbox = [currentMailbox container];
}
return [pathComponents componentsJoinedByString:@"/"];
}
- (void)addMailboxesFromArray:(NSArray *)mailboxes toArray:(NSMutableArray *)objects accountName:(NSString *)accountName accountId:(NSString *)accountId allowLoadChildren:(BOOL)allowLoadChildren parentPath:(NSString *)parentPath mailboxPath:(NSString *)mailboxPath recursive:(BOOL)recursive {
// Get the base Mail path with version detection
NSString *mailPath = [self getMailPath];
for (MailMailbox *mailbox in mailboxes) {
NSString *mailboxName = [mailbox name];
if (!mailboxName) {
continue;
}
// Build display path (for UI)
NSString *currentPath = parentPath ? [NSString stringWithFormat:@"%@/%@", parentPath, mailboxName] : mailboxName;
// Build filesystem path (includes .mbox extensions)
NSString *currentMailboxPath = mailboxPath ? [NSString stringWithFormat:@"%@/%@.mbox", mailboxPath, mailboxName] : [NSString stringWithFormat:@"%@.mbox", mailboxName];
QSObject *newObject = [QSObject objectWithName:[NSString stringWithFormat:@"%@ %@", accountName, currentPath]];
[newObject setObject:mailboxName forType:kQSAppleMailMailboxType];
[newObject setLabel:mailboxName];
[newObject setDetails:accountName];
[newObject setObject:accountId forMeta:@"accountId"];
[newObject setObject:mailboxName forMeta:@"mailboxName"];
[newObject setObject:mailbox forMeta:@"mailboxReference"];
[newObject setObject:currentMailboxPath forMeta:@"mailbox"];
[newObject setIdentifier:[NSString stringWithFormat:@"mailbox:%@//%@", accountName, currentPath]];
[newObject setObject:[NSNumber numberWithBool:allowLoadChildren] forMeta:kAllowLoadChildren];
[newObject setPrimaryType:kQSAppleMailMailboxType];
// Set the account path for file system access
[newObject setObject:[mailPath stringByAppendingPathComponent:accountId] forMeta:@"accountPath"];
[objects addObject:newObject];
if (recursive) {
// Recursively load sub-mailboxes
NSArray *submailboxes = [mailbox mailboxes];
if ([submailboxes count] > 0) {
[self addMailboxesFromArray:submailboxes
toArray:objects
accountName:accountName
accountId:accountId
allowLoadChildren:NO
parentPath:currentPath
mailboxPath:currentMailboxPath
recursive:recursive];
}
}
}
}
- (NSString *)getMailPath {
NSString *basePath = [MAILPATH stringByStandardizingPath];
NSFileManager *fm = [NSFileManager defaultManager];
// Try to access folders in reverse increment from V11 down to V1
NSArray *versionedPaths = @[@"V11", @"V10", @"V9", @"V8", @"V7", @"V6", @"V5", @"V4", @"V3", @"V2", @"V1"];
for (NSString *versionedPath in versionedPaths) {
NSString *testPath = [basePath stringByAppendingPathComponent:versionedPath];
BOOL isDir;
if ([fm fileExistsAtPath:testPath isDirectory:&isDir] && isDir) {
return testPath;
}
}
// Fallback to base path if no versioned folder found
return basePath;
}
- (QSObject *)makeMailboxObject:(NSString *)mailbox withAccountName:(NSString *)accountName withAccountId:(NSString *)accountId withFile:(NSString *)file withChildren:(BOOL)allowLoadChildren {
NSString *mailboxType = [mailbox pathExtension];
NSString *mailboxName = [mailbox stringByDeletingPathExtension];
QSObject *newObject = [QSObject objectWithName:[NSString stringWithFormat:@"%@ %@", accountName, mailboxName]];
[newObject setObject:mailboxName forType:kQSAppleMailMailboxType];
[newObject setLabel:mailboxName];
[newObject setDetails:accountName];
[newObject setObject:accountId forMeta:@"accountId"];
[newObject setObject:mailboxType forMeta:@"mailboxType"];
[newObject setObject:mailbox forMeta:@"mailbox"];
[newObject setIdentifier:[NSString stringWithFormat:@"mailbox:%@//%@", accountName, mailboxName]];
NSString *accountPath = [NSApplication isLion] ? [MAILPATH stringByAppendingPathComponent:@"V2"] : MAILPATH;
[newObject setObject:[[accountPath stringByAppendingPathComponent:file] stringByStandardizingPath] forMeta:@"accountPath"];
[newObject setObject:mailboxName forMeta:@"mailboxName"];
[newObject setObject:[NSNumber numberWithBool:allowLoadChildren] forMeta:kAllowLoadChildren];
[newObject setPrimaryType:kQSAppleMailMailboxType];
return newObject;
}
- (NSString *)decodeRFC2047Subject:(NSString *)subject {
// Handle RFC 2047 encoded-word format: =?charset?encoding?encoded-text?=
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"=\\?([^?]+)\\?([BQ])\\?([^?]+)\\?=" options:0 error:NULL];
NSMutableString *decoded = [subject mutableCopy];
NSArray *matches = [regex matchesInString:subject options:0 range:NSMakeRange(0, [subject length])];
// Process matches in reverse order to maintain string positions
for (NSTextCheckingResult *match in [matches reverseObjectEnumerator]) {
NSString *charset = [subject substringWithRange:[match rangeAtIndex:1]];
NSString *encoding = [subject substringWithRange:[match rangeAtIndex:2]];
NSString *encodedText = [subject substringWithRange:[match rangeAtIndex:3]];
NSString *decodedPart = nil;
if ([encoding isEqualToString:@"Q"]) {
// Quoted-printable decoding
// Replace _ with space and decode =XX sequences
NSMutableString *qDecoded = [[encodedText stringByReplacingOccurrencesOfString:@"_" withString:@" "] mutableCopy];
// Decode =XX hex sequences
NSRegularExpression *hexRegex = [NSRegularExpression regularExpressionWithPattern:@"=([0-9A-F]{2})" options:NSRegularExpressionCaseInsensitive error:NULL];
NSMutableData *decodedData = [NSMutableData data];
NSRange searchRange = NSMakeRange(0, [qDecoded length]);
NSArray *hexMatches = [hexRegex matchesInString:qDecoded options:0 range:searchRange];
// Build the decoded bytes
NSUInteger lastEnd = 0;
for (NSTextCheckingResult *hexMatch in hexMatches) {
// Add the literal characters before this hex code
if (hexMatch.range.location > lastEnd) {
NSString *literal = [qDecoded substringWithRange:NSMakeRange(lastEnd, hexMatch.range.location - lastEnd)];
[decodedData appendData:[literal dataUsingEncoding:NSUTF8StringEncoding]];
}
// Decode the hex value
NSString *hexStr = [qDecoded substringWithRange:[hexMatch rangeAtIndex:1]];
unsigned int hexValue;
[[NSScanner scannerWithString:hexStr] scanHexInt:&hexValue];
unsigned char byte = (unsigned char)hexValue;
[decodedData appendBytes:&byte length:1];
lastEnd = hexMatch.range.location + hexMatch.range.length;
}
// Add remaining literal characters
if (lastEnd < [qDecoded length]) {
NSString *literal = [qDecoded substringFromIndex:lastEnd];
[decodedData appendData:[literal dataUsingEncoding:NSUTF8StringEncoding]];
}
decodedPart = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
} else if ([encoding isEqualToString:@"B"]) {
// Base64 decoding
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:encodedText options:0];
decodedPart = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
}
if (decodedPart) {
[decoded replaceCharactersInRange:match.range withString:decodedPart];
}
}
return decoded;
}
- (NSString *)messageIDFromEmlxFile:(NSString *)filePath {
NSData *data = [NSData dataWithContentsOfFile:filePath];
if (!data || [data length] == 0) {
return nil;
}
// EMLX format: [byte_count]\n[message][plist]
const char *bytes = (const char *)[data bytes];
NSUInteger dataLen = [data length];
// Find the newline that terminates the length
NSUInteger newlinePos = 0;
for (NSUInteger i = 0; i < dataLen && i < 20; i++) {
if (bytes[i] == '\n') {
newlinePos = i;
break;
}
}
if (newlinePos == 0) {
return nil;
}
// Extract and parse the length number
NSString *lengthStr = [[NSString alloc] initWithBytes:bytes length:newlinePos encoding:NSUTF8StringEncoding];
lengthStr = [lengthStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSUInteger messageLength = [lengthStr integerValue];
if (messageLength == 0 || (newlinePos + 1 + messageLength > dataLen)) {
return nil;
}
// Extract just the message portion
NSUInteger messageStart = newlinePos + 1;
NSData *messageData = [data subdataWithRange:NSMakeRange(messageStart, messageLength)];
NSString *messageContent = [[NSString alloc] initWithData:messageData encoding:NSUTF8StringEncoding];
if (!messageContent) {
return nil;
}
// Parse headers to find Message-ID
NSArray *lines = [messageContent componentsSeparatedByString:@"\n"];
for (NSString *line in lines) {
if ([line hasPrefix:@"Message-Id:"]) {
NSString *messageId = [[line substringFromIndex:11] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([messageId hasPrefix:@"<"] && [messageId hasSuffix:@">"]) {
messageId = [messageId substringWithRange:NSMakeRange(1, [messageId length] - 2)];
}
return messageId;
}
// Stop at first blank line (end of headers)
if ([line length] == 0) {
break;
}
}
return nil;
}
- (NSDictionary *)emailMetadataFromFile:(NSString *)filePath {
NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
NSData *data = [NSData dataWithContentsOfFile:filePath];
if (!data || [data length] == 0) {
return metadata;
}
// EMLX format: [byte_count]\n[message][plist]
// First, parse the length header
const char *bytes = (const char *)[data bytes];
NSUInteger dataLen = [data length];
// Find the newline that terminates the length
NSUInteger newlinePos = 0;
for (NSUInteger i = 0; i < dataLen && i < 20; i++) {
if (bytes[i] == '\n') {
newlinePos = i;
break;
}
}
if (newlinePos == 0) {
return metadata;
}
// Extract and parse the length number
NSString *lengthStr = [[NSString alloc] initWithBytes:bytes length:newlinePos encoding:NSUTF8StringEncoding];
lengthStr = [lengthStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSUInteger messageLength = [lengthStr integerValue];
if (messageLength == 0 || (newlinePos + 1 + messageLength > dataLen)) {
return metadata;
}
// Extract just the message portion
NSUInteger messageStart = newlinePos + 1;
NSData *messageData = [data subdataWithRange:NSMakeRange(messageStart, messageLength)];
NSString *messageContent = [[NSString alloc] initWithData:messageData encoding:NSUTF8StringEncoding];
if (!messageContent) {
return metadata;
}
// Parse headers to find Subject and From
NSArray *lines = [messageContent componentsSeparatedByString:@"\n"];
for (NSString *line in lines) {
if ([line hasPrefix:@"Subject:"]) {
NSString *subject = [[line substringFromIndex:8] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (subject && [subject length] > 0) {
// Decode RFC 2047 encoded-word format
subject = [self decodeRFC2047Subject:subject];
[metadata setObject:subject forKey:@"subject"];
}
}
if ([line hasPrefix:@"From:"]) {
NSString *from = [[line substringFromIndex:5] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (from && [from length] > 0) {
[metadata setObject:from forKey:@"from"];
}
}
// Stop at first blank line (end of headers)
if ([line length] == 0) {
break;
}
}
return metadata;
}
- (NSArray *)mailsForMailbox:(QSObject *)object {
NSString *mailboxName = [object objectForType:kQSAppleMailMailboxType];
NSString *accountID = [object objectForMeta:@"accountId"];
NSString *accountPath = [object objectForMeta:@"accountPath"];
MailMailbox *mailboxRef = [object objectForMeta:@"mailboxReference"];
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:0];
if (!accountPath || !mailboxRef) {
return objects;
}
// Build the complete mailbox path by walking up containers if we have the reference
NSString *mailboxPath;
mailboxPath = [accountPath stringByAppendingPathComponent:[self buildMailboxPathForMailbox:mailboxRef]];
NSFileManager *fm = [NSFileManager defaultManager];
// Check if mailbox path exists
BOOL isDir;
if (![fm fileExistsAtPath:mailboxPath isDirectory:&isDir] || !isDir) {
return objects;
}
@autoreleasepool {
// Recursively find all .emlx files in the mailbox
NSDirectoryEnumerator *enumerator = [fm enumeratorAtPath:mailboxPath];
NSMutableArray *emlxFiles = [NSMutableArray array];
for (NSString *file in enumerator) {
if ([[file pathExtension] isEqualToString:@"emlx"]) {
[emlxFiles addObject:[mailboxPath stringByAppendingPathComponent:file]];
}
}
// If mailbox folder is empty, just return empty array
if ([emlxFiles count] == 0) {
return objects;
}
// Normal case: process files found in the mailbox folder
NSLock *arrayLock = [[NSLock alloc] init];
[emlxFiles enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(NSString *filePath, NSUInteger idx, BOOL *stop) {
NSDictionary *metadata = [self emailMetadataFromFile:filePath];
NSString *subject = metadata[@"subject"];
NSString *from = metadata[@"from"];
if (!subject) {
return;
}
if ([subject length] > 255) {
subject = [subject substringToIndex:255];
}
NSString *fsName = [filePath lastPathComponent];
QSObject *messageObjectNew = [[QSObject alloc] init];
[messageObjectNew setPrimaryType:kQSAppleMailMessageType];
[messageObjectNew setObject:accountPath forMeta:@"accountPath"];
[messageObjectNew setObject:mailboxName forMeta:@"mailboxName"];
[messageObjectNew setObject:accountID forMeta:@"accountId"];
[messageObjectNew setObject:[object details] forMeta:@"accountName"];
[messageObjectNew setParentID:[object identifier]];
[messageObjectNew setObject:subject forMeta:kQSObjectPrimaryName];
[messageObjectNew setDetails:from];
[messageObjectNew setIdentifier:[NSString stringWithFormat:@"message:%@", fsName]];
[messageObjectNew setObject:fsName forMeta:@"message_id"];
if (subject) {
[[messageObjectNew dataDictionary] setObject:subject forKey:kQSAppleMailMessageType];
}
[messageObjectNew setObject:filePath forMeta:QSFilePathType];
// Lock only for the array addition (fast operation)
[arrayLock lock];
[objects addObject:messageObjectNew];
[arrayLock unlock];
}];
}
return objects;
}
//- (NSArray *)mailContent:(QSObject *)object
//{
// NSMutableArray *objects = [NSMutableArray arrayWithCapacity:1];
// QSObject *newObject;
//
// // read mail file and parse message
// CTCoreMessage *message = [[CTCoreMessage alloc] initWithFileAtPath:@"/Users/rob/example.msg"];
// if (message) {
// // create QSObjects
// newObject = [QSObject objectWithString:[[message body] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
// [newObject setParentID:[object identifier]];
// [objects addObject:newObject];
//
// CTCoreAddress *from = [[message from] anyObject];
// [message release];
//
// newObject = [QSObject objectWithName:[from email]];
// [newObject setObject:[from email] forType:QSEmailAddressType];
// [newObject setDetails:[from name]];
// [newObject setParentID:[object identifier]];
// [newObject setPrimaryType:QSEmailAddressType];
// [objects addObject:newObject];
//
// return objects;
// }
// return nil;
//}
@end