By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

IMAP4 search with special characters

P: n/a

Hi all,

I have a problem when searching for text with special characters in
e-mails in an IMAP server. I'm using imaplib in python 2.4.3 and I can't
get this code working:

# first connect and login
conn = IMAP4(my_server)
conn.login(my_user, my_pass)

# now select INBOX'INBOX')

# and search for messages (the first parameter of "search" is the
encoding, which defaults to None), '(ALL)') # output: ('OK', ['1 2 3'])

# That works perfectly and I get the 3 messages that I have in my Inbox:
# Now I want to search for messages with special characters. This works
(still no special characters in my search):, '(BODY gasse)')

# and even this:'ISO-8859-1', '(BODY gasse)')

# but not this (there comes the 'ö'):'ISO-8859-1', '(BODY Lemböckgasse)') # error: SEARCH
command error: BAD ['Bogus criteria list in SEARCH']

# After having read the IMAP4 documentation I thought this could work:'ISO-8859-1', '(CHARSET ISO-8859-1 BODY Lemböckgasse)')

# I tried everything that came up to my mind, getting always the same
error. For instance:, '(CHARSET ISO-8859-1 BODY Lemböckgasse)'), '(BODY Lemb\xf6ckgasse)'), '(BODY Lemböckgasse)'.encode('ISO-8859-1')) # here I
get the error "can't decode byte 0xf6 in position 10"'ISO-8859-1', '(BODY Lemböckgasse)'.encode('ISO-8859-1'))

And so on. Does anybody have the remotest idea what I'm doing wrong and
how I could find my e-mail?

Thanks in advance,

Luis Corrales
Jul 21 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.