Форум сайта python.su
Здравствуйте, столкнулся с проблемой записи eml в файл, при использовании библиотеки pop3.
import poplib username = 'MyMail@mail.ru' password = 'MyPass' p = poplib.POP3('pop.mail.ru') p.user(username) p.pass_(password) numMessages = len(p.list()[1]) for i in range(numMessages): for j in p.retr(i+1)[1]: outf = open('eml/%s.eml' % i, "a") outf.write('\n\r'.join(p.retr(i+1)[1])) outf.close() p.quit()
Отредактировано PythonRecrut (Март 26, 2014 21:20:58)
Офлайн
PythonRecrutу print() есть аргумент file
print(j) выводит eml в консоль
>>> import sys >>> >>> print('test', file=sys.stderr) test >>>
PythonRecrutTypeError: sequence item 0: expected str instance, bytes found
>>> ' '.join((b'abc', b'def')) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence item 0: expected str instance, bytes found >>> >>> b' '.join((b'abc', b'def')) b'abc def' >>>
PythonRecrut\r\n (0d 0a)'\n\r'.
Офлайн
Спасибо за помощь.
В итоге получилось.
numMessages = len(p.list()[1]) for i in range(numMessages): outf = open('eml%s.eml' % i, 'wb') outf.write(b'\n'.join(p.retr(i + 1)[1])) outf.close()
Офлайн
там должно быть CRLF в любой системе в соответствии с rfc5322
Messages are divided into lines of characters. A line is a series of
characters that is delimited with the two characters carriage-return
and line-feed; that is, the carriage return (CR) character (ASCII
value 13) followed immediately by the line feed (LF) character (ASCII
value 10). (The carriage return/line feed pair is usually written in
this document as "CRLF".)
Отредактировано py.user.next (Март 26, 2014 22:48:16)
Офлайн
Вы правы
outf.write(b'\r\n'.join(p.retr(i + 1)[1]))
Офлайн