Discussion:
Tool to store on IMAP server
(too old to reply)
Nicolas George
2024-07-29 13:40:01 UTC
Permalink
Hi.

I am looking for a tool that reads a mail from its input and stores it
into an IMAP mailbox:

cat mail_file | imapupload imaps://***@server/Mail/incoming

The goal would be to provide our users an alternative to forwarding
their mail to another mail provider that we will have to forbid lest the
other mail providers accuse us of spamming.

I got curl to work (I did not know that curl could do IMAP):

curl --user george --url imaps://server/Mail/testcurl --upload-file /tmp/mail

Unfortunately, curl hardcodes that mail uploaded that way are seen:

/* Send the APPEND command */
result = imap_sendf(data,
"APPEND %s (\\Seen) {%" CURL_FORMAT_CURL_OFF_T "}",
mailbox, data->state.infilesize);

… and I need them to be new.

Alternatively, I have considered using GNU mailutils:

movemail /tmp/mail imaps://***@server/Mail/testcurl

This time, the issue is it insists on finding the password in
~/.mu-tickets without an option to use another file or preferably a
pipe.

Does anybody here have an idea to make all this better?

Thanks in advance,
--
Nicolas George
mick.crane
2024-07-29 14:00:01 UTC
Permalink
Post by Nicolas George
Hi.
I am looking for a tool that reads a mail from its input and stores it
With a new Dovecot install I believe I copied all the old mails into eg.
~/Maidir/cur
and they showed up.
I was concerned the
'1722260402.M755015P70320.xxxxxxxxxx,S=17279,W=17606:2,S'
numbers might get mixed up with new ones but didn't seem to matter.
Probably not how you are supposed to do it.
mick
Nicolas George
2024-07-29 14:10:02 UTC
Permalink
Post by mick.crane
Post by Nicolas George
I am looking for a tool that reads a mail from its input and stores it
With a new Dovecot install
Thanks, but this is not at all what I am asking. Dovecot is the server,
I am asking for a client.
--
Nicolas George
Greg Wooledge
2024-07-29 14:20:01 UTC
Permalink
Post by Nicolas George
Post by mick.crane
Post by Nicolas George
I am looking for a tool that reads a mail from its input and stores it
With a new Dovecot install
Thanks, but this is not at all what I am asking. Dovecot is the server,
I am asking for a client.
https://superuser.com/questions/191719/transferring-lots-of-messages-between-imap-accounts
Nicolas George
2024-07-29 14:30:01 UTC
Permalink
Post by Greg Wooledge
https://superuser.com/questions/191719/transferring-lots-of-messages-between-imap-accounts
Closer, but no:

I want: transfer ONE message to an IMAP account.

This: transfer LOTS OF messages to an IMAP account.

imapsync (actually mbsync) is really good for what it is good at but
much too heavy for the task at hand, it sets up an infrastructure to
check which mail has already been uploaded.

And mutt's behavior is too unpredictable to be used in a non-interactive
way.

Regards,
--
Nicolas George
Nicolas George
2024-07-29 14:40:01 UTC
Permalink
You did not say you wanted to do this NON-INTERACTIVELY.
Yes, I did, in the very first message:

“The goal would be to provide our users an alternative to forwarding
their mail to another mail provider”
Why do you want to do it non-interactively? It's ONE MESSAGE, ONE TIME!
It is ONE message, thousands of time per hour.
Can anyone guess what my next response is going to be? I have a guess.
It will involve the letters X and Y.
Oh, I know where you are going, but apparently you did not read the
first question carefully enough. I expected that from other people on
the list but not you.

Regards,
--
Nicolas George
Greg Wooledge
2024-07-29 14:40:02 UTC
Permalink
Post by Nicolas George
I want: transfer ONE message to an IMAP account.
Then use the mutt solution.
Post by Nicolas George
And mutt's behavior is too unpredictable to be used in a non-interactive
way.
You did not say you wanted to do this NON-INTERACTIVELY.

Why do you want to do it non-interactively? It's ONE MESSAGE, ONE TIME!

Just do it interactively, and you're done. Problem solved.

...

Can anyone guess what my next response is going to be? I have a guess.
It will involve the letters X and Y.
Tim Woodall
2024-07-30 08:30:01 UTC
Permalink
Post by mick.crane
Post by Nicolas George
Hi.
I am looking for a tool that reads a mail from its input and stores it
With a new Dovecot install I believe I copied all the old mails into eg.
~/Maidir/cur
and they showed up.
I was concerned the '1722260402.M755015P70320.xxxxxxxxxx,S=17279,W=17606:2,S'
numbers might get mixed up with new ones but didn't seem to matter.
Probably not how you are supposed to do it.
mick
Yes, I use unison to keep some imap servers in sync. Three servers
receive mail which is then replicated and I've had no problems.

