]> code.delx.au - offlineimap/commitdiff
Merge branch 'netrc-integration'
authorJohn Goerzen <jgoerzen@complete.org>
Mon, 3 Mar 2008 08:27:13 +0000 (02:27 -0600)
committerJohn Goerzen <jgoerzen@complete.org>
Mon, 3 Mar 2008 08:27:13 +0000 (02:27 -0600)
Applies patches by bboisin to add netrc support

Conflicts:

offlineimap/repository/IMAP.py

refs #14

offlineimap.conf
offlineimap/repository/IMAP.py

index 43cabafc4ad8e075665e1159e12784dd6bd1054f..a5b15d1dd71ca889eaa2b8c0e92d111328bc2a13 100644 (file)
@@ -230,8 +230,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:
index 388535859c00084d8aeef04317e1e07cc378abf2..85870406853ebffc7505291f1baf4d088296c300 100644 (file)
@@ -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):
@@ -110,6 +110,15 @@ class IMAPRepository(BaseRepository):
         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 +155,17 @@ 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):