How to send a non-standard IMAP command?

T

Tim Chase

I need to send one line of commands to an IMAP server. The commands
are not standard IMAP protocols, hence it's not specified in
http://docs.python.org/library/imaplib.html.

Sounds like you want to use the imaplib's IMAP4.xatom() to send a
custom command to your IMAP server:

http://docs.python.org/library/imaplib.html#imaplib.IMAP4.xatom

Given that you don't detail what you want to send or expect back,
it's a little hard to give you more than that, but at least that
should get you started. However, the full source to imaplib is
in your $PYTHONLIB directory so you can see how other commands
are implemented and responses are interpreted.

-tkc
 
X

Xianwen Chen

Sounds like you want to use the imaplib's IMAP4.xatom() to send a
custom command to your IMAP server:

http://docs.python.org/library/imaplib.html#imaplib.IMAP4.xatom

Given that you don't detail what you want to send or expect back,
it's a little hard to give you more than that, but at least that
should get you started. However, the full source to imaplib is
in your $PYTHONLIB directory so you can see how other commands
are implemented and responses are interpreted.

-tkc

Hi Tim,

Thanks a lot for your reply! I thought it would be simpler if the
problem was presented in a brief way. Unfortunately, not for this
case.

Here is the detail. Free Yahoo! mail accounts can be accsessed via
IMAP protocal, however, a non-standard shake hand code is needed
before log in [1]:

ID ("GUID" "1")

.. This is what I'm now working for. I tried:

IMAP4.xatom('','ID ("GUID" "1")','',)

and

dest_srv.xatom('ID ("GUID" "1")')

, but I got error messages. Any hint please?

Best regards,

Xianwen

[1] http://en.wikipedia.org/wiki/Yahoo!_Mail#Free_IMAP_and_SMTPs_access
 
M

Michael Torrie

. This is what I'm now working for. I tried:

IMAP4.xatom('','ID ("GUID" "1")','',)

and

dest_srv.xatom('ID ("GUID" "1")')

, but I got error messages. Any hint please?

What error messages?
 
T

Tim Chase

Thanks a lot for your reply! I thought it would be simpler if the
problem was presented in a brief way. Unfortunately, not for this
case.

Here is the detail. Free Yahoo! mail accounts can be accsessed via
IMAP protocal, however, a non-standard shake hand code is needed
before log in [1]:

ID ("GUID" "1")

. This is what I'm now working for. I tried:

IMAP4.xatom('','ID ("GUID" "1")','',)

and

dest_srv.xatom('ID ("GUID" "1")')

, but I got error messages. Any hint please?

In general, it would be helpful to include the error-message(s)
you get. However, I tried it with a junk Yahoo account I set up:

from imaplib import IMAP4
i = IMAP4("imap.mail.yahoo.com")
USER = '(e-mail address removed)'
PASS = 'your secret goes here'
# per the Wikipedia page you gave
# the ID has to happen before login
i.xatom('ID ("GUID" "1")')

i.login(USER, PASS)
i.select()
typ, data = i.search(None, 'ALL')
for num in data[0].split():
typ, data = i.fetch(num, '(RFC822)')
message = data[0][1].splitlines()
subject = [line
for line in message
if line.lower().startswith('subject: ')
][0]
print num, subject
i.close()
i.logout()

and it worked.

-tkc
 
X

Xianwen Chen


Hi Michael

Thanks a lot!

Yes, it would be much more convenient. Actually, I have been using a
modified version of Thunderbird [1] to access Yahoo! Mail IMAP server
for months. The reason of using Python to access the mail server is to
have less dependency on other software. Now I don't need Thunderbird
anymore.

Best regards,

Xianwen

[1] http://www.crasseux.com/linux/
 
X

Xianwen Chen

Thanks a lot for your reply! I thought it would be simpler if the
problem was presented in a brief way. Unfortunately, not for this
case.
Here is the detail. Free Yahoo! mail accounts can be accsessed via
IMAP protocal, however, a non-standard shake hand code is needed
before log in [1]:
ID ("GUID" "1")
. This is what I'm now working for. I tried:
IMAP4.xatom('','ID ("GUID" "1")','',)

dest_srv.xatom('ID ("GUID" "1")')
, but I got error messages. Any hint please?

In general, it would be helpful to include the error-message(s)
you get.  However, I tried it with a junk Yahoo account I set up:

   from imaplib import IMAP4
   i = IMAP4("imap.mail.yahoo.com")
   USER = '(e-mail address removed)'
   PASS = 'your secret goes here'
   # per the Wikipedia page you gave
   # the ID has to happen before login
   i.xatom('ID ("GUID" "1")')

   i.login(USER, PASS)
   i.select()
   typ, data = i.search(None, 'ALL')
   for num in data[0].split():
     typ, data = i.fetch(num, '(RFC822)')
     message = data[0][1].splitlines()
     subject = [line
       for line in message
       if line.lower().startswith('subject: ')
       ][0]
     print num, subject
   i.close()
   i.logout()

and it worked.

-tkc

Hi Tim,

The problem was the password. I was careless. Thanks for your advice.
Next time I'll have error codes posted.

And thanks a lot for your constructive example!

I have a strange problem that

"M = imaplib.IMAP4_SSL(M_addr)
M.debug = 2"

doesn't work. No verbose output at all. Any hint please?

Best regards,

Xianwen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,247
Latest member
crypto tax software1

Latest Threads

Top