"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/imapServer.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

imapServer.py  (roundup-1.6.1):imapServer.py  (roundup-2.0.0)
skipping to change at line 32 skipping to change at line 32
future it might be more practical to actually include the roundup future it might be more practical to actually include the roundup
files and run the appropriate commands using python. files and run the appropriate commands using python.
*TODO*: *TODO*:
Look into supporting a logfile instead of using 2>/logfile Look into supporting a logfile instead of using 2>/logfile
*TODO*: *TODO*:
Add an option for changing the uid/gid of the running process. Add an option for changing the uid/gid of the running process.
""" """
from __future__ import print_function
import getpass import getpass
import logging import logging
import imaplib import imaplib
import optparse import optparse
import os import os
import re import re
import time import time
from roundup.anypy.my_input import my_input
logging.basicConfig() logging.basicConfig()
log = logging.getLogger('roundup.IMAPServer') log = logging.getLogger('roundup.IMAPServer')
version = '0.1.2' version = '0.1.2'
class RoundupMailbox: class RoundupMailbox:
"""This contains all the info about each mailbox. """This contains all the info about each mailbox.
Username, Password, server, security, roundup database Username, Password, server, security, roundup database
""" """
def __init__(self, dbhome='', username=None, password=None, mailbox=None def __init__(self, dbhome='', username=None, password=None, mailbox=None
, server=None, protocol='imaps'): , server=None, protocol='imaps'):
self.username = username self.username = username
self.password = password self.password = password
self.mailbox = mailbox self.mailbox = mailbox
self.server = server self.server = server
self.protocol = protocol self.protocol = protocol
self.dbhome = dbhome self.dbhome = dbhome
try: try:
if not self.dbhome: if not self.dbhome:
self.dbhome = raw_input('Tracker home: ') self.dbhome = my_input('Tracker home: ')
if not os.path.exists(self.dbhome): if not os.path.exists(self.dbhome):
raise ValueError, 'Invalid home address: ' \ raise ValueError('Invalid home address: ' \
'directory "%s" does not exist.' % self.dbhome 'directory "%s" does not exist.' % self.dbhome)
if not self.server: if not self.server:
self.server = raw_input('Server: ') self.server = my_input('Server: ')
if not self.server: if not self.server:
raise ValueError, 'No Servername supplied' raise ValueError('No Servername supplied')
protocol = raw_input('protocol [imaps]? ') protocol = my_input('protocol [imaps]? ')
self.protocol = protocol self.protocol = protocol
if not self.username: if not self.username:
self.username = raw_input('Username: ') self.username = my_input('Username: ')
if not self.username: if not self.username:
raise ValueError, 'Invalid Username' raise ValueError('Invalid Username')
if not self.password: if not self.password:
print 'For server %s, user %s' % (self.server, self.username) print('For server %s, user %s' % (self.server, self.username))
self.password = getpass.getpass() self.password = getpass.getpass()
# password can be empty because it could be superceeded # password can be empty because it could be superceeded
# by a later entry # by a later entry
#if self.mailbox is None: #if self.mailbox is None:
# self.mailbox = raw_input('Mailbox [INBOX]: ') # self.mailbox = my_input('Mailbox [INBOX]: ')
# # We allow an empty mailbox because that will # # We allow an empty mailbox because that will
# # select the INBOX, whatever it is called # # select the INBOX, whatever it is called
except (KeyboardInterrupt, EOFError): except (KeyboardInterrupt, EOFError):
raise ValueError, 'Canceled by User' raise ValueError('Canceled by User')
def __str__(self): def __str__(self):
return 'Mailbox{ server:%(server)s, protocol:%(protocol)s, ' \ return 'Mailbox{ server:%(server)s, protocol:%(protocol)s, ' \
'username:%(username)s, mailbox:%(mailbox)s, ' \ 'username:%(username)s, mailbox:%(mailbox)s, ' \
'dbhome:%(dbhome)s }' % self.__dict__ 'dbhome:%(dbhome)s }' % self.__dict__
# [als] class name is misleading. this is imap client, not imap server # [als] class name is misleading. this is imap client, not imap server
class IMAPServer: class IMAPServer:
"""IMAP mail gatherer. """IMAP mail gatherer.
skipping to change at line 137 skipping to change at line 140
self.delay = delay self.delay = delay
def addMailbox(self, mailbox): def addMailbox(self, mailbox):
""" The linkage is as follows: """ The linkage is as follows:
servers -- users - mailbox:dbhome servers -- users - mailbox:dbhome
So there can be multiple servers, each with multiple users. So there can be multiple servers, each with multiple users.
Each username can be associated with multiple mailboxes. Each username can be associated with multiple mailboxes.
each mailbox is associated with 1 database home each mailbox is associated with 1 database home
""" """
log.info('Adding mailbox %s', mailbox) log.info('Adding mailbox %s', mailbox)
if not self.mailboxes.has_key(mailbox.server): if mailbox.server not in self.mailboxes:
self.mailboxes[mailbox.server] = {'protocol':'imaps', 'users':{}} self.mailboxes[mailbox.server] = {'protocol':'imaps', 'users':{}}
server = self.mailboxes[mailbox.server] server = self.mailboxes[mailbox.server]
if mailbox.protocol: if mailbox.protocol:
server['protocol'] = mailbox.protocol server['protocol'] = mailbox.protocol
if not server['users'].has_key(mailbox.username): if mailbox.username not in server['users']:
server['users'][mailbox.username] = {'password':'', 'mailboxes':{}} server['users'][mailbox.username] = {'password':'', 'mailboxes':{}}
user = server['users'][mailbox.username] user = server['users'][mailbox.username]
if mailbox.password: if mailbox.password:
user['password'] = mailbox.password user['password'] = mailbox.password
if user['mailboxes'].has_key(mailbox.mailbox): if mailbox.mailbox in user['mailboxes']:
raise ValueError, 'Mailbox is already defined' raise ValueError('Mailbox is already defined')
user['mailboxes'][mailbox.mailbox] = mailbox.dbhome user['mailboxes'][mailbox.mailbox] = mailbox.dbhome
def _process(self, message, dbhome): def _process(self, message, dbhome):
"""Actually process one of the email messages""" """Actually process one of the email messages"""
child = os.popen('roundup-mailgw %s' % dbhome, 'wb') child = os.popen('roundup-mailgw %s' % dbhome, 'wb')
child.write(message) child.write(message)
child.close() child.close()
#print message #print message
skipping to change at line 191 skipping to change at line 194
for user in s_vals['users']: for user in s_vals['users']:
u_vals = s_vals['users'][user] u_vals = s_vals['users'][user]
# TODO: As near as I can tell, you can only # TODO: As near as I can tell, you can only
# login with 1 username for each connection to a server. # login with 1 username for each connection to a server.
protocol = s_vals['protocol'].lower() protocol = s_vals['protocol'].lower()
if protocol == 'imaps': if protocol == 'imaps':
serv = imaplib.IMAP4_SSL(server) serv = imaplib.IMAP4_SSL(server)
elif protocol == 'imap': elif protocol == 'imap':
serv = imaplib.IMAP4(server) serv = imaplib.IMAP4(server)
else: else:
raise ValueError, 'Unknown protocol %s' % protocol raise ValueError('Unknown protocol %s' % protocol)
password = u_vals['password'] password = u_vals['password']
try: try:
log.info('Connecting as user: %s', user) log.info('Connecting as user: %s', user)
serv.login(user, password) serv.login(user, password)
for mbox in u_vals['mailboxes']: for mbox in u_vals['mailboxes']:
dbhome = u_vals['mailboxes'][mbox] dbhome = u_vals['mailboxes'][mbox]
log.info('Using mailbox: %s, home: %s', log.info('Using mailbox: %s, home: %s',
 End of changes. 15 change blocks. 
16 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)