Hi all, here i've found a great manual to build pyext: http://puredata.hurleur.com/viewtopic.php?pid=37639#p37639
in attachement is example og my [pyext gmail.box] object, which can check and count emails with given 'subject' fero
try: import pyext except: print "ERROR: This script must be loaded by the PD pyext external" sys.exit() import imaplib import email mail = '' user = 'user' passw = 'pass' subject = '' uidsList = '' data = '' class box(pyext._class): # number of inlets and outlets _inlets=1 _outlets=2 # constructor def __init__(self,*args): if len(args) == 2: global user, passw user = args[0] passw = "%s" % args[1] def subject_1(self, *args): global subject subject = " ".join(str(e) for e in args) print "Subject changed to '",subject,"'" #print args def login_1(self, *args): global mail, user, passw if len(args) == 2: user = args[0] passw = "%s" % args[1] print "Logging to gmail as", user mail = imaplib.IMAP4_SSL('imap.gmail.com') mail.login( user, passw) mail.list() mail.select("inbox") # connect to inbox. def logout_1(self): print "Logging out from gmail..." global mail mail.close() mail.logout() def check_1(self): global mail, subject, uidsList, data print "________________________________________________" print "Checking mail for SUBJECT ", subject tmp = '(HEADER Subject "%s")' % subject result, data = mail.uid('search', None, tmp) # search and return uids instead #print data str = ''.join(data) if (len(str)>0): uidsList = str.split(' ') #print mylist size = len(uidsList) else: size = 0 if(size > 0 ): latest_email_uid = data[0].split()[-1] result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') raw_email = data[0][1] # here's the body, which is raw text of the whole email # including headers and alternate payloads email_message = email.message_from_string(raw_email) #print email.utils.parseaddr(email_message['From']) self._outlet(2,email.utils.parseaddr(email_message['From'])) self._outlet(2,uidsList) #else: #print "No emails ;(" print "Found ", size, "emails." self._outlet(1,float(size)) def delete_1(self,argv): global mail print "Deleting mail ", argv mail.uid('STORE', argv, '+FLAGS', '\\Deleted') mail.expunge() def deleteall_1(self): global mail, subject, uidsList print "Deleting all mail with subject '",subject ,"'" for n in uidsList: mail.uid('STORE', n, '+FLAGS', '\\Deleted') mail.expunge() def list_1(self): global uidsList print uidsList
#N canvas 591 94 698 581 10; #X declare -lib py; #X symbolatom 91 204 40 0 0 0 - - -; #X obj 91 183 zexy/list2symbol; #X obj 533 -5 import py; #X msg 139 69 check; #X msg 30 12 logout; #X msg 142 120 delete 16437; #X symbolatom 204 183 40 0 0 0 - - -; #X text 89 222 uuids of emails; #X text 338 198 email adress of newest; #X msg 150 89 list; #X obj 24 152 pyext gmail.box; #X obj 203 161 zexy/list2symbol; #X msg 13 98 deleteall; #X floatatom 33 223 5 0 0 0 - - -; #X text 222 7 1.fill your login data; #X text 266 37 2.fill with some subject string of your emails; #X text 260 65 3.press; #X text 29 243 num of emails with given subject; #X msg 113 10 login user pass; #X msg 126 38 subject some subject; #X connect 1 0 0 0; #X connect 3 0 10 1; #X connect 4 0 10 1; #X connect 5 0 10 1; #X connect 9 0 10 1; #X connect 10 0 13 0; #X connect 10 1 1 0; #X connect 10 2 11 0; #X connect 11 0 6 0; #X connect 12 0 10 1; #X connect 18 0 10 1; #X connect 19 0 10 1;
_______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list