]> code.delx.au - offlineimap/commitdiff
Applied netrc_v2.diff from bboissin
authorJohn Goerzen <jgoerzen@complete.org>
Mon, 3 Mar 2008 08:21:33 +0000 (02:21 -0600)
committerJohn Goerzen <jgoerzen@complete.org>
Mon, 3 Mar 2008 08:21:33 +0000 (02:21 -0600)
offlineimap.conf
offlineimap/repository/IMAP.py

index 06f883b599574003bd43225bd68503fd0ad8f268..1f1504162ed86520852a3214cd7f89564b43cf40 100644 (file)
@@ -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:
index 33987e29cd4a5aecefd80acc78ec5adbb0ce6cc4..83f634ac662d9d1e61e3bd8d65fdc8eedd0ec69d 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):
@@ -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):