]> 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

1  2 
offlineimap.conf
offlineimap/repository/IMAP.py

diff --combined offlineimap.conf
index 43cabafc4ad8e075665e1159e12784dd6bd1054f,1f1504162ed86520852a3214cd7f89564b43cf40..a5b15d1dd71ca889eaa2b8c0e92d111328bc2a13
@@@ -51,18 -51,18 +51,18 @@@ maxsyncaccounts = 
  # fails, the second, and so forth.
  #
  # The pre-defined options are:
 -# Tk.Blinkenlights -- A graphical interface, shows LEDs and a single log
 -# Tk.VerboseUI -- A graphical interface, shows logs per thread
  # Curses.Blinkenlights -- A text-based (terminal) interface similar to
  # Tk.Blinkenlights
  # TTY.TTYUI -- a text-based (terminal) interface
  # Noninteractive.Basic -- Noninteractive interface suitable for cronning
  # Noninteractive.Quiet -- Noninteractive interface, generates no output
  #                         except for errors.
 +# Machine.MachineUI -- Interactive interface suitable for machine
 +#                      parsing.
  #
  # You can override this with a command-line option -u.
  
 -ui = Tk.Blinkenlights, Tk.VerboseUI, Curses.Blinkenlights, TTY.TTYUI,
 +ui = Curses.Blinkenlights, TTY.TTYUI,
       Noninteractive.Basic, Noninteractive.Quiet
  
  # If you try to synchronize messages to a read-only folder,
@@@ -85,19 -85,6 +85,19 @@@ ignore-readonly = n
  # pythonfile = ~/.offlineimap.py
  #
  
 +# By default, OfflineIMAP will not exit due to a network error until
 +# the operating system returns an error code.  Operating systems can sometimes
 +# take forever to notice this.  Here you can activate a timeout on the
 +# socket.  This timeout applies to individual socket reads and writes,
 +# not to an overall sync operation.  You could perfectly well have a 30s
 +# timeout here and your sync still take minutes.
 +#
 +# Values in the 30-120 second range are reasonable.
 +#
 +# The default is to have no timeout beyond the OS.  Times are given in seconds.
 +#
 +# socktimeout = 60
 +
  ##################################################
  # Mailbox name recorder
  ##################################################
@@@ -129,10 -116,29 +129,10 @@@ footer = "\n
  # Note that this filter can be used only to further restrict mbnames
  # to a subset of folders that pass the account's folderfilter.
  
 -##################################################
 -# Blinkenlights configuration
 -##################################################
 -
 -[ui.Tk.Blinkenlights]
 -
 -# Specifies the default number of lines in the log.
 -
 -loglines = 5
 -
 -# Specifies how many lines are in the scrollback log buffer.
 -
 -bufferlines = 500
 -
 -# If true, says that the log should be enabled by default.
 -# Otherwise, you have to click "Show Log" to enable the log.
 -
 -showlog = false
 +[ui.Curses.Blinkenlights]
 +# Character used to indicate thread status.
  
 -# Sets the font information.
 -
 -fontfamily = Helvetica
 -fontsize = 8
 +statuschar = .
  
  ##################################################
  # Accounts
@@@ -159,16 -165,6 +159,16 @@@ remoterepository = RemoteExampl
  
  # autorefresh = 5
  
 +# You can tell offlineimap to do a number of quicker synchronizations
 +# between full updates.  A quick synchronization only synchronizes
 +# if a Maildir folder has changed, or if an IMAP folder has received
 +# new messages or had messages deleted.  It does not update if the
 +# only changes were to IMAP flags.  Specify 0 to never do quick updates,
 +# -1 to always do quick updates, or a positive integer to do that many
 +# quick updates between each full synchronization (requires autorefresh).
 +
 +# quick = 10
 +
  [Repository LocalExample]
  
  # This is one of the two repositories that you'll work with given the
@@@ -203,18 -199,10 +203,18 @@@ restoreatime = n
  
  [Repository RemoteExample]
  
 -# And this is the remote repository.  For now, we only support IMAP here.
 +# And this is the remote repository.  We only support IMAP or Gmail here.
  
  type = IMAP
  
 +# The following can fetch the account credentials via a python expression that
 +# is parsed from the pythonfile parameter. For example, a function called
 +# "getcredentials" that parses a file "filename" and returns the account
 +# details for "hostname".
 +# remotehosteval = getcredentials("filename", "hostname", "hostname")
 +# remoteusereval = getcredentials("filename", "hostname", "user")
 +# remotepasseval = getcredentials("filename", "hostname", "passwd")
 +
  # Specify the remote hostname.
  remotehost = examplehost
  
@@@ -230,8 -218,10 +230,10 @@@ remoteuser = usernam
  # 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:
@@@ -380,33 -370,3 +382,33 @@@ holdconnectionopen = n
  #
  # foldersort = lambda x, y: -cmp(x, y)
  
 +
 +[Repository GmailExample]
 +
 +# A repository using Gmail's IMAP interface.  Any configuration
 +# parameter of `IMAP` type repositories can be used here.  Only
 +# `remoteuser` (or `remoteusereval` ) is mandatory.  Default values
 +# for other parameters are OK, and you should not need fiddle with
 +# those.
 +#
 +# The Gmail repository will use hard-coded values for `remotehost`,
 +# `remoteport`, `tunnel` and `ssl`.  (See
 +# http://mail.google.com/support/bin/answer.py?answer=78799&topic=12814)
 +# Any attempt to set those parameters will be silently ignored.
 +#
 +
 +type = Gmail
 +
 +# Specify the Gmail user name. This is the only mandatory parameter.
 +remoteuser = username@gmail.com
 +
 +# Deleting a message from a Gmail folder via the IMAP interface will
 +# just remove that folder's label from the message: the message will
 +# continue to exist in the '[Gmail]/All Mail' folder.  If `realdelete`
 +# is set to `True`, then deleted messages will really be deleted
 +# during `offlineimap` sync, by moving them to the '[Gmail]/Trash'
 +# folder.  BEWARE: this will deleted a messages from *all folders* it
 +# belongs to!
 +#
 +# See http://mail.google.com/support/bin/answer.py?answer=77657&topic=12815
 +realdelete = no
index 388535859c00084d8aeef04317e1e07cc378abf2,bed03587960eda24601e633b55af3df33abf4b7d..85870406853ebffc7505291f1baf4d088296c300
@@@ -20,7 -20,7 +20,7 @@@ from Base import BaseRepositor
  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):
          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)
  
              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):
      def getfoldertype(self):
          return folder.IMAP.IMAPFolder
  
 +    def connect(self):
 +        imapobj = self.imapserver.acquireconnection()
 +        self.imapserver.releaseconnection(imapobj)
 +
 +    def forgetfolders(self):
 +        self.folders = None
 +
      def getfolders(self):
          if self.folders != None:
              return self.folders