Esempio n. 1
0
 def send(self):
     sender = self.getaddrs('from')
     if sender:
         if len(sender) > 1:
             raise Errors.MessageError(
                 'More than one sender specified: %s' % (', '.join(sender)))
         else:
             sender = sender[0]
     recipients = self.getaddrs('to', 'cc')
     if not recipients:
         raise ValueError('no recipients specified')
     if not self.has_key('subject'):
         self.add_header('subject', ' '.join(sys.argv))
     for sm_path in self.sm_path_try:
         if os.path.exists(sm_path):
             sendmail = sm_path
             break
     else:
         raise ValueError('sendmail not found')
     args = [sendmail]
     if sender:
         args.append('-f' + sender)
     args.extend(recipients)
     sm = os.popen(' '.join(args), 'w')
     try:
         sm.write(self.as_string(unixfrom=False))
     finally:
         if sm.close():
             print >> sys.stderr, 'command failed: %s' % ' '.join(args)
Esempio n. 2
0
 def getaddrs(self, *hdrs):
     addrs = []
     for hdr in hdrs:
         for cmt, addr in Utils.getaddresses(self.get_all(hdr, [])):
             try:
                 valid_addr(addr)
             except Errors.MessageError, e:
                 raise Errors.MessageError('%s: %s' % (hdr, e))
             addrs.append(addr)
Esempio n. 3
0
def valid_addr(addr):
    if not value_addr_re.match(addr):
        raise Errors.MessageError('invalid address %r' % addr)