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

Allow to export as maildir #600

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

williamdes
Copy link
Contributor

mkdir ./export-username
cargo run --no-default-features --features maildir --bin stalwart-cli -- --url http://xxxxxxx --credentials xxx:xxxx export account --format maildir [email protected] ./export-username

It works !
Fixes #596

ls -lahR export-username/[email protected]/maildir/
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:31 2024 🗁 .
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:33 2024 🗁 ..
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:31 2024 🗁 cur
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:32 2024 🗁 new
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:32 2024 🗁 tmp

export-username/[email protected]/maildir/cur:
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:31 2024 🗁 .
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:31 2024 🗁 ..

export-username/[email protected]/maildir/new:
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:32 2024 🗁 .
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:31 2024 🗁 ..
.rw-r--r-- williamdes williamdes  91 KB Sun Jul  7 15:57:32 2024 🗋 1720360652.#0M108962097P802225V64770I6100747.williamdes,S=93289
.rw-r--r-- williamdes williamdes  58 KB Sun Jul  7 15:57:32 2024 🗋 1720360652.#1M292000374P802225V64770I6100749.williamdes,S=59110
.rw-r--r-- williamdes williamdes  50 KB Sun Jul  7 15:57:32 2024 🗋 1720360652.#2M524520825P802225V64770I6100750.williamdes,S=51553
.rw-r--r-- williamdes williamdes 231 KB Sun Jul  7 15:57:32 2024 🗋 1720360652.#3M797068180P802225V64770I6100751.williamdes,S=236812
.rw-r--r-- williamdes williamdes  45 KB Sun Jul  7 15:57:32 2024 🗋 1720360652.#4M987264110P802225V64770I6100752.williamdes,S=45833

export-username/[email protected]/maildir/tmp:
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:32 2024 🗁 .
drwxr-xr-x williamdes williamdes 4.0 KB Sun Jul  7 15:57:31 2024 🗁 ..

This PR is not prefect, but at least it works.
Feel free to do what you want about it, I can apply suggestions.

@mdecimus
Copy link
Member

mdecimus commented Jul 8, 2024

Thank you for the PR. There are two items missing in the implementation:

  • Do not export blobs to Maildir that are linked to Sieve scripts.
  • Export the folder structure as well and place each message in their respective folder.

@williamdes
Copy link
Contributor Author

Do not export blobs to Maildir that are linked to Sieve scripts.

They do not, as it foreach emails
Did I get something wrong ?

Export the folder structure as well and place each message in their respective folder.

Yes, can you guide me on how to access the folder structure ?

@mdecimus
Copy link
Member

mdecimus commented Jul 8, 2024

Yes, can you guide me on how to access the folder structure ?

You can experiment with the fetch_mailboxes function. Each mailbox has as an id and a parentId so you need to replicate this structure on Maildir (I've never used the maildir crate but I'm sure they support nested folder creation). Then each email has the mailboxIds it belongs to.

@williamdes
Copy link
Contributor Author

Yes, can you guide me on how to access the folder structure ?

You can experiment with the fetch_mailboxes function. Each mailbox has as an id and a parentId so you need to replicate this structure on Maildir (I've never used the maildir crate but I'm sure they support nested folder creation). Then each email has the mailboxIds it belongs to.

And can the names be fetched or ids are names?

@mdecimus
Copy link
Member

And can the names be fetched or ids are names?

Yes, the names are also returned by fetch_mailboxes. You need to keep track of the folder ids also so you know where to write the message to in the maildir.

@williamdes

This comment was marked as resolved.

@williamdes williamdes marked this pull request as draft July 31, 2024 16:43
@williamdes
Copy link
Contributor Author

it handles folder now (in a simple way), but still needs https://todo.sr.ht/~kmaasrud/maildirpp/1 to have working set_id calls

How can I build to string the folder name with all it's parents ?
Like: Inbox.folder1.subfolder1
is there an existing method in the project ?

@mdecimus
Copy link
Member

mdecimus commented Aug 9, 2024

How can I build to string the folder name with all it's parents ?
Like: Inbox.folder1.subfolder1
is there an existing method in the project ?

The IMAP server code does something similar to that but perhaps its easier to write the logic from scratch.

@williamdes
Copy link
Contributor Author

How can I build to string the folder name with all it's parents ?
Like: Inbox.folder1.subfolder1
is there an existing method in the project ?

The IMAP server code does something similar to that but perhaps its easier to write the logic from scratch.

Well, I honestly do not know how to write this algorithm :/
Can you point me out to some existing code so I can understand how to write it myself?

@mdecimus
Copy link
Member

Can you point me out to some existing code so I can understand how to write it myself?

Here:

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

Successfully merging this pull request may close these issues.

[enhancement]: CLI allow to export in the mbox/maildir format
2 participants