Patch from Jim Pryor to support /etc/netrc in addition to ~/.netrc

This commit is contained in:
John Goerzen 2008-12-02 13:15:44 -06:00
parent 147265ac39
commit 75af76b70f
2 changed files with 25 additions and 4 deletions

View File

@ -267,10 +267,11 @@ remoteuser = username
# There are five ways to give the password for the remote IMAP # There are five ways to give the password for the remote IMAP
# server: # server:
# #
# 1. No password at all specified in the config file. If a matching # 1. No password at all specified in the config file. If a matching entry is
# entry is found in ~/.netrc (see netrc (5) for information) the # found in ~/.netrc (see netrc (5) for information) the password from the
# password from the matching entry will be used. Otherwise you # matching entry will be used. If there is no ~/.netrc file but there is an
# will be prompted for the password when OfflineIMAP starts. # /etc/netrc file, the password will instead be taken from there. 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

@ -117,6 +117,16 @@ class IMAPRepository(BaseRepository):
if netrcentry: if netrcentry:
return netrcentry[0] return netrcentry[0]
try:
netrcentry = netrc.netrc('/etc/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)
@ -170,6 +180,16 @@ class IMAPRepository(BaseRepository):
user = self.getconf('remoteuser') user = self.getconf('remoteuser')
if user == None or user == netrcentry[0]: if user == None or user == netrcentry[0]:
return netrcentry[2] return netrcentry[2]
try:
netrcentry = netrc.netrc('/etc/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):