Skip to content

Commit

Permalink
Merge pull request #50 from JanST123/fix_icloud
Browse files Browse the repository at this point in the history
fix a bug that occured for icloud mail
  • Loading branch information
rcarmo authored Jun 18, 2024
2 parents 7cccc9d + bc4bcb2 commit a7fe1a8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions imapbackup38.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def string_from_file(value):
return content.read().strip()


def download_messages(server, filename, messages, overwrite, nospinner, thunderbird, basedir):
def download_messages(server, filename, messages, overwrite, nospinner, thunderbird, basedir, icloud):
"""Download messages from folder and append to mailbox"""

fullname = os.path.join(basedir,filename)
Expand Down Expand Up @@ -176,9 +176,12 @@ def download_messages(server, filename, messages, overwrite, nospinner, thunderb

# fetch message
msg_id_str = str(messages[msg_id])
typ, data = server.fetch(msg_id_str, "(RFC822)")
typ, data = server.fetch(msg_id_str, "(BODY.PEEK[])" if icloud else "(RFC822)")


assert('OK' == typ)
data_bytes = data[0][1]

text_bytes = data_bytes.strip().replace(b'\r', b'')
if thunderbird:
# This avoids Thunderbird mistaking a line starting "From " as the start
Expand Down Expand Up @@ -433,6 +436,7 @@ def print_usage():
print (" -t SECS --timeout=SECS Sets socket timeout to SECS seconds.")
print (" --thunderbird Create Mozilla Thunderbird compatible mailbox")
print (" --nospinner Disable spinner (makes output log-friendly)")
print (" --icloud Enable iCloud compatibility mode (for iCloud mailserver)")
sys.exit(2)


Expand All @@ -443,15 +447,15 @@ def process_cline():
short_args = "aynekt:c:s:u:p:f:d:"
long_args = ["append-to-mboxes", "yes-overwrite-mboxes",
"ssl", "timeout", "keyfile=", "certfile=", "server=", "user=", "pass=",
"folders=", "exclude-folders=", "thunderbird", "nospinner", "mbox-dir="]
"folders=", "exclude-folders=", "thunderbird", "nospinner", "mbox-dir=", "icloud"]
opts, extraargs = getopt.getopt(sys.argv[1:], short_args, long_args)
except getopt.GetoptError:
print_usage()

warnings = []
config = {'overwrite': False, 'usessl': False,
'thunderbird': False, 'nospinner': False,
'basedir': "."}
'basedir': ".", 'icloud': False}
errors = []

# empty command line
Expand Down Expand Up @@ -492,6 +496,8 @@ def process_cline():
config['thunderbird'] = True
elif option == "--nospinner":
config['nospinner'] = True
elif option == "--icloud":
config['icloud'] = True
else:
errors.append("Unknown option: " + option)

Expand Down Expand Up @@ -711,7 +717,7 @@ def main():
# for f in new_messages:
# print "%s : %s" % (f, new_messages[f])

download_messages(server, filename, new_messages, config['overwrite'], config['nospinner'], config['thunderbird'], basedir)
download_messages(server, filename, new_messages, config['overwrite'], config['nospinner'], config['thunderbird'], basedir, config['icloud'])

except SkipFolderException as e:
print (e)
Expand Down

0 comments on commit a7fe1a8

Please sign in to comment.