paul@49 | 1 | #!/usr/bin/env python |
paul@49 | 2 | |
paul@146 | 3 | """ |
paul@146 | 4 | A processing framework for iMIP content. |
paul@146 | 5 | |
paul@1212 | 6 | Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> |
paul@146 | 7 | |
paul@146 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@146 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@146 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@146 | 11 | version. |
paul@146 | 12 | |
paul@146 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@146 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@146 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@146 | 16 | details. |
paul@146 | 17 | |
paul@146 | 18 | You should have received a copy of the GNU General Public License along with |
paul@146 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@146 | 20 | """ |
paul@146 | 21 | |
paul@49 | 22 | from email import message_from_file |
paul@1212 | 23 | from imiptools.config import settings |
paul@604 | 24 | from imiptools.client import Client |
paul@1286 | 25 | from imiptools.content import handle_itip_part, have_itip_part, \ |
paul@1286 | 26 | is_returned_message |
paul@604 | 27 | from imiptools.data import get_address, get_addresses, get_uri |
paul@83 | 28 | from imiptools.mail import Messenger |
paul@1340 | 29 | from imiptools.stores import get_store, get_publisher, get_journal, \ |
paul@1340 | 30 | StoreInitialisationError |
paul@991 | 31 | import sys, os |
paul@49 | 32 | |
paul@49 | 33 | # Postfix exit codes. |
paul@49 | 34 | |
paul@49 | 35 | EX_TEMPFAIL = 75 |
paul@49 | 36 | |
paul@49 | 37 | # Processing of incoming messages. |
paul@49 | 38 | |
paul@49 | 39 | def get_all_values(msg, key): |
paul@1312 | 40 | |
paul@1312 | 41 | "Return all values in 'msg' for 'key'." |
paul@1312 | 42 | |
paul@49 | 43 | l = [] |
paul@49 | 44 | for v in msg.get_all(key) or []: |
paul@1312 | 45 | for s in v.split(","): |
paul@1312 | 46 | l.append(s.strip()) |
paul@49 | 47 | return l |
paul@49 | 48 | |
paul@49 | 49 | class Processor: |
paul@49 | 50 | |
paul@49 | 51 | "The processing framework." |
paul@49 | 52 | |
paul@822 | 53 | def __init__(self, handlers, outgoing_only=False): |
paul@49 | 54 | self.handlers = handlers |
paul@822 | 55 | self.outgoing_only = outgoing_only |
paul@607 | 56 | self.messenger = None |
paul@60 | 57 | self.lmtp_socket = None |
paul@1088 | 58 | self.store_type = None |
paul@563 | 59 | self.store_dir = None |
paul@563 | 60 | self.publishing_dir = None |
paul@1039 | 61 | self.journal_dir = None |
paul@639 | 62 | self.preferences_dir = None |
paul@563 | 63 | self.debug = False |
paul@1384 | 64 | self.output_only = False |
paul@49 | 65 | |
paul@569 | 66 | def get_store(self): |
paul@1338 | 67 | |
paul@1343 | 68 | "Return any configured store." |
paul@1338 | 69 | |
paul@1343 | 70 | return get_store(self.store_type, self.store_dir) |
paul@569 | 71 | |
paul@569 | 72 | def get_publisher(self): |
paul@1338 | 73 | |
paul@1340 | 74 | "Return any configured publisher or None if not configured." |
paul@1338 | 75 | |
paul@1340 | 76 | try: |
paul@1340 | 77 | return get_publisher(self.publishing_dir) |
paul@1340 | 78 | except StoreInitialisationError: |
paul@1340 | 79 | return None |
paul@569 | 80 | |
paul@1039 | 81 | def get_journal(self): |
paul@1338 | 82 | |
paul@1340 | 83 | "Return any configured journal or None if not configured." |
paul@1338 | 84 | |
paul@1340 | 85 | try: |
paul@1340 | 86 | return get_journal(self.store_type, self.journal_dir) |
paul@1340 | 87 | except StoreInitialisationError: |
paul@1340 | 88 | return None |
paul@1039 | 89 | |
paul@822 | 90 | def process(self, f, original_recipients): |
paul@49 | 91 | |
paul@49 | 92 | """ |
paul@49 | 93 | Process content from the stream 'f' accompanied by the given |
paul@515 | 94 | 'original_recipients'. |
paul@49 | 95 | """ |
paul@49 | 96 | |
paul@49 | 97 | msg = message_from_file(f) |
paul@49 | 98 | |
paul@604 | 99 | messenger = self.messenger |
paul@604 | 100 | store = self.get_store() |
paul@604 | 101 | publisher = self.get_publisher() |
paul@1039 | 102 | journal = self.get_journal() |
paul@639 | 103 | preferences_dir = self.preferences_dir |
paul@604 | 104 | |
paul@49 | 105 | # Handle messages with iTIP parts. |
paul@438 | 106 | # Typically, the details of recipients are of interest in handling |
paul@438 | 107 | # messages. |
paul@49 | 108 | |
paul@822 | 109 | if not self.outgoing_only: |
paul@1282 | 110 | senders = get_addresses(get_all_values(msg, "Reply-To") or get_all_values(msg, "From") or []) |
paul@438 | 111 | original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or []) |
paul@1282 | 112 | users = [] |
paul@1282 | 113 | |
paul@438 | 114 | for recipient in original_recipients: |
paul@1282 | 115 | users.append(get_uri(recipient)) |
paul@438 | 116 | |
paul@438 | 117 | # However, outgoing messages do not usually presume anything about the |
paul@832 | 118 | # eventual recipients and focus on the sender instead. If possible, the |
paul@832 | 119 | # sender is identified, but since this may be the calendar system (and |
paul@832 | 120 | # the actual sender is defined in the object), and since the recipient |
paul@832 | 121 | # may be in a Bcc header that is not available here, it may be left as |
paul@832 | 122 | # None and deduced from the object content later. |
paul@438 | 123 | |
paul@438 | 124 | else: |
paul@1282 | 125 | senders = [] |
paul@1282 | 126 | |
paul@1282 | 127 | for sender in get_addresses(get_all_values(msg, "From") or []): |
paul@1282 | 128 | if sender != settings["MESSAGE_SENDER"]: |
paul@1282 | 129 | senders.append(sender) |
paul@1282 | 130 | |
paul@1282 | 131 | users = [senders and get_uri(senders[0]) or None] |
paul@1282 | 132 | |
paul@1282 | 133 | # Process the message for each recipient. |
paul@1282 | 134 | |
paul@1285 | 135 | if self.debug: |
paul@1285 | 136 | print >>sys.stderr, "Recipients..." |
paul@1334 | 137 | print >>sys.stderr, ", ".join(map(str, users)) |
paul@1285 | 138 | |
paul@1282 | 139 | for user in users: |
paul@1282 | 140 | Recipient(user, messenger, store, publisher, journal, |
paul@1282 | 141 | preferences_dir, self.handlers, self.outgoing_only, |
paul@1384 | 142 | self.debug, self.output_only).process(msg, senders) |
paul@229 | 143 | |
paul@49 | 144 | def process_args(self, args, stream): |
paul@49 | 145 | |
paul@49 | 146 | """ |
paul@49 | 147 | Interpret the given program arguments 'args' and process input from the |
paul@49 | 148 | given 'stream'. |
paul@49 | 149 | """ |
paul@49 | 150 | |
paul@1312 | 151 | args = parse_args(args, {"--show-config" : ("show_config", False)}) |
paul@49 | 152 | |
paul@1312 | 153 | self.debug = args["debug"] |
paul@1384 | 154 | self.output_only = args["output_only"] |
paul@49 | 155 | |
paul@1285 | 156 | # Obtain arguments or configured defaults. |
paul@49 | 157 | |
paul@1345 | 158 | self.store_type = args.get("store_type") |
paul@1345 | 159 | self.store_dir = args.get("store_dir") |
paul@1345 | 160 | self.journal_dir = args.get("journal_dir") |
paul@1312 | 161 | self.preferences_dir = args.get("preferences_dir") or settings["PREFERENCES_DIR"] |
paul@1345 | 162 | self.publishing_dir = args.get("publishing_dir") |
paul@1088 | 163 | |
paul@1312 | 164 | self.messenger = Messenger(lmtp_socket=args["lmtp"], |
paul@1312 | 165 | local_smtp=args["local_smtp"], |
paul@1312 | 166 | sender=(args["senders"] or [None])[0]) |
paul@563 | 167 | |
paul@1285 | 168 | # Show configuration and exit if requested. |
paul@639 | 169 | |
paul@1312 | 170 | if args["show_config"]: |
paul@1285 | 171 | print """\ |
paul@1345 | 172 | Store type: %s (%s) |
paul@1345 | 173 | Store directory: %s (%s) |
paul@1345 | 174 | Journal directory: %s (%s) |
paul@1285 | 175 | Preferences directory: %s |
paul@1345 | 176 | Publishing directory: %s (%s) |
paul@1345 | 177 | """ % ( |
paul@1345 | 178 | self.store_type, settings["STORE_TYPE"], |
paul@1345 | 179 | self.store_dir, settings["STORE_DIR"], |
paul@1345 | 180 | self.journal_dir, settings["JOURNAL_DIR"], |
paul@1345 | 181 | self.preferences_dir, |
paul@1345 | 182 | self.publishing_dir, settings["PUBLISH_DIR"]) |
paul@1285 | 183 | return |
paul@1174 | 184 | |
paul@1174 | 185 | # If debug mode is set, extend the line length for convenience. |
paul@1174 | 186 | |
paul@1174 | 187 | if self.debug: |
paul@1212 | 188 | settings["CALENDAR_LINE_LENGTH"] = 1000 |
paul@1285 | 189 | print >>sys.stderr, "Store type", self.store_type, "at", self.store_dir |
paul@1174 | 190 | |
paul@1174 | 191 | # Process the input. |
paul@1174 | 192 | |
paul@1312 | 193 | self.process(stream, args["original_recipients"]) |
paul@49 | 194 | |
paul@49 | 195 | def __call__(self): |
paul@49 | 196 | |
paul@49 | 197 | """ |
paul@49 | 198 | Obtain arguments from the command line to initialise the processor |
paul@49 | 199 | before invoking it. |
paul@49 | 200 | """ |
paul@49 | 201 | |
paul@49 | 202 | args = sys.argv[1:] |
paul@49 | 203 | |
paul@1312 | 204 | # Show the help text if requested. |
paul@991 | 205 | |
paul@1312 | 206 | if "--help" in args: |
paul@1312 | 207 | show_help(os.path.split(sys.argv[0])[-1]) |
paul@991 | 208 | |
paul@1312 | 209 | # In debug mode, process the message without exception handling. |
paul@991 | 210 | |
paul@991 | 211 | elif "-d" in args: |
paul@49 | 212 | self.process_args(args, sys.stdin) |
paul@1312 | 213 | |
paul@1312 | 214 | # Otherwise, process the message and handle exceptions gracefully. |
paul@1312 | 215 | |
paul@49 | 216 | else: |
paul@49 | 217 | try: |
paul@49 | 218 | self.process_args(args, sys.stdin) |
paul@49 | 219 | except SystemExit, value: |
paul@49 | 220 | sys.exit(value) |
paul@49 | 221 | except Exception, exc: |
paul@60 | 222 | if "-v" in args: |
paul@60 | 223 | raise |
paul@1285 | 224 | |
paul@1285 | 225 | # Obtain the exception origin. |
paul@1285 | 226 | |
paul@49 | 227 | type, value, tb = sys.exc_info() |
paul@310 | 228 | while tb.tb_next: |
paul@310 | 229 | tb = tb.tb_next |
paul@310 | 230 | f = tb.tb_frame |
paul@310 | 231 | co = f and f.f_code |
paul@310 | 232 | filename = co and co.co_filename |
paul@1285 | 233 | |
paul@310 | 234 | print >>sys.stderr, "Exception %s at %d in %s" % (exc, tb.tb_lineno, filename) |
paul@1285 | 235 | |
paul@82 | 236 | #import traceback |
paul@82 | 237 | #traceback.print_exc(file=open("/tmp/mail.log", "a")) |
paul@1285 | 238 | |
paul@49 | 239 | sys.exit(EX_TEMPFAIL) |
paul@1285 | 240 | |
paul@49 | 241 | sys.exit(0) |
paul@49 | 242 | |
paul@604 | 243 | class Recipient(Client): |
paul@604 | 244 | |
paul@604 | 245 | "A processor acting as a client on behalf of a recipient." |
paul@604 | 246 | |
paul@1039 | 247 | def __init__(self, user, messenger, store, publisher, journal, preferences_dir, |
paul@1384 | 248 | handlers, outgoing_only, debug, output_only): |
paul@604 | 249 | |
paul@604 | 250 | """ |
paul@604 | 251 | Initialise the recipient with the given 'user' identity, 'messenger', |
paul@1384 | 252 | 'store', 'publisher', 'journal', 'preferences_dir', 'handlers', and with |
paul@1384 | 253 | the given 'outgoing_only', 'debug' and 'output_only' status. |
paul@604 | 254 | """ |
paul@604 | 255 | |
paul@1039 | 256 | Client.__init__(self, user, messenger, store, publisher, journal, preferences_dir) |
paul@607 | 257 | self.handlers = handlers |
paul@822 | 258 | self.outgoing_only = outgoing_only |
paul@607 | 259 | self.debug = debug |
paul@1384 | 260 | self.output_only = output_only |
paul@604 | 261 | |
paul@822 | 262 | def process(self, msg, senders): |
paul@604 | 263 | |
paul@604 | 264 | """ |
paul@604 | 265 | Process the given 'msg' for a single recipient, having the given |
paul@822 | 266 | 'senders'. |
paul@604 | 267 | |
paul@604 | 268 | Processing individually means that contributions to resulting messages |
paul@604 | 269 | may be constructed according to individual preferences. |
paul@604 | 270 | """ |
paul@604 | 271 | |
paul@1384 | 272 | handlers = get_handlers(self, self.handlers, senders) |
paul@604 | 273 | handled = False |
paul@604 | 274 | |
paul@667 | 275 | # Check for participating recipients. Non-participating recipients will |
paul@667 | 276 | # have their messages left as being unhandled. |
paul@667 | 277 | |
paul@1286 | 278 | if not is_returned_message(msg) and (self.outgoing_only or self.is_participating()): |
paul@667 | 279 | |
paul@1286 | 280 | # Handle parts. |
paul@665 | 281 | |
paul@665 | 282 | for part in msg.walk(): |
paul@1289 | 283 | if self.debug and have_itip_part(part): |
paul@1289 | 284 | print >>sys.stderr, "Handle method %s..." % part.get_param("method") |
paul@604 | 285 | |
paul@1289 | 286 | handled = handle_itip_part(part, handlers) or handled |
paul@604 | 287 | |
paul@604 | 288 | # When processing outgoing messages, no replies or deliveries are |
paul@604 | 289 | # performed. |
paul@604 | 290 | |
paul@822 | 291 | if self.outgoing_only: |
paul@604 | 292 | return |
paul@604 | 293 | |
paul@604 | 294 | # Get responses from the handlers. |
paul@604 | 295 | |
paul@604 | 296 | all_responses = [] |
paul@604 | 297 | for handler in handlers.values(): |
paul@604 | 298 | all_responses += handler.get_results() |
paul@604 | 299 | |
paul@604 | 300 | # Pack any returned parts into messages. |
paul@604 | 301 | |
paul@604 | 302 | if all_responses: |
paul@604 | 303 | outgoing_parts = {} |
paul@604 | 304 | forwarded_parts = [] |
paul@604 | 305 | |
paul@604 | 306 | for outgoing_recipients, part in all_responses: |
paul@604 | 307 | if outgoing_recipients: |
paul@604 | 308 | for outgoing_recipient in outgoing_recipients: |
paul@604 | 309 | if not outgoing_parts.has_key(outgoing_recipient): |
paul@604 | 310 | outgoing_parts[outgoing_recipient] = [] |
paul@604 | 311 | outgoing_parts[outgoing_recipient].append(part) |
paul@604 | 312 | else: |
paul@604 | 313 | forwarded_parts.append(part) |
paul@604 | 314 | |
paul@604 | 315 | # Reply using any outgoing parts in a new message. |
paul@604 | 316 | |
paul@604 | 317 | if outgoing_parts: |
paul@604 | 318 | |
paul@604 | 319 | # Obtain free/busy details, if configured to do so. |
paul@604 | 320 | |
paul@604 | 321 | fb = self.can_provide_freebusy(handlers) and self.get_freebusy_part() |
paul@604 | 322 | |
paul@604 | 323 | for outgoing_recipient, parts in outgoing_parts.items(): |
paul@604 | 324 | |
paul@604 | 325 | # Bundle free/busy messages, if configured to do so. |
paul@604 | 326 | |
paul@604 | 327 | if fb: parts.append(fb) |
paul@604 | 328 | message = self.messenger.make_outgoing_message(parts, [outgoing_recipient]) |
paul@604 | 329 | |
paul@607 | 330 | if self.debug: |
paul@604 | 331 | print >>sys.stderr, "Outgoing parts for %s..." % outgoing_recipient |
paul@604 | 332 | print message |
paul@604 | 333 | else: |
paul@604 | 334 | self.messenger.sendmail([outgoing_recipient], message.as_string()) |
paul@604 | 335 | |
paul@604 | 336 | # Forward messages to their recipients either wrapping the existing |
paul@604 | 337 | # message, accompanying it or replacing it. |
paul@604 | 338 | |
paul@604 | 339 | if forwarded_parts: |
paul@604 | 340 | |
paul@604 | 341 | # Determine whether to wrap, accompany or replace the message. |
paul@604 | 342 | |
paul@604 | 343 | prefs = self.get_preferences() |
paul@1212 | 344 | incoming = prefs.get("incoming", settings["INCOMING_DEFAULT"]) |
paul@604 | 345 | |
paul@604 | 346 | if incoming == "message-only": |
paul@604 | 347 | messages = [msg] |
paul@1384 | 348 | elif incoming == "summary-wraps-message": |
paul@1384 | 349 | messages = [self.messenger.wrap_message(msg, forwarded_parts)] |
paul@604 | 350 | else: |
paul@604 | 351 | summary = self.messenger.make_summary_message(msg, forwarded_parts) |
paul@604 | 352 | if incoming == "summary-then-message": |
paul@604 | 353 | messages = [summary, msg] |
paul@604 | 354 | elif incoming == "message-then-summary": |
paul@604 | 355 | messages = [msg, summary] |
paul@1384 | 356 | else: # incoming == "summary-only": |
paul@604 | 357 | messages = [summary] |
paul@604 | 358 | |
paul@604 | 359 | for message in messages: |
paul@607 | 360 | if self.debug: |
paul@604 | 361 | print >>sys.stderr, "Forwarded parts..." |
paul@1384 | 362 | |
paul@1384 | 363 | if self.debug or self.output_only: |
paul@604 | 364 | print message |
paul@607 | 365 | elif self.messenger.local_delivery(): |
paul@666 | 366 | self.messenger.sendmail([get_address(self.user)], message.as_string()) |
paul@604 | 367 | |
paul@604 | 368 | # Unhandled messages are delivered as they are. |
paul@604 | 369 | |
paul@604 | 370 | if not handled: |
paul@607 | 371 | if self.debug: |
paul@604 | 372 | print >>sys.stderr, "Unhandled parts..." |
paul@1384 | 373 | |
paul@1384 | 374 | if self.debug: |
paul@604 | 375 | print msg |
paul@1384 | 376 | elif self.output_only: |
paul@1384 | 377 | pass |
paul@607 | 378 | elif self.messenger.local_delivery(): |
paul@666 | 379 | self.messenger.sendmail([get_address(self.user)], msg.as_string()) |
paul@604 | 380 | |
paul@604 | 381 | def can_provide_freebusy(self, handlers): |
paul@604 | 382 | |
paul@604 | 383 | "Test for any free/busy information produced by 'handlers'." |
paul@604 | 384 | |
paul@604 | 385 | fbhandler = handlers.get("VFREEBUSY") |
paul@604 | 386 | if fbhandler: |
paul@604 | 387 | fbmethods = fbhandler.get_outgoing_methods() |
paul@604 | 388 | return not "REPLY" in fbmethods and not "PUBLISH" in fbmethods |
paul@604 | 389 | else: |
paul@604 | 390 | return False |
paul@604 | 391 | |
paul@1384 | 392 | # Handler construction using an existing client. |
paul@1384 | 393 | |
paul@1384 | 394 | def get_handlers(client, handler_items, senders=None): |
paul@1384 | 395 | |
paul@1384 | 396 | """ |
paul@1384 | 397 | Return instantiated handlers using the information provided by 'client' |
paul@1384 | 398 | plus the appropriate 'handler_items' and the 'senders' of a message. |
paul@1384 | 399 | """ |
paul@1384 | 400 | |
paul@1384 | 401 | handlers = {} |
paul@1384 | 402 | |
paul@1384 | 403 | # Instantiate handlers for the supported methods. |
paul@1384 | 404 | |
paul@1384 | 405 | for name, cls in handler_items: |
paul@1384 | 406 | handlers[name] = cls(senders, client.user and get_address(client.user), |
paul@1384 | 407 | client.messenger, client.store, client.publisher, |
paul@1384 | 408 | client.journal, client.preferences_dir) |
paul@1384 | 409 | |
paul@1384 | 410 | return handlers |
paul@1384 | 411 | |
paul@1312 | 412 | # Standard arguments used by imip-agent programs. |
paul@1312 | 413 | |
paul@1312 | 414 | def parse_args(args, extra_argdefs=None): |
paul@1312 | 415 | |
paul@1312 | 416 | """ |
paul@1312 | 417 | Interpret the given program arguments 'args'. Any 'extra_argdefs' define a |
paul@1312 | 418 | mapping from option arguments to (option name, starting value) tuples to be |
paul@1312 | 419 | considered in addition to (or as replacements for) the default definitions. |
paul@1312 | 420 | """ |
paul@1312 | 421 | |
paul@1312 | 422 | argdefs = { |
paul@1312 | 423 | "-d" : ("debug", False), |
paul@1312 | 424 | "-j" : ("journal_dir", None), |
paul@1312 | 425 | "-l" : ("lmtp", None), |
paul@1312 | 426 | "-L" : ("local_smtp", False), |
paul@1312 | 427 | "-o" : ("original_recipients", []), |
paul@1384 | 428 | "-O" : ("output_only", False), |
paul@1312 | 429 | "-p" : ("preferences_dir", None), |
paul@1312 | 430 | "-P" : ("publishing_dir", None), |
paul@1312 | 431 | "-s" : ("senders", []), |
paul@1312 | 432 | "-S" : ("store_dir", None), |
paul@1312 | 433 | "-T" : ("store_type", None), |
paul@1312 | 434 | } |
paul@1312 | 435 | |
paul@1312 | 436 | argdefs.update(extra_argdefs) |
paul@1312 | 437 | |
paul@1312 | 438 | l = [] |
paul@1312 | 439 | option = None |
paul@1312 | 440 | |
paul@1312 | 441 | for arg in args: |
paul@1312 | 442 | |
paul@1312 | 443 | # Set any selected option value. |
paul@1312 | 444 | |
paul@1312 | 445 | if option and argdefs.has_key(option): |
paul@1312 | 446 | name, value = argdefs[option] |
paul@1312 | 447 | argdefs[option] = name, arg |
paul@1312 | 448 | option = None |
paul@1312 | 449 | |
paul@1312 | 450 | # Where recognised, obtain the option name and value. |
paul@1312 | 451 | |
paul@1312 | 452 | elif argdefs.has_key(arg): |
paul@1312 | 453 | name, value = argdefs[arg] |
paul@1312 | 454 | |
paul@1312 | 455 | # For boolean options, invert the current value. |
paul@1312 | 456 | |
paul@1312 | 457 | if isinstance(value, bool): |
paul@1312 | 458 | argdefs[arg] = name, not value |
paul@1312 | 459 | |
paul@1312 | 460 | # For list options, switch to the given list and collect arguments. |
paul@1312 | 461 | |
paul@1312 | 462 | elif isinstance(value, list): |
paul@1312 | 463 | l = value |
paul@1312 | 464 | |
paul@1312 | 465 | # Otherwise, select the option. |
paul@1312 | 466 | |
paul@1312 | 467 | else: |
paul@1312 | 468 | option = arg |
paul@1312 | 469 | |
paul@1312 | 470 | # Where unrecognised, collect the argument in the current list. |
paul@1312 | 471 | |
paul@1312 | 472 | else: |
paul@1312 | 473 | l.append(arg) |
paul@1312 | 474 | |
paul@1312 | 475 | # Return a mapping from option names to values. |
paul@1312 | 476 | |
paul@1312 | 477 | return dict(argdefs.values()) |
paul@1312 | 478 | |
paul@1312 | 479 | def show_help(progname): |
paul@1312 | 480 | print >>sys.stderr, help_text % progname |
paul@1312 | 481 | |
paul@1312 | 482 | help_text = """\ |
paul@1312 | 483 | Usage: %s [ -o <recipient> ... ] [-s <sender> ... ] [ -l <socket> | -L ] \\ |
paul@1312 | 484 | [ -T <store type ] \\ |
paul@1312 | 485 | [ -S <store directory> ] [ -P <publishing directory> ] \\ |
paul@1312 | 486 | [ -p <preferences directory> ] [ -j <journal directory> ] \\ |
paul@1312 | 487 | [ -d ] [ --show-config ] |
paul@1312 | 488 | |
paul@1312 | 489 | Address options: |
paul@1312 | 490 | |
paul@1312 | 491 | -o Indicate the original recipients of the message, overriding any found in |
paul@1312 | 492 | the message headers |
paul@1312 | 493 | -s Indicate the senders of the message, overriding any found in the message |
paul@1312 | 494 | headers |
paul@1312 | 495 | |
paul@1312 | 496 | Delivery options: |
paul@1312 | 497 | |
paul@1312 | 498 | -l The socket filename for LMTP communication with a mailbox solution, |
paul@1312 | 499 | selecting the LMTP delivery method |
paul@1312 | 500 | -L Selects the local SMTP delivery method, requiring a suitable mail system |
paul@1312 | 501 | configuration |
paul@1312 | 502 | |
paul@1312 | 503 | (Where a program needs to deliver messages, one of the above options must be |
paul@1312 | 504 | specified.) |
paul@1312 | 505 | |
paul@1312 | 506 | Configuration options (overriding configured defaults): |
paul@1312 | 507 | |
paul@1312 | 508 | -j Indicates the location of quota-related journal information |
paul@1312 | 509 | -P Indicates the location of published free/busy resources |
paul@1312 | 510 | -p Indicates the location of user preference directories |
paul@1312 | 511 | -S Indicates the location of the calendar data store containing user storage |
paul@1312 | 512 | directories |
paul@1312 | 513 | -T Indicates the store and journal type (the configured value if omitted) |
paul@1312 | 514 | |
paul@1312 | 515 | Output options: |
paul@1312 | 516 | |
paul@1312 | 517 | -d Run in debug mode, producing informative output describing the behaviour |
paul@1312 | 518 | of the program, displaying responses on standard output instead of sending |
paul@1312 | 519 | messages |
paul@1384 | 520 | -O Run in output-only mode, producing handled incoming messages on standard |
paul@1384 | 521 | output instead of sending messages to the recipient (responses are sent as |
paul@1384 | 522 | normal, unhandled messages are discarded) |
paul@1312 | 523 | |
paul@1312 | 524 | Diagnostic options: |
paul@1312 | 525 | |
paul@1312 | 526 | --show-config Show the configuration with the specified options and exit |
paul@1312 | 527 | without performing any actions |
paul@1312 | 528 | """ |
paul@1312 | 529 | |
paul@49 | 530 | # vim: tabstop=4 expandtab shiftwidth=4 |