转换Maildir到mbox
题
Im改变主机,我要把我的maildir账户在我的旧服务器mbox在我的新服务器。
任何想法的最佳方式做到这一点?
我发现了这个:
我在新的/*cur/*;做formail <"$i">>../mbox;做
但我并不真正理解它。我有一个基本知识的linux和我根访问以我的服务器通过ssh。
大多数Maildir文件夹中都有以下内容:
cur
新的
tmp
鸽舍.索引。日志
鸽舍-uidlist
鸽舍.索引
鸽舍.索引。日志。2
鸽舍.索引。高速缓存
鸽舍-关键词
订阅
我需要所有那或者我可以忽略的鸽舍的文件?
任何意见将是极大的赞赏。
C
解决方案
如果你有机会获得通过IMAP两台服务器(或可暂时安排吧),你可能要考虑使用imapsync工具,例如:
http://freshmeat.net/projects/imapsync/
如果这是行不通的,你应该能够忽略dovecot的文件,但要小心,你很可能会丢失信息等,其信息读取和任何标志上的信息设置。 (该方法imapsync将保持所有这些事情。)
其他提示
如果需要转换maildir账户转入一个邮箱帐户没有设定邮件服务器,可以使用的邮箱图书馆的蟒蛇。如果一个人有一个单一的maildir文件夹转换,一个可以使用这个小(10+意见)python脚本中发现了 在这里,.如果一个人有子文件夹中,一个需要探讨电子文件夹结构,该结构是不同的,两者之间格式。这给出了以下脚本:
#!/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')
不隶属于 StackOverflow