Hi,
Anyone ported imaplib.py to S60 Python? Just copying it to device and using it resulted error, so some porting would be needed.
Hi,
Anyone ported imaplib.py to S60 Python? Just copying it to device and using it resulted error, so some porting would be needed.
Did you get the error when importing it, or when calling a function from it?
import went ok but the next line:
server= IMAP4("my.mail.server")
resulted (in imaplib.py):
AttibuteError:'dict' object has no attribute 'pop'
Before that it asked IAP and obviously tried to get connected.
hi havital
if it was asking for the access point then i dont think there is any problem with the copying or porting of the imaplib.py. there can be problem with your code have a check.
thanks
Gargi Das- http://gargidas.blogsot.com
Forum Nokia Python Wiki
Learn Python at http://mobapps.org/PyS60
Thanks Jouni, I indeed took that from Python 2.5.
Now I tried with imaplib.py from Python 2.2.2 packet and it works!
In case someone is interested here are the steps to get started:
1) Copy imaplib.py to the E:\Python\lib\ folder in your memory card. The imaplib.py is found from here:
http://www.python.org/ftp/python/2.2.2/Python-2.2.2.tgz
2) Run the following script in Python shell. That giver you a list of your IMAP mailboxes.
Add you mail server and account information.
from imaplib import *
server = IMAP4("your.mail.server")
a,b=server.login("your_username","your_password")
print "a=",a," b=",b
mboxes = server.list()[1]
print "mboxes=",mboxes
Br,
Hannu
thanks haviital!
copied your imaplib.py to my phone and it works perfectly. However, IMAP4_SSL isnt available in this version.
many web email accounts require SSL to access. does anyone know of any method to use IMAP over SSL in PyS60 v1.4.5?
in python shell:
Code:from imaplib import * m=IMAP4("imap.server.com") m.login("username","password") m.list()[1] #list available mailboxes m.select("INBOX") #select Inbox m.search(None,"ALL") #list mail ids of all messages in inbox m.search(None,"UNSEEN") #list mail ids of all unread messages in inbox m.fetch(mail_id,"(BODY[HEADER.FIELDS (FROM)])")[1] #print sender details of specified message id m.fetch(mail_id,"(BODY[HEADER.FIELDS (SUBJECT)])")[1] #print subject of specified message id m.logout()
You can try the latest Python for S60 v1.9.3 which is based on Python 2.5.4 core. It has imaplib and should support SSL as well.
import antigravity
ok so now the latest versions support IMAP. does anyone know how to extract the properly extract the plain text part of the message?
Code:import email data=m.fetch(mail_id,"(RFC822)")[1][0][1] msg=rfc822.Message(data) msg=email.message_from_string(msg) msg1=msg.get_payload()[0] #assuming it is multipart print msg1.get_payload() #output the message body to screen, but charset is us-ascii so wont print properly to screen
Last edited by the86hitman; 2009-07-03 at 23:46.
Here's the code I use to get both HTML and plain text from an e-mail. By the way, the calls to M=imaplib.... and M.login both popup a request to select which access point I want to use. Does anyone know how to set the default access point for imaplib since it seems to be separate from "btsocket.set_default_access_point(apo)". I'm using 1.9.7.
Code:try: M=imaplib.IMAP4_SSL('imap.gmail.com', 993) M.login('xxx@gmail.com','xxxxxxxx') status, count = M.select('Inbox') if str(count[0]) != "0": status, data = M.fetch(count[0], '(RFC822)') messagePlainText = '' messageHTML = '' for response_part in data: if isinstance(response_part, tuple): msg = email.message_from_string(response_part[1]) for part in msg.walk(): if str(part.get_content_type()) == 'text/plain': messagePlainText = messagePlainText + str(part.get_payload()) if str(part.get_content_type()) == 'text/html': messageHTML = messageHTML + str(part.get_payload()) round.set(u'' + messagePlainText) M.close() M.logout() except: appuifw.note(u"Couldn't retrieve e-mail ", "info")
thanks for the code, will test it out later!
similar to recent discussion here:
if you're using PyS60 modules, u should use "btsocket".
if using core python modules, use "socket".
imaplib is part of the core python, therefore use socket.set_default_access_point()
The86Hitman
PyS60 1.9.7 on E71
http://www.drhtailor.com/pys60