使用offlineimap时出错:getfolder()请求不存在的文件夹

2 投票
1 回答
1981 浏览
提问于 2025-04-18 03:11

我想通过命令行用mutt来收发邮件。我一直在尝试跟着这两个指南:http://blog.developwithpassion.com/2013/05/02/getting-up-and-running-with-a-sane-mutt-setup/http://stevelosh.com/blog/2012/10/the-homely-mutt/#configuring-offlineimap

为了做到这一点,主要有四个步骤: 1. 设置offlineimap来下载并保持邮件同步 2. 设置mutt(邮件用户界面) 3. 设置notmuch(以便能够搜索邮件) 4. 设置msmtp(以便能够发送邮件)

需要注意的是,我使用的是运行OS X 10.9.2的Macbook Pro。我在第一步遇到了麻烦,因为offlineimap出现了错误!我可以长时间运行offlineimap,也就是说,它会同步所有邮件(总共有36197封!),但就在最后,它会抛出以下错误:

ERROR: getfolder() asked for a nonexisting folder 'Drafts'.

Folder Deleted Items [acc: gloriphobia]:

Establishing connection to imap.gmail.com:993

Account sync gloriphobia:

 *** Finished account 'gloriphobia' in 137:16

ERROR: Exceptions occurred during the run!

ERROR: command: UID => socket error: <class 'socket.error'> - [Errno 54] Connection reset by peer


Traceback:

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/folder/IMAP.py", line 219, in getmessage
'(BODY.PEEK[])')

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/imaplib2.py", line 1167, in uid

    return self._simple_command('UID', command, *args, **kw)

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/imaplib2.py", line 1615, in _simple_command
return self._command_complete(self._command(name, *args), kw)

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/imaplib2.py", line 1378, in _command_complete
typ, dat = rqb.get_response('command: %s => %%s' % rqb.name)

 File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/imaplib2.py", line 176, in get_response
raise typ(exc_fmt % str(val))


ERROR: getfolder() asked for a nonexisting folder 'Drafts'.


Traceback:

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/accounts.py", line 241, in syncrunner
self.sync()

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/accounts.py", line 320, in sync
localfolder = self.get_local_folder(remotefolder)

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/accounts.py", line 269, in get_local_folder
replace(self.remoterepos.getsep(), self.localrepos.getsep()))

  File "/usr/local/Cellar/offline-imap/6.5.5/libexec/offlineimap/repository/Maildir.py", line 134, in getfolder
OfflineImapError.ERROR.FOLDER)

我的.offlineimaprc文件是:

[general]
accounts = gloriphobia
ui = TTYUI
pythonfile=~/Development/MuttMailPython/offline.py
fsync = False

[Account gloriphobia]
localrepository = gloriphobia_local
remoterepository = gloriphobia_remote
status_backend = sqlite
postsynchook = notmuch new

[Repository gloriphobia_local]
type = Maildir
localfolders = ~/.mail/Test
nametrans = get_remote_name

[Repository gloriphobia_remote]
maxconnections = 1
type = Gmail
cert_fingerprint = 89091347184d41768bfc0da9fad94bfe882dd358
remoteuser = myemailaddress
remotepasseval = get_keychain_pass(account="myemailaddress",server="imap.gmail.com")
realdelete = no
nametrans = get_local_name
folderfilter = is_included

我的python文件,叫做offline.py,是:

#!/usr/bin/python
import subprocess
import re    

class NameMapping:
  def __init__(self, local_name, remote_name):
    self.local_name = local_name
    self.remote_name = remote_name    

class LocalName:
  def __init__(self, folder):
    self.folder = folder    

  def matches(self, mapping):
    return mapping.remote_name == self.folder    

  def mapped_folder_name(self, mapping):
    return mapping.local_name    

class RemoteName:
  def __init__(self, folder):
    self.folder = folder    

  def matches(self, mapping):
    return mapping.local_name == self.folder    

  def mapped_folder_name(self, mapping):
    return mapping.remote_name    

def get_keychain_pass(account=None, server=None):
  params = {
      'security': '/usr/bin/security',
      'command': 'find-internet-password',
      'account': account,
      'server': server,
      'keychain': '/Users/mec07/Library/Keychains/login.keychain',
  }
  command = "sudo -u mec07 %(security)s -v %(command)s -g -a %(account)s -s %(server)s %(keychain)s" % params
  output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
  outtext = [l for l in output.splitlines()
             if l.startswith('password: ')][0]    

  return re.match(r'password: "(.*)"', outtext).group(1)    

def is_included(folder):
  result = True    

  for pattern in exclusion_patterns:
    result = result and (re.search(pattern, folder) == None)    

  return result    

exclusion_patterns = [
  "efax",
  "earth_class_mail",
  "eventbrite",
  "gotomeeting",
  "moshi_monsters",
  "peepcode",
  "raini_fowl",
  "stuart_know",
  "training.*2008",
  "training.*2009",
  "training.*2010",
  "training.*2011",
  "training.*2012",
  "training.*nbdn",
  "training.*nothin_but_bdd",
  "unblock_us",
  "web_hosting",
  "webinars",
  "Gmail.*Important"
]    

name_mappings = [
  NameMapping('inbox', '[Gmail]/Inbox'),
  NameMapping('starred', '[Gmail]/Starred'),
  NameMapping('important', '[Gmail]/Important'),
  NameMapping('sent', '[Gmail]/Sent Mail'),
  NameMapping('drafts', '[Gmail]/Drafts'),
  NameMapping('archive', '[Gmail]/All Mail'),
  NameMapping('spam', '[Gmail]/Spam'),
  NameMapping('flagged', '[Gmail]/Starred'),
  NameMapping('trash',   '[Gmail]/Trash'),
  NameMapping('deleted', '[Gmail]/Deleted Items'),
  NameMapping('Mum', '[Gmail]/Jana'),
  NameMapping('Maggie', '[Gmail]/Maggie'),
  NameMapping('papers', '[Gmail]/Scholar Alert'),
  NameMapping('sent items', '[Gmail]/Sent Items'),
  NameMapping('sent messages', '[Gmail]/Sent Messages')
]    



def find_name_mapping(name):
  default_mapping = NameMapping(name.folder, name.folder)    

  for mapping in name_mappings:
    if (name.matches(mapping)):
      return mapping    

  return default_mapping    

def get_name_mapping(name):
  mapping = find_name_mapping(name)
  return name.mapped_folder_name(mapping)    

def get_remote_name(local_folder_name):
  name = RemoteName(local_folder_name)
  return get_name_mapping(name)    

def get_local_name(remote_folder_name):
  name = LocalName(remote_folder_name)
  return get_name_mapping(name)    

提前感谢你的帮助!

1 个回答

1

添加:

folderfilter = lambda folder: folder not in ['Drafts,]

撰写回答