Domanda

I'd appreciate help with how can I circumvent IMAP UID SEARCH for Message-ID containing % (percent) sign:

import imaplib

messageId = '<CA824955.19602%username@hostname.com>'
M.uid('search', None, 'HEADER', 'Message-ID', "'" + messageId + "'")

getting:

51:55.73 > EKEE4 UID SEARCH HEADER Message-ID '<CA824955.19602%username@hostname.com>'
51:55.83 < EKEE4 BAD Could not parse command
51:55.83 BAD response: Could not parse command

I've tried

CA824955.19602%username@hostname.com
'CA824955.19602%username@hostname.com'
'CA824955.19602\%username@hostname.com'
'CA824955.19602%%username@hostname.com'

with or without quotes all were returning same "Could not parse command".

Server is imap.gmail.com

Thank you,

PS: Thanks much @glglgl, wrapping it into '"' + messageId + '"' actually helped. I'm getting messageId from mysql string field, for some reason it didn't work without this wrapping... Question is solved, thank you very much for lightning speed answer!!!

È stato utile?

Soluzione

I don't see your problem.

import imaplib m=imaplib.IMAP4_SSL([...]) m.login([...])
m.select('Archiv/misc') m.uid('search', None, 'HEADER', 'Message-ID',
   '<1i6c6x0.inv6rk1u5kx5cN%68kmac@gmail.com>')

works perfectly for me.

Have you already tried to omit the "'" + and + "'"?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top