From 50fc49bf7f955fb9b3d1f2603eabb79f97aaac88 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Mon, 3 Mar 2008 02:21:33 -0600 Subject: [PATCH 1/2] Applied netrc_v2.diff from bboissin --- offlineimap.conf | 6 ++++-- offlineimap/repository/IMAP.py | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/offlineimap.conf b/offlineimap.conf index 06f883b..1f15041 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -218,8 +218,10 @@ remoteuser = username # There are four ways to specify the password for the remote IMAP # server: # -# 1. No password at all specified in the config file. 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. 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 33987e2..83f634a 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -20,7 +20,7 @@ from Base import BaseRepository from offlineimap import folder, imaputil, imapserver from offlineimap.folder.UIDMaps import MappedIMAPFolder from offlineimap.threadutil import ExitNotifyThread -import re, types, os +import re, types, os, netrc, errno from threading import * class IMAPRepository(BaseRepository): @@ -109,6 +109,14 @@ class IMAPRepository(BaseRepository): user = self.getconf('remoteuser') if user != None: 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): return self.getconfint('remoteport', None) @@ -146,6 +154,16 @@ class IMAPRepository(BaseRepository): password = fd.readline().strip() fd.close() 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 def getfolder(self, foldername): From 9b8720a4ec8d0c2302fb523c3ca6620670007904 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Mon, 3 Mar 2008 02:23:50 -0600 Subject: [PATCH 2/2] Apply tabspace.diff refs #14 --- offlineimap/repository/IMAP.py | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 83f634a..bed0358 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -85,30 +85,30 @@ class IMAPRepository(BaseRepository): return self.imapserver.delim def gethost(self): - host = None + host = None localeval = self.localeval if self.config.has_option(self.getsection(), 'remotehosteval'): - host = self.getconf('remotehosteval') - if host != None: - return localeval.eval(host) + host = self.getconf('remotehosteval') + if host != None: + return localeval.eval(host) - host = self.getconf('remotehost') - if host != None: - return host + host = self.getconf('remotehost') + if host != None: + return host def getuser(self): - user = None + user = None localeval = self.localeval if self.config.has_option(self.getsection(), 'remoteusereval'): - user = self.getconf('remoteusereval') - if user != None: - return localeval.eval(user) + user = self.getconf('remoteusereval') + if user != None: + return localeval.eval(user) - user = self.getconf('remoteuser') - if user != None: - return user + user = self.getconf('remoteuser') + if user != None: + return user try: netrcentry = netrc.netrc().authentificator(self.gethost()) except IOError, inst: @@ -137,13 +137,13 @@ class IMAPRepository(BaseRepository): return self.getconfboolean('expunge', 1) def getpassword(self): - passwd = None + passwd = None localeval = self.localeval if self.config.has_option(self.getsection(), 'remotepasseval'): - passwd = self.getconf('remotepasseval') - if passwd != None: - return localeval.eval(passwd) + passwd = self.getconf('remotepasseval') + if passwd != None: + return localeval.eval(passwd) password = self.getconf('remotepass', None) if password != None: @@ -153,7 +153,7 @@ class IMAPRepository(BaseRepository): fd = open(os.path.expanduser(passfile)) password = fd.readline().strip() fd.close() - return password + return password try: netrcentry = netrc.netrc().authenticators(self.gethost()) except IOError, inst: