1.1 --- a/imiptools/__init__.py Sun Oct 01 22:32:11 2017 +0200
1.2 +++ b/imiptools/__init__.py Sun Oct 01 23:09:50 2017 +0200
1.3 @@ -67,7 +67,7 @@
1.4 return get_store(self.store_type, self.store_dir)
1.5
1.6 def get_publisher(self):
1.7 - return self.publishing_dir and get_publisher(self.publishing_dir) or None
1.8 + return get_publisher(self.publishing_dir)
1.9
1.10 def get_journal(self):
1.11 return get_journal(self.store_type, self.journal_dir)
1.12 @@ -117,6 +117,10 @@
1.13
1.14 # Process the message for each recipient.
1.15
1.16 + if self.debug:
1.17 + print >>sys.stderr, "Recipients..."
1.18 + print >>sys.stderr, ", ".join(users)
1.19 +
1.20 for user in users:
1.21 Recipient(user, messenger, store, publisher, journal,
1.22 preferences_dir, self.handlers, self.outgoing_only,
1.23 @@ -201,16 +205,33 @@
1.24 getvalue = lambda value, default=None: value and value[0] or default
1.25
1.26 self.messenger = Messenger(lmtp_socket=getvalue(lmtp), local_smtp=local_smtp, sender=getvalue(senders))
1.27 +
1.28 + # Obtain arguments or configured defaults.
1.29 +
1.30 self.store_type = getvalue(store_type, settings["STORE_TYPE"])
1.31 - self.store_dir = getvalue(store_dir)
1.32 - self.publishing_dir = getvalue(publishing_dir)
1.33 - self.preferences_dir = getvalue(preferences_dir)
1.34 - self.journal_dir = getvalue(journal_dir)
1.35 + self.store_dir = getvalue(store_dir, settings["STORE_DIR"])
1.36 + self.journal_dir = getvalue(journal_dir, settings["JOURNAL_DIR"])
1.37 + self.preferences_dir = getvalue(preferences_dir, settings["PREFERENCES_DIR"])
1.38 + self.publishing_dir = getvalue(publishing_dir, settings["PUBLISH_DIR"])
1.39 +
1.40 + # Show configuration and exit if requested.
1.41 +
1.42 + if "--show-config" in args:
1.43 + print """\
1.44 +Store type: %s
1.45 +Store directory: %s
1.46 +Journal directory: %s
1.47 +Preferences directory: %s
1.48 +Publishing directory: %s""" % (
1.49 + self.store_type, self.store_dir, self.journal_dir,
1.50 + self.preferences_dir, self.publishing_dir)
1.51 + return
1.52
1.53 # If debug mode is set, extend the line length for convenience.
1.54
1.55 if self.debug:
1.56 settings["CALENDAR_LINE_LENGTH"] = 1000
1.57 + print >>sys.stderr, "Store type", self.store_type, "at", self.store_dir
1.58
1.59 # Process the input.
1.60
1.61 @@ -230,7 +251,8 @@
1.62 Usage: %s [ -o <recipient> ... ] [-s <sender> ... ] [ -l <socket> | -L ] \\
1.63 [ -T <store type ] \\
1.64 [ -S <store directory> ] [ -P <publishing directory> ] \\
1.65 - [ -p <preferences directory> ] [ -j <journal directory> ] [ -d ]
1.66 + [ -p <preferences directory> ] [ -j <journal directory> ] \\
1.67 + [ -d ] [ --show-config ]
1.68
1.69 Address options:
1.70
1.71 @@ -249,7 +271,7 @@
1.72 (Where a program needs to deliver messages, one of the above options must be
1.73 specified.)
1.74
1.75 -Configuration options:
1.76 +Configuration options (overriding configured defaults):
1.77
1.78 -j Indicates the location of quota-related journal information
1.79 -P Indicates the location of published free/busy resources
1.80 @@ -261,8 +283,15 @@
1.81 Output options:
1.82
1.83 -d Run in debug mode, producing informative output describing the behaviour
1.84 - of the program
1.85 + of the program, displaying responses on standard output instead of sending
1.86 + messages
1.87 +
1.88 +Diagnostic options:
1.89 +
1.90 +--show-config Show the configuration with the specified options and exit
1.91 + without performing any actions
1.92 """ % os.path.split(sys.argv[0])[-1]
1.93 +
1.94 elif "-d" in args:
1.95 self.process_args(args, sys.stdin)
1.96 else:
1.97 @@ -273,16 +302,23 @@
1.98 except Exception, exc:
1.99 if "-v" in args:
1.100 raise
1.101 +
1.102 + # Obtain the exception origin.
1.103 +
1.104 type, value, tb = sys.exc_info()
1.105 while tb.tb_next:
1.106 tb = tb.tb_next
1.107 f = tb.tb_frame
1.108 co = f and f.f_code
1.109 filename = co and co.co_filename
1.110 +
1.111 print >>sys.stderr, "Exception %s at %d in %s" % (exc, tb.tb_lineno, filename)
1.112 +
1.113 #import traceback
1.114 #traceback.print_exc(file=open("/tmp/mail.log", "a"))
1.115 +
1.116 sys.exit(EX_TEMPFAIL)
1.117 +
1.118 sys.exit(0)
1.119
1.120 class Recipient(Client):
1.121 @@ -313,10 +349,15 @@
1.122 may be constructed according to individual preferences.
1.123 """
1.124
1.125 - handlers = dict([(name, cls(senders, self.user and get_address(self.user),
1.126 - self.messenger, self.store, self.publisher,
1.127 - self.journal, self.preferences_dir))
1.128 - for name, cls in self.handlers])
1.129 + handlers = {}
1.130 +
1.131 + # Instantiate handlers for the supported methods.
1.132 +
1.133 + for name, cls in self.handlers:
1.134 + handlers[name] = cls(senders, self.user and get_address(self.user),
1.135 + self.messenger, self.store, self.publisher,
1.136 + self.journal, self.preferences_dir)
1.137 +
1.138 handled = False
1.139
1.140 # Check for participating recipients. Non-participating recipients will
1.141 @@ -334,6 +375,9 @@
1.142 if part.get_content_type() in itip_content_types and \
1.143 part.get_param("method"):
1.144
1.145 + if self.debug:
1.146 + print >>sys.stderr, "Handle method %s..." % part.get_param("method")
1.147 +
1.148 handle_itip_part(part, handlers)
1.149 handled = True
1.150