10

ホストを変更したため、古いサーバーの maildir アカウントを新しいサーバーの mbox に変換する必要があります。

これを行うための最良の方法に関するアイデアはありますか?

私はこれを見つけました:

for i in new/* cur/*;do formail <”$i” >> ../mbox;done

しかし、私は本当にそれを理解していません。Linux の基本的な知識があり、ssh 経由でサーバーにルート アクセスできます。

ほとんどの Maildir フォルダーには、次の内容があります。


cur
new
tmp
dovecot.index.log
dovecot-uidlist
dovecot.index
dovecot.index.log.2
dovecot.index.cache
dovecot-keywords
サブスクリプション


そのすべてが必要ですか、それとも dovecot ファイルを無視できますか?

アドバイスをいただければ幸いです。

4

2 に答える 2

29

メールサーバーを設定せずに maildir アカウントをメールボックス アカウントに変換する必要がある場合は、python のメールボックス ライブラリを使用できます。変換する maildir フォルダーが 1 つしかない場合は、ここにある小さな (10 行 + コメント) python スクリプトを使用できます。サブフォルダーがある場合は、2 つの形式で異なるサブフォルダー構造を調べる必要があります。これにより、次のスクリプトが得られます。

#!/usr/bin/env python 
# -*- coding: utf-8 -*-
"""
Frédéric Grosshans, 19 January 2012
Nathan R. Yergler, 6 June 2010

This file does not contain sufficient creative expression to invoke
assertion of copyright. No warranty is expressed or implied; use at
your own risk.

---

Uses Python's included mailbox library to convert mail archives from
maildir [http://en.wikipedia.org/wiki/Maildir] to 
mbox [http://en.wikipedia.org/wiki/Mbox] format, icluding subfolder.

See http://docs.python.org/library/mailbox.html#mailbox.Mailbox for 
full documentation on this library.

---

To run, save as md2mb.py and run:

$ python md2mb.py [maildir_path] [mbox_filename]

[maildir_path] should be the the path to the actual maildir (containing new, 
cur, tmp, and the subfolders, which are hidden directories with names like 
.subfolde.subsubfolder.subsubsbfolder);

[mbox_filename] will be newly created, as well as a [mbox_filename].sbd the 
directory.
"""

import mailbox
import sys
import email
import os

def maildir2mailbox(maildirname, mboxfilename):
    """
    slightly adapted from maildir2mbox.py, 
    Nathan R. Yergler, 6 June 2010
    http://yergler.net/blog/2010/06/06/batteries-included-or-maildir-to-mbox-again/


    """
    # open the existing maildir and the target mbox file
    maildir = mailbox.Maildir(maildirname, email.message_from_file)
    mbox = mailbox.mbox(mboxfilename)

    # lock the mbox
    mbox.lock()

    # iterate over messages in the maildir and add to the mbox
    for msg in maildir:
        mbox.add(msg)

    # close and unlock
    mbox.close()
    maildir.close()

#Creates the main mailbox
dirname=sys.argv[-2]
mboxname=sys.argv[-1]
print(dirname +' -> ' +mboxname)
mboxdirname=mboxname+'.sbd'
maildir2mailbox(dirname,mboxname)
if not os.path.exists(mboxdirname): os.makedirs(mboxdirname)

listofdirs=[dn for dn in os.walk(dirname).next()[1] if dn not in ['new', 'cur', 'tmp']]
for curfold in listofdirs:
    curlist=[mboxname]+curfold.split('.')
    curpath=os.path.join(*[dn+'.sbd' for dn in curlist if dn])
    if not os.path.exists(curpath): os.makedirs(curpath)
    print('| ' +curfold +' -> '+curpath[:-4])
    maildir2mailbox(os.path.join(dirname,curfold),curpath[:-4])

print('Done')
于 2012-01-19T17:01:22.193 に答える
4

imap 経由で両方のサーバーにアクセスできる (または一時的に配置できる) 場合は、imapsync ツールの使用を検討することをお勧めします。

http://freshmeat.net/projects/imapsync/

それがうまくいかない場合は、dovecot ファイルを無視できるはずですが、どのメッセージが読み取られたか、メッセージに設定されたフラグなどの情報が失われる可能性があることに注意してください。( imapsync メソッドは、これらすべてのものを保存します。)

于 2010-03-25T06:21:41.803 に答える