Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import-mailbox-to-gmail.py: error: argument --dir is required #34

Closed
jwebbstevens opened this issue Jan 18, 2018 · 12 comments
Closed

import-mailbox-to-gmail.py: error: argument --dir is required #34

jwebbstevens opened this issue Jan 18, 2018 · 12 comments
Assignees

Comments

@jwebbstevens
Copy link

I get an error message running the test that I setup for this.

import-mailbox-to-gmail.py: error: argument --dir is required

Is this the directory of the mbox or the directory of the python script?

@PMox
Copy link
Contributor

PMox commented Jan 18, 2018

When in doubt, you can run the script with --help to see the meaning of the various options.

The meaning of --dir is: "Path to the directory that contains user directories with mbox files to import"

@jwebbstevens
Copy link
Author

Thanks @PMox that is very helpful. Perhaps it's something with how apple mail handled the Export process of the mbox?

I'm pretty sure my file path is accurate since the script is running, the target mbox appers to throw the script off.

When I exported the mbox from Apple mail (i used the trash folder which had only one email in it for testing purposes) this is how I structured the file path. I kept the script and the target folder for the mbox in the same folder on the desktop.

python /Users/computer/Desktop/import-mailbox/import-mailbox-to-gmail.py --json /Users/computer /Desktop/import-mailbox/Gmail API-87b47b451bb4.json -- dir /Users/computer/Desktop/import-mailbox/mbox

I noticed the Apple Mail exporter created a [GMAIL] folder inbetween the email address and the actual mbox file. Does that matter?

so the mbox folder looks like

/mbox
/mbox/[email protected]
/mbox/[email protected]/[GMAIL]
/mbox/[email protected]/[GMAIL]/imported messages.mbox.

I noticed the instructions don't call for that middle folder but if I remove it and put the mbox right in the [email protected] folder I still get that dir error.

I think I'm structuring something wrong.

@jwebbstevens
Copy link
Author

Ugh...I'm an idiot I had an extra space between -- and dir

@jwebbstevens
Copy link
Author

jwebbstevens commented Jan 18, 2018

it worked. i also learned Google reserves the word trash. So had to rename to a different label. this is pretty slick. thank you all for creating/contributing to this.

@eesheesh
Copy link
Collaborator

IIRC you should be able to import a file named 'Trash.mbox' and it will get imported to the 'Trash' label. If you like, please post the exact folder structure and file name you had with Trash that failed to be imported in a new issue, and I'll see if I can fix it.

Thanks for the help @PMox. :)

@jwebbstevens
Copy link
Author

Here's the file structure I used....

mbox
mbox/[email protected]
mbox/[email protected]/Trash.mbox

and then within that mbox are two files mbox and table_of_contents respectively.

This is exported from Apple mail running on the latest Apple OS.

This is the ERROR message I get

13:29:20 ERROR [email protected] Can't create label 'Trash' for user [email protected]
Traceback (most recent call last):
File "/Users/computer/Desktop/import-mailbox/import-mailbox-to-gmail.py", line 153, in get_label_id_from_name
body=label_object).execute(num_retries=args.num_retries)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/googleapiclient/http.py", line 844, in execute
raise HttpError(resp, content, uri=self.uri)
HttpError: <HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/[email protected]/labels?alt=json returned "Invalid label name">
13:29:20 ERROR [email protected] Skipping label 'Trash' because it can't be created'

email and device name changed for privacy purposes. i think i can run a deeper debug so if that provides more information and helps i will.

Also I have the Trash label in Gmail set to hide but it is checked off to show in IMAP.

Does show/hide impact the ability to import to that specific label? Now that I think of it that might be it.

@jwebbstevens
Copy link
Author

I tried to show the "Trash" label in Gmail and it still Errored. Same error listed above.

@jwebbstevens jwebbstevens reopened this Jan 19, 2018
eesheesh added a commit that referenced this issue Jan 24, 2018
@eesheesh
Copy link
Collaborator

I think I found the issue - can you try to download the new version of the script and see if importing a file called "Trash.mbox" works now?

Thanks!

@eesheesh eesheesh self-assigned this Jan 24, 2018
@jwebbstevens
Copy link
Author

