Merge branch 'netrc-integration'

Applies patches by bboisin to add netrc support

Conflicts:

	offlineimap/repository/IMAP.py

refs #14
This commit is contained in:
John Goerzen 2008-03-03 02:27:13 -06:00
commit 7b4e651d12
2 changed files with 25 additions and 3 deletions

View File

@ -230,8 +230,10 @@ remoteuser = username
# There are four ways to specify the password for the remote IMAP # There are four ways to specify the password for the remote IMAP
# server: # server:
# #
# 1. No password at all specified in the config file. You will # 1. No password at all specified in the config file. If a matching
# be prompted for the password when OfflineIMAP starts. # entry is found in ~/.netrc (see netrc (5) for information) the
# password from the matching entry will be used. Otherwise you
# will be prompted for the password when OfflineIMAP starts.
# #
# 2. The remote password stored in this file with the remotepass # 2. The remote password stored in this file with the remotepass
# option. Example: # option. Example:

View File

@ -20,7 +20,7 @@ from Base import BaseRepository
from offlineimap import folder, imaputil, imapserver from offlineimap import folder, imaputil, imapserver
from offlineimap.folder.UIDMaps import MappedIMAPFolder from offlineimap.folder.UIDMaps import MappedIMAPFolder
from offlineimap.threadutil import ExitNotifyThread from offlineimap.threadutil import ExitNotifyThread
import re, types, os import re, types, os, netrc, errno
from threading import * from threading import *
class IMAPRepository(BaseRepository): class IMAPRepository(BaseRepository):
@ -110,6 +110,15 @@ class IMAPRepository(BaseRepository):
if user != None: if user != None:
return user return user
try:
netrcentry = netrc.netrc().authentificator(self.gethost())
except IOError, inst:
if inst.errno != errno.ENOENT:
raise
else:
if netrcentry:
return netrcentry[0]
def getport(self): def getport(self):
return self.getconfint('remoteport', None) return self.getconfint('remoteport', None)
@ -146,6 +155,17 @@ class IMAPRepository(BaseRepository):
password = fd.readline().strip() password = fd.readline().strip()
fd.close() fd.close()
return password return password
try:
netrcentry = netrc.netrc().authenticators(self.gethost())
except IOError, inst:
if inst.errno != errno.ENOENT:
raise
else:
if netrcentry:
user = self.getconf('remoteuser')
if user == None or user == netrcentry[0]:
return netrcentry[2]
return None return None
def getfolder(self, foldername): def getfolder(self, foldername):