I'd like to use Scripting Bridge to find messages in Mail's Inbox that have attachments with a certain suffix (e.g., txt) and ultimately retrieve just those.

When I get a reference to "Inbox", what I want (in plain English) is ALL messages that have at least one attachment whose name ends in "txt".

I took the SBSendEMail example code as a base, and was hoping I could get the last code chunk at the end to work, but it fails.

MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
MailMailbox *inbox = mail.inbox;

SBElementArray *messages = inbox.messages;

#if 1 // cannonical routine, works fine, slow

for(MailMessage *message in messages)
{
    SBElementArray *mailAttachments = [message mailAttachments];
    for(MailMailAttachment *attachment in mailAttachments)
    {
        if([[attachment.name pathExtension] isEqualToString:@"txt"])
        {
            ; // NSLog()
        }
    }
}

#elif 0 // works, takes a REALLY long time

SBElementArray *atts = [messages valueForKeyPath:@"@unionOfArrays.mailAttachments"]; // time hog NSPredicate *filter = [NSPredicate predicateWithFormat:@"SELF.name ENDSWITH 'txt'"];
[atts filterUsingPredicate:filter];

#elif  0// fails

// Prefilter, getting only those Messages that have attachments first...

NSPredicate *filter = [NSPredicate
    predicateWithFormat:@"self.mailattachmen...@count > 0"];
[messages filterUsingPredicate:filter];

#endif


Am I missing something, or is this just the best that I can do?

David

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to