migrate older e-mails to local mailbox

23 views
Skip to first unread message

Tamas Papp

unread,
Nov 25, 2025, 3:20:08 AM11/25/25
to mu-discuss
Hi,

Gmail is bugging me about my mailbox getting full. I thought I would
migrate older (eg pre-2020) emails to a local mailbox (of course backed
up), and have mu index that too.

What would be the best way to do this (the migration, not the indexing;
I know how to do the latter ;-)). Is there a script I can use?

best

Tamas

Alberto Luaces

unread,
Nov 25, 2025, 9:02:11 AM11/25/25
to mu-discuss
From the very mu4e, I move those emails to a new mailbox folder (created on the
fly if needed, if I recall correctly) that is not synced.

You can test it with just one message, copying it first.

Tamas Papp

unread,
Nov 25, 2025, 9:13:07 AM11/25/25
to Alberto Luaces, mu-discuss
On Tue, Nov 25 2025, Alberto Luaces wrote:
Thanks, but I was hoping for a more automated solution (talking about
30k messages). Eg search for all messages before a given date in
mailbox, move them to a given folder.

best

Tamas

Alberto Luaces

unread,
Nov 25, 2025, 11:32:59 AM11/25/25
to mu-discuss
Yes, that's what I'm suggesting. You search them, you mark them, you
move them.

I only wrote about a simple test before you move those 30k messages.

Tamas Papp

unread,
Apr 2, 2026, 9:40:17 AMApr 2
to mu-discuss
Currently I am doing the following:

1. search for a particular year, eg with the query


2. mark all messages by pressing '*' (I could not find a way to
something-mark all messages in a query, is there one?)

3. e'x'ecuting the mark, and then specifying 'm' and the target folder.

If I create the target folder in my maildir, is it automatically
indexed? (that seems to be the case after moving).

Is there a way to make this more efficient, especially (2)?

Thanks,

Tamás

Dirk-Jan C. Binnema

unread,
Apr 5, 2026, 7:51:29 AMApr 5
to mu-di...@googlegroups.com
Hi Tamas,

On Thursday Apr 02 2026, Tamas Papp wrote:

> Currently I am doing the following:
>
> 1. search for a particular year, eg with the query
>
> 2. mark all messages by pressing '*' (I could not find a way to
> something-mark all messages in a query, is there one?)
>
> 3. e'x'ecuting the mark, and then specifying 'm' and the target folder.
>
> If I create the target folder in my maildir, is it automatically
> indexed? (that seems to be the case after moving).
>
> Is there a way to make this more efficient, especially (2)?

I think batch operations are best done outside mu4e; perhaps something
like the following to move all messages from 2010 to the archive folder

$ mu find date:2010..2010 --exec 'echo' | \
xargs -I {} echo "mu move {} /archive"

(this ^^ just echoes, use to test first...).

'mu move' also updates the index.

Kind regards,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
gpg: 6987 9CED 1745 9375 0F14 DA98 11DD FEA9 DCC4 A036

Tamas Papp

unread,
Apr 20, 2026, 10:42:19 AMApr 20
to mu-di...@googlegroups.com
On Sun, Apr 05 2026, Dirk-Jan C. Binnema wrote:

> Hi Tamas,
>
> On Thursday Apr 02 2026, Tamas Papp wrote:
>
>> Currently I am doing the following:
>>
>> 1. search for a particular year, eg with the query
>>
>> 2. mark all messages by pressing '*' (I could not find a way to
>> something-mark all messages in a query, is there one?)
>>
>> 3. e'x'ecuting the mark, and then specifying 'm' and the target folder.
>>
>> If I create the target folder in my maildir, is it automatically
>> indexed? (that seems to be the case after moving).
>>
>> Is there a way to make this more efficient, especially (2)?
>
> I think batch operations are best done outside mu4e; perhaps something
> like the following to move all messages from 2010 to the archive folder
>
> $ mu find date:2010..2010 --exec 'echo' | \
> xargs -I {} echo "mu move {} /archive"
>
> (this ^^ just echoes, use to test first...).
>
> 'mu move' also updates the index.

Hi Dirk,

Thanks, this works splendidly on the local folders, but does not remove
the messages from my Gmail account.

Does mu move work the same way as deleting messages? (This question
betrays my lack of understanding about the intricaties of IMAP, sorry).

best

Tamás

Dirk-Jan C. Binnema