So just adding files should be fine.
Nicolas George
2024-07-30 08:30:01 UTC
Permalink
Post by Tim Woodall
Yes, I use unison to keep some imap servers in sync.
Be precise: you use unison to keep the directories that serve as mail
storage for some IMAP servers in sync. Your unison does not know that
there is IMAP involved.
--
Nicolas George
Tim Woodall
2024-07-30 09:00:01 UTC
Permalink
Post by Nicolas George
Post by Tim Woodall
Yes, I use unison to keep some imap servers in sync.
Be precise: you use unison to keep the directories that serve as mail
storage for some IMAP servers in sync. Your unison does not know that
there is IMAP involved.
Correct. Unison has no idea that it's synching maildirs.

cat inbox-imap17.prf

# Unison preferences file
#

# Roots of the synchronization
root = /home/tim/Maildir/INBOX
root = ssh://imap17//home/tim/Maildir/INBOX

#Name matches anything, including a directory name.
#Path matches anything but is anchored at the root
ignore = Name .lock
ignore = Name {dovecot.*}
ignore = Name {dovecot-*}
ignore = Name {tmp/*}

# Log actions to the terminal
log = true



I've never 'tried' to break it by, for example, performing imap things
on the same email on two servers at once but my guess is I'd end up with
a duplicated email. It's possible I'd get a synch conflict but I've not
had one yet. And I do occasionally use imap on more than one server at
once.

But I'd assume dropping files into the maildir with non-conflicting
names - there might be restricions on how they should be named - would
'just work' at least with dovecot.
Max Nikulin
2024-07-31 02:20:01 UTC
Permalink
Post by Tim Woodall
Post by mick.crane
I was concerned the
'1722260402.M755015P70320.xxxxxxxxxx,S=17279,W=17606:2,S'
numbers might get mixed up with new ones but didn't seem to matter.
[...]
Post by Tim Woodall
Yes, I use unison to keep some imap servers in sync.
Maildir file names include keywords.

I suspect, there is a chance of discrepancy of keyword mapping across
servers unless your perform sync when IMAP servers are stopped and files
containing mapping are copied as well.

https://doc.dovecot.org/admin_manual/mailbox_formats/maildir/

Darac Marjal
2024-07-29 17:40:02 UTC
Permalink
Post by Nicolas George
Hi.
I am looking for a tool that reads a mail from its input and stores it
The goal would be to provide our users an alternative to forwarding
their mail to another mail provider that we will have to forbid lest the
other mail providers accuse us of spamming.
curl --user george --url imaps://server/Mail/testcurl --upload-file /tmp/mail
/* Send the APPEND command */
result = imap_sendf(data,
"APPEND %s (\\Seen) {%" CURL_FORMAT_CURL_OFF_T "}",
mailbox, data->state.infilesize);

 and I need them to be new.
This time, the issue is it insists on finding the password in
~/.mu-tickets without an option to use another file or preferably a
pipe.
Does anybody here have an idea to make all this better?
I can think of a couple of options.

"imapfilter" is a program intended to filter messages on an IMAP server.
The program handles the hard work of talking to an IMAP server (i.e. the
IMAP protocol), allowing the user to write a lua script which does the
important work. It shouldn't be too hard to write a lua script which
reads the message from stdin and then passes it to the imapfilter
functions for storage.

Alternatively, most programming languages offer some form of high-level
imap library. Depending on your predilection, you could write a
Perl/Python/whatever script to do this.
Post by Nicolas George
Thanks in advance,
James Cloos
2024-07-29 19:00:01 UTC
Permalink
NG> I got curl to work (I did not know that curl could do IMAP):

NG> curl --user george --url imaps://server/Mail/testcurl --upload-file /tmp/mail

NG> Unfortunately, curl hardcodes that mail uploaded that way are seen:

NG> /* Send the APPEND command */
NG> result = imap_sendf(data,
NG> "APPEND %s (\\Seen) {%" CURL_FORMAT_CURL_OFF_T "}",
NG> mailbox, data->state.infilesize);

NG> … and I need them to be new.

How about keeping a locally patched version of curl on hand (you could
call it something like /usr/local/bin/imap-upload) which sets the flags
as you want them to be?
--
-JimC
***@jhcloos.com
Nicolas George
2024-07-30 07:20:01 UTC
Permalink
Post by James Cloos
How about keeping a locally patched version of curl on hand (you could
call it something like /usr/local/bin/imap-upload) which sets the flags
as you want them to be?
I did not need to ask for help for the obvious solution “write it
yourself”, be it from scratch or from parts.

Regards,
--
Nicolas George
Loading...