• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Scripting Bridge to Mail using predicates question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scripting Bridge to Mail using predicates question


  • Subject: Scripting Bridge to Mail using predicates question
  • From: David Hoerl <email@hidden>
  • Date: Wed, 19 May 2010 15:49:01 -0400

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.mailAttachments.@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 (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: Simulating Text Input
  • Next by Date: Re: Simulating Text Input
  • Previous by thread: Re: iPhone/iPad: Desktop wallpaper can't be set.
  • Next by thread: Cracks in image using NSDrawThreePartImage
  • Index(es):
    • Date
    • Thread