polo2ro / imapbox

Dump imap inbox to a local folder in a regular backupable format: html, json and attachements
MIT License
223 stars 47 forks source link

TypeError: initial_value must be str or None, not bytes #15

Open mrhyde opened 6 years ago

mrhyde commented 6 years ago

Despite the declared python3 support, I was unable to run it on Ubuntu 17.10

  File "imapbox.py", line 97, in <module>
    main()
  File "imapbox.py", line 90, in main
    stats = mailbox.copy_emails(options['days'], options['local_folder'], options['wkhtmltopdf'])
  File "/home/imapbox/mailboxresource.py", line 39, in copy_emails
    if self.saveEmail(data):
  File "/home/imapbox/mailboxresource.py", line 72, in saveEmail
    msg = email.message_from_string(response_part[1])
  File "/usr/lib/python3.6/email/__init__.py", line 38, in message_from_string
    return Parser(*args, **kws).parsestr(s)
  File "/usr/lib/python3.6/email/parser.py", line 68, in parsestr
    return self.parse(StringIO(text), headersonly=headersonly)
TypeError: initial_value must be str or None, not bytes

trying the same code with python2.7 leads to the desired result but from time to time this kind of error is popping out:

/mnt/volume-fra1-01/arc/2017/3128654e-fa30-40e8-823a-e6e745c7c350KAWGMEHUB01.gme.gbl
MailboxClient.saveEmail() failed
'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

which is probably related to default encoding in python2

I would gladly contribute with a PR but unfortunately, python is not my forte :(

polo2ro commented 6 years ago

Hi, when the PR with python3 support has been merged, i created a python2 branch. for python2 support, you must use that branch. P3 version is actually not production ready, i just pushed today a major fix for this on master branch

mrhyde commented 6 years ago

Great! Thank you for information and your great work. I will give it a try and let you know about the result