auino / mail-attachments-archiver

Store mail attachments to file-system
14 stars 7 forks source link

It seems that the script don't run with python >= 3 #2

Open Gitsaibot opened 2 years ago

Gitsaibot commented 2 years ago

Get errors like this:

    print "<"+str(mail['date'])+"> "+"["+str(mail['from'])+"] :"+str(mail['subject'])
          ^
*SyntaxError: invalid syntax*

First error solved with print(...)


Traceback (most recent call last):
  File "/home/tobias/ExtractMailAttachment.py", line 80, in <module>
    mail = email.message_from_string(email_body)
  File "/usr/lib/python3.9/email/__init__.py", line 38, in message_from_string
    return Parser(*args, **kws).parsestr(s)
  File "/usr/lib/python3.9/email/parser.py", line 67, in parsestr
    return self.parse(StringIO(text), headersonly=headersonly)
*TypeError: initial_value must be str or None, not bytes*

Here I need help...

auino commented 2 years ago

I confirm that it depends on the Python version used: the program works on python2. Hence, in your case, it is needed to port it to python3. Particularly, python3 embeds the imaplib library (see https://www.devdungeon.com/content/read-and-send-email-python), hence, the best porting would make use of such library, instead of the email one.