comparison roundup/scripts/roundup_mailgw.py @ 4001:82bdcff42c17

better comments, small refactoring
author Richard Jones <richard@users.sourceforge.net>
date Tue, 19 Aug 2008 01:06:01 +0000
parents 39af38d6f77d
children 61cf00ca920a
comparison
equal deleted inserted replaced
4000:39af38d6f77d 4001:82bdcff42c17
12 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 12 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 13 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16 # 16 #
17 # $Id: roundup_mailgw.py,v 1.24 2008-08-19 01:01:32 richard Exp $ 17 # $Id: roundup_mailgw.py,v 1.25 2008-08-19 01:06:01 richard Exp $
18 18
19 """Command-line script stub that calls the roundup.mailgw. 19 """Command-line script stub that calls the roundup.mailgw.
20 """ 20 """
21 __docformat__ = 'restructuredtext' 21 __docformat__ = 'restructuredtext'
22 22
163 socket.setdefaulttimeout(60) 163 socket.setdefaulttimeout(60)
164 164
165 if source == 'mailbox': 165 if source == 'mailbox':
166 return handler.do_mailbox(specification) 166 return handler.do_mailbox(specification)
167 167
168 # Try parsing the netrc file first. 168 # the source will be a network server, so obtain the credentials to
169 # use in connecting to the server
169 try: 170 try:
171 # attempt to obtain credentials from a ~/.netrc file
170 authenticator = netrc.netrc().authenticators(specification) 172 authenticator = netrc.netrc().authenticators(specification)
171 username = authenticator[0] 173 username = authenticator[0]
172 password = authenticator[2] 174 password = authenticator[2]
173 server = specification 175 server = specification
174 # IOError if no ~/.netrc file, TypeError if the hostname 176 # IOError if no ~/.netrc file, TypeError if the hostname
181 password = match.group('pass') 183 password = match.group('pass')
182 server = match.group('server') 184 server = match.group('server')
183 else: 185 else:
184 return usage(argv, _('Error: %s specification not valid') % source) 186 return usage(argv, _('Error: %s specification not valid') % source)
185 187
186 if source == 'pop' or source == 'pops': 188 # now invoke the mailgw handler depending on the server handler requested
189 if source.startswith('pop'):
187 ssl = source.endswith('s') 190 ssl = source.endswith('s')
188 if ssl and sys.version_info<(2,4): 191 if ssl and sys.version_info<(2,4):
189 return usage(argv, _('Error: a later version of python is required')) 192 return usage(argv, _('Error: a later version of python is required'))
190 return handler.do_pop(server, username, password, ssl) 193 return handler.do_pop(server, username, password, ssl)
191 elif source == 'apop': 194 elif source == 'apop':
192 return handler.do_apop(server, username, password) 195 return handler.do_apop(server, username, password)
193 elif source == 'imap' or source == 'imaps': 196 elif source.startswith('imap'):
194 ssl = source.endswith('s') 197 ssl = source.endswith('s')
195 mailbox = '' 198 mailbox = ''
196 if len(args) > 3: 199 if len(args) > 3:
197 mailbox = args[3] 200 mailbox = args[3]
198 return handler.do_imap(server, username, password, mailbox, ssl) 201 return handler.do_imap(server, username, password, mailbox, ssl)
199 202
200 return usage(argv, _('Error: The source must be either "mailbox",' 203 return usage(argv, _('Error: The source must be either "mailbox",'
201 ' "pop", "apop", "imap" or "imaps"')) 204 ' "pop", "pops", "apop", "imap" or "imaps"'))
202 finally: 205 finally:
203 # handler might have closed the initial db and opened a new one 206 # handler might have closed the initial db and opened a new one
204 handler.db.close() 207 handler.db.close()
205 208
206 def run(): 209 def run():

Roundup Issue Tracker: http://roundup-tracker.org/