[Pythonmac-SIG] controlling Mail.app and GnuPG

has hengist.podd at virgin.net
Mon Aug 25 23:44:14 CEST 2008


Henning Hraban Ramm wrote:

> It is known that the public API of Apple's Mail.app is incomplete  
> and buggy, therefore stuff like the GnuPG plugin stay in eternal  
> beta (and just don't work on my German system - I guess i might my a  
> language problem).
> Anyway.
>
> I tried to write a little helper for GPG encrypted mails - before I  
> dragged the "encrypted.asc" attachment in some folder, called gpg in  
> the bash, copied the decrypted text back in my reply window and  
> replaced all the MIME codes with proper umlauts etc.
> (I can encrypt the mail via S/MIME, my friend can decrypt that, but  
> didn't get S/MIME encryption to work in her Linux Thunderbird or  
> Evolution, so she sends GPG encrypted...)
>
> So, my script gets the selected message in Mail.app...
>
> * issue (1) [appscript syntax for Mail.app]:
> I can list the attachments with appscript, but I didn't find a way  
> to save them or to access them as files.

Something like this should work (assuming the files don't already  
exist in the destination folder):

message = app('Mail').selection()[0]
for attachment in message.mail_attachments():
	attachment.save(in_=mactypes.File(u'/path/to/outfolder/' +  
attachment.name()))


> Now I've finally the readable text of the message in proper unicode.
> Let's make a reply mail:
>
> reply = message.reply(opening_window=True)
>
> I don't understand why usually a message window is invisible, but  
> anyway, that works so far.
>
> reply.content.set(decrypted_text)
>
> Doesn't work: If I try it in PyCrust, the new text appears above the  
> initial content, can't delete that.
> In my script I get only a CommandError:
>
> CommandError -10000: Apple event handler failed.
> 	Failed command: app(u'/Applications/ 
> Mail.app').outgoing_messages.ID(409455472).content.set(u'bla')
>
> Despite that error, when I close Mail.app, a new message containing  
> my text appears, i.e. instead of setting the content of my  
> previously created reply mail, it makes a new outgoing message in  
> the background.
>
> * issue (4) [appscript syntax for Mail.app]:
> How can I set the complete content of a reply message?


Dunno offhand; might have time to look into it tomorrow unless anyone  
else has any ideas. As you say, Mail's scripting interface is less  
than stellar. BTW, you could also try asking on Apple's AppleScript- 
users mailing list; I expect there's a few folk there who've had  
dealings with Mail as well and might be able to shed some light on the  
problem.

HTH

has
-- 
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net



More information about the Pythonmac-SIG mailing list