Complete.Org: Mailing Lists: Archives: offlineimap: November 2008:
Patch: enable offlineimap to get password from /etc/netrc
Home

Patch: enable offlineimap to get password from /etc/netrc

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: offlineimap@xxxxxxxxxxxx
Subject: Patch: enable offlineimap to get password from /etc/netrc
From: Jim Pryor <lists+offlineimap@xxxxxxxxxxxx>
Date: Sat, 29 Nov 2008 05:29:39 -0500

Attached is a patch that enables offlineimap to get its password from a
system-wide /etc/netrc file if there's no user-specific ~/.netrc.
I wanted to use a system-wide /etc/netrc file because I have some
system daemons sometimes sending me email. I use msmtp, which doesn't do
local mail. It will only send mail through external smtp servers. I've
also patched msmtp to be capable or retrieving passwords from
/etc/netrc. So now I can just put my email address in that one file, and
all my daemons and cronjobs and everything can get the email credentials
they need from that one place.

-- 
Jim Pryor
jim@xxxxxxxxxxxx


-- Attached file included as plaintext by Ecartis --

diff -Naur offlineimap.orig/offlineimap/repository/IMAP.py 
offlineimap/offlineimap/repository/IMAP.py
--- offlineimap.orig/offlineimap/repository/IMAP.py     2008-08-23 
14:38:07.000000000 -0400
+++ offlineimap/offlineimap/repository/IMAP.py  2008-08-23 14:44:13.000000000 
-0400
@@ -117,6 +117,16 @@
             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 @@
                 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):




[Prev in Thread] Current Thread [Next in Thread]
  • Patch: enable offlineimap to get password from /etc/netrc, Jim Pryor <=