I gave this a shot thanks. But it didn't work. I downloaded the new version of the script moved some messages that were not imported in previous runs to Trash in Apple Mail.

Used Apple Mail to Export the mailbox to an .mbox. Opened the mbox file in a text editor and confirmed that one of the messages not previously imported is in the .mbox file.

I then ran the new script with debug level four. Here's the result....

`13:39:50 INFO main @import-mailbox-to-gmail.py *** Starting import-mailbox-to-gmail 1.4 on Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] ***
13:39:50 INFO main @import-mailbox-to-gmail.py Arguments:
13:39:50 INFO main @import-mailbox-to-gmail.py auth_host_name: 'localhost'
13:39:50 INFO main @import-mailbox-to-gmail.py auth_host_port: [8080, 8090]
13:39:50 INFO main @import-mailbox-to-gmail.py dir: '/Users/macbook/Desktop/import-mailbox/mbox/email @email.com/Trash.mbox'
13:39:50 INFO main @import-mailbox-to-gmail.py fix_msgid: True
13:39:50 INFO main @import-mailbox-to-gmail.py from_message: 0
13:39:50 INFO main @import-mailbox-to-gmail.py httplib2debuglevel: 4
13:39:50 INFO main @import-mailbox-to-gmail.py json: '/Users/macbook/Desktop/import-mailbox/ JSON'
13:39:50 INFO main @import-mailbox-to-gmail.py log: 'import-mailbox-to-gmail-78454.log'
13:39:50 INFO main @import-mailbox-to-gmail.py logging_level: 'INFO'
13:39:50 INFO main @import-mailbox-to-gmail.py noauth_local_webserver: False
13:39:50 INFO main @import-mailbox-to-gmail.py num_retries: 10
13:39:50 INFO main @import-mailbox-to-gmail.py replace_quoted_printable: True
13:39:50 INFO main @import-mailbox-to-gmail.py *** Done importing all users from directory '/Users/macbook/Desktop/import-mailbox/mbox/[email protected]/Trash.mbox'
13:39:50 INFO main @import-mailbox-to-gmail.py *** Import summary:
13:39:50 INFO main @import-mailbox-to-gmail.py 0 users imported with no failures
13:39:50 INFO main @import-mailbox-to-gmail.py 0 users imported with some failures
13:39:50 INFO main @import-mailbox-to-gmail.py 0 users failed
13:39:50 INFO main @import-mailbox-to-gmail.py 0 labels (mbox files) imported with no failures
13:39:50 INFO main @import-mailbox-to-gmail.py 0 labels (mbox files) imported with some failures
13:39:50 INFO main @import-mailbox-to-gmail.py 0 labels (mbox files) failed
13:39:50 INFO main @import-mailbox-to-gmail.py 0 messages imported successfully
13:39:50 INFO main @import-mailbox-to-gmail.py 0 messages failed

13:39:50 INFO main @import-mailbox-to-gmail.py Finished.`

I modified the data above to retain privacy but the above is essentially the log

Unfortunately with the latest build zero message was imported into the Trash label for Gmail (that is the native Trash label in Gmail, not one I created)

@eesheesh
Copy link
Collaborator

As far as I can tell, the issue in this case is that you used --dir /Users/macbook/Desktop/import-mailbox/mbox/email @email.com/Trash.mbox and it should just have been --dir /Users/macbook/Desktop/import-mailbox/mbox.

The way you had it, the directory structure should be something like /Users/macbook/Desktop/import-mailbox/mbox/[email protected]/Trash.mbox/[email protected]/Trash.mbox. :)

@jwebbstevens
Copy link
Author

Thanks. I fixed my folder structure and it worked. The script found the messages and threw them in the Gmail Trash label. Problem solved (still stuck with Apple Mail Export Mailbox on Attachments though.) I have to send them another disk image. Other users are reporting it on the Apple Forums so it's not just me and must be something with High Sierra's latest build of Apple Mail 😞

@eesheesh
Copy link
Collaborator

Excellent, thanks for confirming!

ryan-taylor pushed a commit to ryan-taylor/mbox-to-google-workspace that referenced this issue Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants