1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17  """ 
 18  Text based news notifier 
 19  """ 
 20  __author__    = "André Malo" 
 21  __docformat__ = "epytext en" 
 22  __all__       = ['TextNewsNotifier'] 
 23   
 24   
 25  from svnmailer.notifier import _textmail, _mail 
 26   
 27   
 29      """ Returns an initialized notifier or nothing 
 30   
 31          @param cls: The notifier base class to use 
 32          @type cls: C{class} 
 33   
 34          @param settings: The svnmailer settings 
 35          @type settings: C{svnmailer.settings.Settings} 
 36   
 37          @param groupset: The groupset to process 
 38          @type groupset: C{list} 
 39   
 40          @return: The list of notifiers (containing 0 or 1 member) 
 41          @rtype: C{list} 
 42      """ 
 43      from svnmailer import util 
 44   
 45      return [_textmail.decorateNotifier( 
 46          util.inherit(cls, TextNewsNotifier), 
 47          groupset.groups[0].long_news_action, settings, groupset 
 48      )] 
  49   
 50   
 51 -class TextNewsNotifier(_textmail.TextMailNotifier): 
  52      """ Bases class for news notifiers """ 
 53      __implements__ = [_textmail.TextMailNotifier] 
 54   
 55 -    def sendMail(self, sender, to_addr, mail): 
  56          """ Sends the news 
 57   
 58              @param sender: The mail sender (envelope from) 
 59              @type sender: C{str} 
 60   
 61              @param to_addr: The receivers 
 62              @type to_addr: C{list} 
 63   
 64              @param mail: The mail object 
 65              @type mail: C{_TextMail} 
 66          """ 
 67          self.sendNews(mail) 
  68   
 69   
 70 -    def sendNews(self, posting): 
  71          """ Sends the news 
 72   
 73              @param posting: The posting object 
 74              @type posting: C{_textmail._TextMail} 
 75          """ 
 76          raise NotImplementedError() 
  77   
 78   
 80          """ Returns the news transfer encoding """ 
 81          return self.config.news_transfer_encoding 
  82   
 83   
 85          """ Compose the informational headers of the mail 
 86   
 87              @param groups: The groups to process 
 88              @type groups: C{list} 
 89   
 90              @return: sender (C{unicode}), recipients (C{list}), headers 
 91                  (C{dict}) 
 92              @rtype: C{tuple} 
 93          """ 
 94          from email import Header 
 95   
 96          sender, from_addrs, to_newsgroups, reply_to = \ 
 97              self.getNewsAddresses(groups) 
 98          if not to_newsgroups: 
 99              raise _mail.NoRecipientsError() 
100   
101          headers = self.getBasicHeaders() 
102          headers['From'] = from_addrs[0] 
103          headers['Newsgroups'] = Header.Header(','.join(to_newsgroups)) 
104   
105          if reply_to: 
106              headers['Reply-To'] = Header.Header(', '.join(reply_to)) 
107          if len(from_addrs) > 1: 
108               
109              headers['Sender'] = Header.Header(from_addrs[0]) 
110   
111           
112   
113          if self._settings.runtime.debug: 
114              headers['X-Config-Groups'] = Header.Header(', '.join([ 
115                  "[%s]" % group._name for group in groups 
116              ]), 'iso-8859-1') 
117   
118          return (sender, to_newsgroups, headers) 
 119   
120   
121 -    def getNewsAddresses(self, groups): 
 122          """ Returns the substituted mail addresses (from/to/reply-to) 
123   
124              @param groups: The groups to process 
125              @type groups: C{list} 
126   
127              @return: The address lists (sender, from, to, reply-to) 
128              @rtype: C{tuple} 
129          """ 
130          from_addrs = [] 
131          to_newsgroups = [] 
132          reply_to = [] 
133   
134          sender = None 
135          for group in groups: 
136              from_addrs.extend(group.from_addr or []) 
137              to_newsgroups.extend(group.to_newsgroup or []) 
138              reply_to.extend( 
139                  group.reply_to_addr and [group.reply_to_addr] or [] 
140              ) 
141   
142          from_addrs = dict.fromkeys(from_addrs).keys() or [ 
143              (self.getAuthor() and self.getAuthor().decode('utf-8', 'replace')) 
144              or u'no_author' 
145          ] 
146          to_newsgroups = dict.fromkeys(to_newsgroups).keys() 
147          reply_to = dict.fromkeys(reply_to).keys() 
148   
149          return (sender or from_addrs[0], from_addrs, to_newsgroups, reply_to) 
  150