rgladwell / imap-upload

Python script for uploading a local mbox file to IMAP4 server.
Other
127 stars 30 forks source link

"-r" option only works where mbox files have extension "mbox" #61

Open Behinder opened 2 years ago

Behinder commented 2 years ago

If I import single file without extension it works however recursive option not work. Thunderbird stores mailboxes on Windows without giving them extension so with large number of mailboxes it can be pain to change them all manually. Is it any way for a program to detect mboxes anyway?

However even with that option script seems to stop after processing first folder

322/322   5.3 kB  Nowe wiadomości w skrzynce       OK (1 sec)
Done. (OK: 322, WARNING: 0, ERROR: 0)
Found mailbox at /Volumes/T5/LocalFolders/Archives/2011.mbox...
Behinder commented 2 years ago

As a suplementary note I discovered that recursive option not work if folders have dot in names. In my case Thunderbird named the folders with ".sbd" extension

rgladwell commented 2 years ago

Hi @Behinder, thanks for the report. Tou might want to raise that second bug as another issue.

Unfortunately, I don't know when I can get around to fixing this. If you have the time, a PR would be gratefully received.

Behinder commented 2 years ago

I don't know if this is really fixable, I noticed that even with retry flag program during recursive tends to stop after importing one or two boxes, I had to delete them and run program again few times to finally import everything. Because --debug flag really does nothing and no error was raised I am not sure if something can be done.

rgladwell commented 2 years ago

Please don't lose hope. There have been a lot of changes in the repository recently. Please let me know if this version of the scripts works better for you:

https://github.com/rgladwell/imap-upload/blob/1d55a745b6ae2533b7d93e0baaa7182448c7b9e4/imap_upload.py

panreyes commented 4 months ago

I've noticed that MBOX files don't have a header or magic bytes, so identifying them without the extension is quite difficult... but a quick solution for uploading Thunderbird MBOX files would be to search for .msf files, and then for their counterparts without extension.

I've made a quick & dirty fix to the script to make it work in my case:

        elif file.endswith(".msf"):
            print("Found mailbox at {}...".format(path))
            mbox = mailbox.mbox(path.replace(".msf",""), create=False)
            if (email_only_folders and has_mixed_content(src)):
                target_box = box + separator + src.split(os.sep)[-1]
            else:
                target_box = file.split('.')[0] if (box is None or box == "") else box
            if err:
                err = mailbox.mbox(err)
            upload(imap, target_box, mbox, err, time_fields)

Now it's detecting those Thunderbird mbox files :)

rgladwell commented 4 months ago

Thanks for posting that. It would be a big help if you raised a PR to include that fragment in the code base.

panreyes commented 4 months ago

Done, thanks for letting me contribute to imap-upload! :)

rgladwell commented 4 months ago

Thank you for contributing. Does https://github.com/rgladwell/imap-upload/pull/66 fix this issue?