Re: Leopard (10.5+): Any Upper-Level (Cocoa) access to Mail?
Re: Leopard (10.5+): Any Upper-Level (Cocoa) access to Mail?
- Subject: Re: Leopard (10.5+): Any Upper-Level (Cocoa) access to Mail?
- From: has <email@hidden>
- Date: Mon, 2 Jun 2008 21:34:41 +0100
email@hidden wrote:
I'm searching for a Cocoa/ObjC routine to access/check Mail;
specifically #read & #unread mail messages.
Use AppleScript or one of the ObjC-Apple event bridges to control
Mail. For example, using objc-appscript:
#import "MLGlue/MLGlue.h"
// To generate Mail glue: osaglue -o MLGlue -p ML Mail
void CountMessagesInMailbox(MLReference *box) {
int totalCount, unreadCount;
NSString *name;
totalCount = [[[[box messages] count] send] intValue];
unreadCount = [[[box unreadCount] getItem] intValue];
name = [[box name] getItem];
printf("Mailbox %s contains %i read and %i unread messages.\n",
[name UTF8String], totalCount - unreadCount, unreadCount);
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i;
MLApplication *mail = [[MLApplication alloc] initWithBundleID:
@"com.apple.mail"];
printf("Standard mailboxes:\n");
CountMessagesInMailbox([mail draftsMailbox]);
CountMessagesInMailbox([mail inbox]);
CountMessagesInMailbox([mail outbox]);
CountMessagesInMailbox([mail sentMailbox]);
printf("\nUser-defined mailboxes...\n");
int boxCount = [[[[mail mailboxes] count] send] intValue];
for (i = 1; i <= boxCount; i++) { // note: application references are
1-indexed
CountMessagesInMailbox([[mail mailboxes] at: i]);
}
[mail release];
[pool drain];
return 0;
}
Regardless of what IPC bridge you use, I'd suggest that questions on
how to perform specific operations on Mail are best directed to the
AppleScript-users mailing list <http://lists.apple.com/mailman/listinfo/applescript-users
> as that's where most experienced Mail scripters can be found.
Obviously, any answers you get will be phrased in AppleScript, so
you'll want to learn the AppleScript language in order to translate it
back to ObjC. I'd suggest a copy of Matt Neuburg's "AppleScript: The
Definitive Guide" as a programmer-friendly introduction to the beast.
I'm also working on ObjC syntax support in ASTranslate (a very handy
tool that converts AppleScript commands to their appscript
equivalents) which I hope to have done fairly soon.
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
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