unread,
Apr 20, 2026, 2:54:09 PMApr 20
to mu-di...@googlegroups.com
mu only knows about your local Maildir. How this Maildir is synchronized
(or not) with a remote mail-server depends on the intricacies of the
program you use for that... offlineimap or mbsync etc.

So best study the program you are using for that a bit, or ask here if
you have more details. Can't help you much (I don't use those programs)
except for remembering that with mbsync the '--change-name' option (for
'mu move') / mu4e-change-filenames-when-moving can be useful

[ I use good-old fetchmail, which just downloads
the messages and makes no attempt at synchronization; which is fine
for me ]

Good luck!

Tamas Papp

unread,
Apr 21, 2026, 3:11:24 AMApr 21
to mu-di...@googlegroups.com
On Mon, Apr 20 2026, Dirk-Jan C. Binnema wrote:

> mu only knows about your local Maildir. How this Maildir is synchronized
> (or not) with a remote mail-server depends on the intricacies of the
> program you use for that... offlineimap or mbsync etc.
>
> So best study the program you are using for that a bit, or ask here if
> you have more details. Can't help you much (I don't use those programs)
> except for remembering that with mbsync the '--change-name' option (for
> 'mu move') / mu4e-change-filenames-when-moving can be useful

I am using mbsync, but I am moving (with mu move) to a folder that is
_not_ managed by mbsync. I thought, perhaps naively, that when mu move
moves those messages, that would be equivalent to deleting them as far
as mbsync is concerned, and it would propagate the changes back to the
server.

I attach the relevant portion of my isyncrc in case anyone has a
suggestion.

best

Tamas
isyncrc

Tamas Papp

unread,
Apr 23, 2026, 4:10:13 AMApr 23
to mu-di...@googlegroups.com
Hi Dirk,

I have been reading the IMAP protocol (RFC 9051) and the mu sources,
just to make sure I am doing what I am supposed to be doing.

My understanding is that mu move ultimately calls Store::move_message,
which, after some sanity checks, simply moves _the file_. Is that
correct?

If yes, maybe isync does not know that the message was moved (since the
file disappears), so that should be communicated differently, eg I am
wondering if it would be better to

1. first copy the message to the new destination,

2. mark it as (mu4e-headers-mark-for-delete), if that can be done with
the command line (how?)

Does this make sense?

Best,

Tamás

Dirk-Jan C. Binnema

unread,
Apr 26, 2026, 2:52:22 AMApr 26
to mu-di...@googlegroups.com
I don't use isync, so cannot give much help here. I do know it can get
confused a bit. The --change-name option (as explained above) may help,
and you can update flags as desired (with --flags)

mark-for-delete really *deletes* the message; maybe trashing is better.

One common confusion is that the Maildir 'T' flag ("mark for manual
deletion later") is (mis)interpreted by some tools (isync perhaps?) as
"mark for automatic deletion". (see 'mu4e-trash-without-flag')

So, I'd recommend some experimentation, and please report back with your
findings!

Kind regards,

Luke Newman

unread,
Apr 26, 2026, 6:22:24 AMApr 26
to mu-di...@googlegroups.com
Hi Tamas, Dirk

I believe I am doing something similar to what Tamas wants. I have
"INBOX", "Done" and "Sent" folders in the local maildir and these are
synchronized, along with some others, with the remote IMAPS server
using mbsync/isync. I also have a local "Archive" folder and this is
*not* synchronized with the IMAP server.

Periodically, using mu4e, I move older messages from the local "Done"
and "Sent" folders to the local "Archive" folder. On next synchronizing
with the IMAP server, these messages are effectively deleted from the
remote "Done" and "Sent" folders. This cuts down the amount of storage
that I need on the IMAP server, but does of course mean that I am wholly
responsible for backing-up messages in the local "Archive" folder.

I believe the key setting in my mu4e configuration is indeed

(setq mu4e-change-filenames-when-moving t)

If I understand correctly, this effectively "deletes" a message UID from
the local "Done" or "Sent" folder and creates a new one in the "Archive"
folder. Then

Expunge Both

in my .mbsyncrc file propagates the deletion to the IMAP server.

I must stress that YMMV. I am lucky in that the IMAP server provided by
my ISP is entirely "well-behaved", unlike some out there. I also tested
things extensively before invoking the "Expunge Both" command.

HTH

Luke
Reply all
Reply to author
Forward
0 new messages