From 75af76b70f31336df6d5d20de6e608a70d8f0d39 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Tue, 2 Dec 2008 13:15:44 -0600 Subject: [PATCH] Patch from Jim Pryor to support /etc/netrc in addition to ~/.netrc --- offlineimap.conf | 9 +++++---- offlineimap/repository/IMAP.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/offlineimap.conf b/offlineimap.conf index 011c33e..7f51819 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -267,10 +267,11 @@ remoteuser = username # There are five ways to give the password for the remote IMAP # server: # -# 1. No password at all specified in the config file. If a matching -# 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. +# 1. No password at all specified in the config file. If a matching entry is +# found in ~/.netrc (see netrc (5) for information) the password from the +# matching entry will be used. If there is no ~/.netrc file but there is an +# /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 # option. Example: diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index a9d7343..f8445f8 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -117,6 +117,16 @@ class IMAPRepository(BaseRepository): if netrcentry: 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): return self.getconfint('remoteport', None) @@ -170,6 +180,16 @@ class IMAPRepository(BaseRepository): user = self.getconf('remoteuser') if user == None or user == netrcentry[0]: 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 def getfolder(self, foldername):