imip-agent

Change of imiptools/__init__.py

1039:a12150034cbd
imiptools/__init__.py
     1.1 --- a/imiptools/__init__.py	Sun Feb 07 23:35:20 2016 +0100
     1.2 +++ b/imiptools/__init__.py	Mon Feb 08 00:14:53 2016 +0100
     1.3 @@ -3,7 +3,7 @@
     1.4  """
     1.5  A processing framework for iMIP content.
     1.6  
     1.7 -Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
     1.8 +Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
     1.9  
    1.10  This program is free software; you can redistribute it and/or modify it under
    1.11  the terms of the GNU General Public License as published by the Free Software
    1.12 @@ -58,6 +58,7 @@
    1.13          self.lmtp_socket = None
    1.14          self.store_dir = None
    1.15          self.publishing_dir = None
    1.16 +        self.journal_dir = None
    1.17          self.preferences_dir = None
    1.18          self.debug = False
    1.19  
    1.20 @@ -67,6 +68,9 @@
    1.21      def get_publisher(self):
    1.22          return self.publishing_dir and imip_store.FilePublisher(self.publishing_dir) or None
    1.23  
    1.24 +    def get_journal(self):
    1.25 +        return imip_store.FileJournal(self.journal_dir)
    1.26 +
    1.27      def process(self, f, original_recipients):
    1.28  
    1.29          """
    1.30 @@ -80,6 +84,7 @@
    1.31          messenger = self.messenger
    1.32          store = self.get_store()
    1.33          publisher = self.get_publisher()
    1.34 +        journal = self.get_journal()
    1.35          preferences_dir = self.preferences_dir
    1.36  
    1.37          # Handle messages with iTIP parts.
    1.38 @@ -89,7 +94,7 @@
    1.39          if not self.outgoing_only:
    1.40              original_recipients = original_recipients or get_addresses(get_all_values(msg, "To") or [])
    1.41              for recipient in original_recipients:
    1.42 -                Recipient(get_uri(recipient), messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
    1.43 +                Recipient(get_uri(recipient), messenger, store, publisher, journal, preferences_dir, self.handlers, self.outgoing_only, self.debug
    1.44                           ).process(msg, senders)
    1.45  
    1.46          # However, outgoing messages do not usually presume anything about the
    1.47 @@ -101,7 +106,7 @@
    1.48  
    1.49          else:
    1.50              senders = [sender for sender in get_addresses(get_all_values(msg, "From") or []) if sender != config.MESSAGE_SENDER]
    1.51 -            Recipient(senders and senders[0] or None, messenger, store, publisher, preferences_dir, self.handlers, self.outgoing_only, self.debug
    1.52 +            Recipient(senders and senders[0] or None, messenger, store, publisher, journal, preferences_dir, self.handlers, self.outgoing_only, self.debug
    1.53                       ).process(msg, senders)
    1.54  
    1.55      def process_args(self, args, stream):
    1.56 @@ -120,6 +125,7 @@
    1.57          store_dir = []
    1.58          publishing_dir = []
    1.59          preferences_dir = []
    1.60 +        journal_dir = []
    1.61          local_smtp = False
    1.62  
    1.63          l = []
    1.64 @@ -161,6 +167,11 @@
    1.65              elif arg == "-p":
    1.66                  l = preferences_dir
    1.67  
    1.68 +            # Switch to getting the journal directory.
    1.69 +
    1.70 +            elif arg == "-j":
    1.71 +                l = journal_dir
    1.72 +
    1.73              # Ignore debugging options.
    1.74  
    1.75              elif arg == "-d":
    1.76 @@ -172,6 +183,7 @@
    1.77          self.store_dir = store_dir and store_dir[0] or None
    1.78          self.publishing_dir = publishing_dir and publishing_dir[0] or None
    1.79          self.preferences_dir = preferences_dir and preferences_dir[0] or None
    1.80 +        self.journal_dir = journal_dir and journal_dir[0] or None
    1.81          self.process(stream, original_recipients)
    1.82  
    1.83      def __call__(self):
    1.84 @@ -187,7 +199,7 @@
    1.85              print >>sys.stderr, """\
    1.86  Usage: %s [ -o <recipient> ... ] [-s <sender> ... ] [ -l <socket> | -L ] \\
    1.87           [ -S <store directory> ] [ -P <publishing directory> ] \\
    1.88 -         [ -p <preferences directory> ] [ -d ]
    1.89 +         [ -p <preferences directory> ] [ -j <journal directory> ] [ -d ]
    1.90  
    1.91  Address options:
    1.92  
    1.93 @@ -208,10 +220,11 @@
    1.94  
    1.95  Configuration options:
    1.96  
    1.97 +-j  Indicates the location of quota-related journal information
    1.98 +-P  Indicates the location of published free/busy resources
    1.99 +-p  Indicates the location of user preference directories
   1.100  -S  Indicates the location of the calendar data store containing user storage
   1.101      directories
   1.102 --P  Indicates the location of published free/busy resources
   1.103 --p  Indicates the location of user preference directories
   1.104  
   1.105  Output options:
   1.106  
   1.107 @@ -244,15 +257,16 @@
   1.108  
   1.109      "A processor acting as a client on behalf of a recipient."
   1.110  
   1.111 -    def __init__(self, user, messenger, store, publisher, preferences_dir, handlers, outgoing_only, debug):
   1.112 +    def __init__(self, user, messenger, store, publisher, journal, preferences_dir,
   1.113 +                 handlers, outgoing_only, debug):
   1.114  
   1.115          """
   1.116          Initialise the recipient with the given 'user' identity, 'messenger',
   1.117 -        'store', 'publisher', 'preferences_dir', 'handlers', 'outgoing_only' and
   1.118 -        'debug' status.
   1.119 +        'store', 'publisher', 'journal', 'preferences_dir', 'handlers',
   1.120 +        'outgoing_only' and 'debug' status.
   1.121          """
   1.122  
   1.123 -        Client.__init__(self, user, messenger, store, publisher, preferences_dir)
   1.124 +        Client.__init__(self, user, messenger, store, publisher, journal, preferences_dir)
   1.125          self.handlers = handlers
   1.126          self.outgoing_only = outgoing_only
   1.127          self.debug = debug
   1.128 @@ -269,7 +283,7 @@
   1.129  
   1.130          handlers = dict([(name, cls(senders, self.user and get_address(self.user),
   1.131                                      self.messenger, self.store, self.publisher,
   1.132 -                                    self.preferences_dir))
   1.133 +                                    self.journal, self.preferences_dir))
   1.134                           for name, cls in self.handlers])
   1.135          handled = False
   1.136