Code

New tests for htmltemplate (well, it's a beginning)
[roundup.git] / roundup-mailgw
index 94623c59eea5a2d00f1e537d5f95ef2eb8d15401..a75f4387f9af9814006d47827686a04afe7abecc 100755 (executable)
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: roundup-mailgw,v 1.16 2001-11-30 18:23:55 jhermann Exp $
+# $Id: roundup-mailgw,v 1.21 2002-01-11 07:02:29 grubert Exp $
+
+# python version check
+from roundup import version_check
 
 import sys, os, re, cStringIO
-if int(sys.version[0]) < 2:
-    print "Roundup requires Python 2.0 or newer."
-    sys.exit(1)
 
 from roundup.mailgw import Message
+from roundup.i18n import _
 
 def do_pipe(handler):
     '''Read a message from standard input and pass it to the mail handler.
@@ -62,14 +63,23 @@ def do_mailbox(handler, filename):
 def do_pop(handler, server, user='', password=''):
     '''Read a series of messages from the specified POP server.
     '''
-    import getpass, poplib
-    if not user:
-        user = raw_input('User: ')
-    if not password:
-        password = getpass.getpass()
+    import getpass, poplib, socket
+    try:
+        if not user:
+            user = raw_input(_('User: '))
+        if not password:
+            password = getpass.getpass()
+    except (KeyboardInterrupt, EOFError):
+        # Ctrl C or D maybe also Ctrl Z under Windows.
+        print "\nAborted by user."
+        return 1
 
     # open a connection to the server and retrieve all messages
-    server = poplib.POP3(server)
+    try:
+        server = poplib.POP3(server)
+    except socket.error, message:
+        print "POP server error:", message
+        return 1
     server.user(user)
     server.pass_(password)
     numMessages = len(server.list()[1])
@@ -92,8 +102,8 @@ def do_pop(handler, server, user='', password=''):
 def usage(args, message=None):
     if message is not None:
         print message
-    print 'Usage: %s <instance home> [source spec]'%args[0]
-    print '''
+    print _('Usage: %(program)s <instance home> [source spec]')%{'program': args[0]}
+    print _('''
 The roundup mail gateway may be called in one of two ways:
  . with an instance home as the only argument,
  . with both an instance home and a mail spool file, or
@@ -120,7 +130,7 @@ POP:
     pop server
  are both valid. The username and/or password will be prompted for if
  not supplied on the command-line.
-'''
+''')
     return 1
 
 def main(args):
@@ -148,7 +158,7 @@ def main(args):
 
     # otherwise, figure what sort of mail source to handle
     if len(args) < 4:
-        return usage(args, 'Error: not enough source specification information')
+        return usage(args, _('Error: not enough source specification information'))
     source, specification = args[2:]
     if source == 'mailbox':
         return do_mailbox(handler, specification)
@@ -158,9 +168,9 @@ def main(args):
         if m:
             return do_pop(handler, m.group('server'), m.group('user'),
                 m.group('pass'))
-        return usage(args, 'Error: pop specification not valid')
+        return usage(args, _('Error: pop specification not valid'))
 
-    return usage(args, 'Error: The source must be either "mailbox" or "pop"')
+    return usage(args, _('Error: The source must be either "mailbox" or "pop"'))
 
 # call main
 if __name__ == '__main__':
@@ -168,6 +178,33 @@ if __name__ == '__main__':
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.20  2002/01/07 10:43:48  richard
+# #500329 ] exception on server not reachable-patch
+#
+# Revision 1.19  2002/01/05 02:19:03  richard
+# i18n'ification
+#
+# Revision 1.18  2001/12/13 00:20:01  richard
+#  . Centralised the python version check code, bumped version to 2.1.1 (really
+#    needs to be 2.1.2, but that isn't released yet :)
+#
+# Revision 1.17  2001/12/02 05:06:16  richard
+# . We now use weakrefs in the Classes to keep the database reference, so
+#   the close() method on the database is no longer needed.
+#   I bumped the minimum python requirement up to 2.1 accordingly.
+# . #487480 ] roundup-server
+# . #487476 ] INSTALL.txt
+#
+# I also cleaned up the change message / post-edit stuff in the cgi client.
+# There's now a clearly marked "TODO: append the change note" where I believe
+# the change note should be added there. The "changes" list will obviously
+# have to be modified to be a dict of the changes, or somesuch.
+#
+# More testing needed.
+#
+# Revision 1.16  2001/11/30 18:23:55  jhermann
+# Cleaned up strange import (less pollution, too)
+#
 # Revision 1.15  2001/11/30 13:16:37  rochecompaan
 # Fixed bug. Mail gateway was not using the extended Message class
 # resulting in failed submissions when mails were processed from a Unix