首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python: tbird2claws.py问题

Python: tbird2claws.py问题
EN

Stack Overflow用户
提问于 2018-11-30 23:02:46
回答 1查看 91关注 0票数 0

我正在尝试将我的归档消息+文件夹结构从雷鸟迁移到爪子。开发人员(和其他人)建议尝试使用Python tbird2claws.py (“将Mozilla邮箱集成到爪子邮件”)。

但是,我收到以下错误消息:

代码语言:javascript
复制
root@debian:~/.thunderbird/f6tkjcoh.default# python $HOME/Downloads/claws-mail-tbird2claws/tbird2claws.py . ~/Mail
Traceback (most recent call last):
  File "/root/Downloads/claws-mail-tbird2claws/tbird2claws.py", line 130, in <module>
    convert_tree(sys.argv[1], sys.argv[2])
  File "/root/Downloads/claws-mail-tbird2claws/tbird2claws.py", line 124, in convert_tree
    os.path.join(out_treepath,outpath,f))
  File "/root/Downloads/claws-mail-tbird2claws/tbird2claws.py", line 95, in process_file
    offs = harvest_offsets(filepath)
  File "/root/Downloads/claws-mail-tbird2claws/tbird2claws.py", line 63, in harvest_offsets
    for i,line in enumerate(open(filepath)):
IOError: [Errno 2] No such file or directory: './lock'

问题

  1. 这些错误意味着什么?
  2. 如何使这个脚本运行良好?
  3. 还有其他的想法吗?如何将归档消息+文件夹结构从雷鸟迁移到爪子?

tbird2claws.py文件:

代码语言:javascript
复制
#!/usr/bin/python

# Script name : tbird2claws.py
# Script purpose : Integrate a Thunderbird folder tree to Claws Mail
# Author : Aleksandar Urosevic aka Urke MMI <urke@gmx.net>
# Licence : GPL
# Author: Rodrigo Dias Arruda Senra

#The script receives two parameters from command-line:
#<Thunderbird folder path> <Claws Mail folder path>

#Best way to use it is to go to inside yout Thunderbird
#root mailfolder directory and invoke it as:

#<path>\python2.4 <path>\tbird2claws.py . <path to
#claws-mail>\Mail

import os
import sys

__author__ = 'Rodrigo Senra <rsenra@acm.org>'
__date__ =  '2005-03-23'
__version__ =  '0.3'

__doc__ = r"""
This module integrates your Mozilla Thunderbird 1.0 tree to
your Claws Mail MH mailbox tree.

The script receives two parameters from command-line:
 <Thunderbird folder path> <Claws Mail folder path>

Best way to use it is to go to inside yout Thunderbird
root mailfolder directory and invoke it as:

  <path>\python2.4 <path>\tbird2syl.py . <path to claws mail>\Mail

This idiom will avoid the creation of the folder Thunderbird inside
your Claws Mail folder tree.

If the names of your directories match in both trees, files should
be placed in the correct folder.

This is an alpha release, so it may be a little rough around the edges.
Nevertheless, I used it with great success to convert a very large and
deep folder tree.

Please, do backup your claws-mail (destination) folder tree before trying
this out. Live safe and die old!

This code is released in the public domain.
"""

def harvest_offsets(filepath):
    """Given the filepath, this runs through the file finding
    the number of the line where a message begins.

    The functions returns a list of integers corresponding to
    the begining of messages.
    """ 
    offsets = []
    i = 0
    state = 'begin'
    for i,line in enumerate(open(filepath)):
        if line.startswith('From - ') and state!='found_head':
        offsets.append(i)
        continue
#        elif line.startswith('Return-Path') and state=='found_head':
#       state = 'found_offset'
#       offsets.append(i)
#       continue
    offsets.append(i)
    return offsets

def make_messages(outputdir, filepath, offsets, start):
    """Given a filepath holding several messages in Thunderbird format,
    extarct the messages and create individual files for them, inside
    outputdir with appropriate the appropriate naming scheme.
    """ 
    if not os.path.exists(outputdir):
        os.makedirs(outputdir)
    if not os.path.exists(filepath):
        raise Exception('Cannot find message file  %s'%(filepath))
    lines = open(filepath).readlines()
    aux = offsets[:]
    msgoffs = zip(offsets[:-1], aux[1:])
    for i,j in msgoffs:
    fd  = open(os.path.join(outputdir,"%d"%start),"w")
    fd.write(''.join(lines[i:j-1])) #-1 to remove first from line
    fd.close()
    start +=1

def process_file(filepath, outputdir):
    """Integrates a Thunderbird message file into a claws-mail message diretory.
    """  
    offs = harvest_offsets(filepath)
    make_messages(outputdir, filepath, offs, 1)

def clean_path(path):
    """Rename all directories and subdirectories <X>.sbd to <X>
    """
    l = []
    f = os.path.basename(path)
    while f and f != "":
        if f.endswith('.sbd'): 
            f = f[:-4]
        l.append(f)
        path = os.path.dirname(path)
        f = os.path.basename(path)
    l.reverse()
    r = os.path.join(*l)
    return r



def convert_tree(in_treepath, out_treepath):
    """Traverse your thunderbird tree, converting each message file found into
    a claws-mail message directory.
    """
    for path,subs,files in os.walk(in_treepath):
        outpath = clean_path(path)
        if files:
            for f in [x for x in files if not x.endswith('.msf')]:
                process_file(os.path.join(path,f),
                             os.path.join(out_treepath,outpath,f))

if __name__=='__main__':
    if len(sys.argv)<3:
        print __doc__
    else:
        convert_tree(sys.argv[1], sys.argv[2])
EN

回答 1

Stack Overflow用户

发布于 2018-11-30 23:24:57

根据https://github.com/avocado-framework/avocado/issues/818的说法,当您再次运行脚本时,这个问题将自行解决。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53566083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档