Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Delete msgs from junk folder / data structures in apple script
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 8th September 19:13
achim domma
External User
 
Posts: 1
Default Delete msgs from junk folder / data structures in apple script



Hi,

I'm a quite experienced C++/C#/Python developer, but quite new to Mac
OS X and apple script. I have too much messages in my junk folder and
want to delete messages which have subjects which appear more than
once. My idea was to iterate over the junk folder, count the occurence
of each subjekt and then delete all messages whose subject as a
occurence greater than a given threshold.

I was able to connect a script to the mail tool and do iterate over
the messages in the junk folder. But I could not find any infos about
dictinary like data structures in apple script.

Any starting point to solve the above problem would be very
appreciated. If apple script is the wrong tool, I'm also open for
better ideas.

best regards,
Achim
  Reply With Quote


 


2 8th September 19:13
has
External User
 
Posts: 1
Default Delete msgs from junk folder / data structures in apple script



Doesn't have one. There are various workarounds/solutions to this, but
since you already know Python the easiest thing would just be to use
that. Example: #!/usr/bin/python
from appscript import * # from <http://appscript.sourceforge.net>

threshold = 2 # your value here

mail = app('Mail')

subjects = mail.junk_mailbox.messages.subject.get()

subjectcount = {}

for name in subjects:
name = name.lower()
if name in subjectcount:
subjectcount[name] += 1
else:
subjectcount[name] = 1

for name, count in subjectcount.items():
if count > threshold:
mail.junk_mailbox.messages[its.subject == name].delete()
print 'Deleted %i junk messages named %r' % (count, name)


HTH

has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666