/head: changeset 37
Updated
This commit is contained in:
parent
75dcb0dd16
commit
8171027aa1
@ -35,6 +35,12 @@ metadata = ~/.imapsync
|
||||
|
||||
accounts = Test
|
||||
|
||||
# You can have imapsync continue running indefinately, automatically
|
||||
# syncing your mail periodically. If you want that, specify how
|
||||
# frequently to do that (in minutes) here.
|
||||
|
||||
# autorefresh = 5
|
||||
|
||||
##################################################
|
||||
# Mailbox name recorder
|
||||
##################################################
|
||||
|
@ -45,6 +45,7 @@ remoterepos = None
|
||||
localrepos = None
|
||||
mailboxes = []
|
||||
|
||||
def syncitall():
|
||||
for accountname in accounts:
|
||||
ui.acct(accountname)
|
||||
accountmetadata = os.path.join(metadatadir, accountname)
|
||||
@ -60,6 +61,8 @@ for accountname in accounts:
|
||||
password = config.get(accountname, "remotepass")
|
||||
else:
|
||||
password = ui.getpass(accountname, host, port, user)
|
||||
# Save it for future reference.
|
||||
config.set(accountname, "remotepass", password)
|
||||
ssl = config.getboolean(accountname, "ssl")
|
||||
|
||||
# Connect to the remote server.
|
||||
@ -110,6 +113,20 @@ for accountname in accounts:
|
||||
ui.syncingmessages(localrepos, localfolder, statusrepos, statusfolder)
|
||||
localfolder.syncmessagesto(statusfolder)
|
||||
statusfolder.save()
|
||||
server.close()
|
||||
|
||||
|
||||
mbnames.genmbnames(config, mailboxes)
|
||||
|
||||
syncitall()
|
||||
if config.has_option('general', 'autorefresh'):
|
||||
refreshperiod = config.getint('general', 'autorefresh') * 60
|
||||
while 1:
|
||||
sleepamount = refreshperiod
|
||||
abortsleep = 0
|
||||
while sleepamount > 0 and not abortsleep:
|
||||
abortsleep = ui.sleeping(1, sleepamount)
|
||||
sleepamount -= 1
|
||||
ui.sleeping(0, 0) # Done sleeping.
|
||||
syncitall()
|
||||
|
||||
|
@ -64,7 +64,7 @@ class IMAPFolder(BaseFolder):
|
||||
|
||||
def getmessage(self, uid):
|
||||
assert(self.imapobj.select(self.getfullname())[0] == 'OK')
|
||||
return self.imapobj.uid('fetch', '%d' % uid, '(RFC822)')[1][0][1].replace("\r\n", "\n")
|
||||
return self.imapobj.uid('fetch', '%d' % uid, '(BODY.PEEK[])')[1][0][1].replace("\r\n", "\n")
|
||||
|
||||
def getmessageflags(self, uid):
|
||||
return self.getmessagelist()[uid]['flags']
|
||||
|
@ -67,4 +67,6 @@ class IMAPServer:
|
||||
self.imapobj = imapobj
|
||||
return imapobj
|
||||
|
||||
|
||||
def close(self):
|
||||
self.imapobj.logout()
|
||||
self.imapobj = None
|
||||
|
@ -50,5 +50,6 @@ class IMAPRepository(BaseRepository):
|
||||
continue
|
||||
retval.append(folder.IMAP.IMAPFolder(self.imapserver, name,
|
||||
self.nametrans(imaputil.dequote(name))))
|
||||
retval.sort()
|
||||
self.folders = retval
|
||||
return retval
|
||||
|
@ -1,5 +1,6 @@
|
||||
from UIBase import UIBase
|
||||
from getpass import getpass
|
||||
import select, sys
|
||||
|
||||
class TTYUI(UIBase):
|
||||
def __init__(self, verbose = 0):
|
||||
@ -23,3 +24,18 @@ class TTYUI(UIBase):
|
||||
def messagelistloaded(s, repos, folder, count):
|
||||
if s.verbose:
|
||||
UIBase.messagelistloaded(s, repos, folder, count)
|
||||
|
||||
def sleeping(s, sleepsecs, remainingsecs):
|
||||
if remainingsecs > 0:
|
||||
sys.stdout.write("Next sync in %d:%02d (press Enter to sync now) \r" % \
|
||||
(remainingsecs / 60, remainingsecs % 60))
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
sys.stdout.write("Wait done, proceeding with sync.... ")
|
||||
|
||||
if sleepsecs > 0:
|
||||
if len(select.select([sys.stdin], [], [], sleepsecs)[0]):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from imapsync import repository
|
||||
import re
|
||||
import re, time
|
||||
|
||||
class UIBase:
|
||||
################################################## UTILS
|
||||
@ -95,12 +95,22 @@ class UIBase:
|
||||
def addingflags(s, uid, flags, destlist):
|
||||
ds = s.folderlist(destlist)
|
||||
s._msg("Adding flags %s to message %d on %s" % \
|
||||
(flags.join(", "), uid, ds))
|
||||
(", ".join(flags), uid, ds))
|
||||
|
||||
def deletingflags(s, uid, flags, destlist):
|
||||
ds = s.folderlist(destlist)
|
||||
s._msg("Deleting flags %s to message %d on %s" % \
|
||||
(flags.join(", "), uid, ds))
|
||||
(", ".join(flags), uid, ds))
|
||||
|
||||
################################################## Other
|
||||
|
||||
def sleeping(s, sleepsecs, remainingsecs):
|
||||
"""Sleep for sleepsecs, remainingsecs to go.
|
||||
If sleepsecs is 0, indicates we're done sleeping.
|
||||
|
||||
Return 0 for normal sleep, or 1 to indicate a request
|
||||
to sync immediately."""
|
||||
s._msg("Next refresh in %d seconds" % remainingsec)
|
||||
if sleepsecs > 0:
|
||||
time.sleep(sleepsecs)
|
||||
return 0
|
||||
|
Loading…
Reference in New Issue
Block a user