iro/anbieter/geonet.py
changeset 0 a3b6e531f0d2
equal deleted inserted replaced
-1:000000000000 0:a3b6e531f0d2
       
     1 # -*- coding: utf-8 -*-
       
     2 #Copyright (C) 2009  Sandro Knauß <bugs@sandroknauss.de>
       
     3 
       
     4 #This program is free software; you can redistribute it and/or modify it under the terms
       
     5 #of the GNU General Public License as published by the Free Software Foundation;
       
     6 #either version 3 of the License, or any later version.
       
     7 #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
       
     8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       
     9 #See the GNU General Public License for more details.
       
    10 
       
    11 #You should have received a copy of the GNU General Public License
       
    12 #along with this program; if not, see <http://www.gnu.org/licenses/>.
       
    13 
       
    14 from smtp import SMTP
       
    15 from anbieter import anbieter
       
    16 from telnumber import telnumber
       
    17 
       
    18 from email import Encoders
       
    19 from email.MIMEMultipart import MIMEMultipart
       
    20 from email.MIMEBase import MIMEBase
       
    21 from email.MIMEText import MIMEText
       
    22 
       
    23 class Mail(MIMEMultipart):
       
    24     def __init__(self,send_from,header,cont,attachments):
       
    25         MIMEMultipart.__init__(self)
       
    26         self['From'] = send_from
       
    27         self['Subject']=header
       
    28         self.attach(MIMEText(cont))
       
    29         for attachment in attachments:
       
    30             part = MIMEBase('application', mimetypes.guess_type(attachment)[0])
       
    31             part.set_payload( open(attachment,"rb").read() )
       
    32             Encoders.encode_base64(part)
       
    33             art.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
       
    34             self.attach(part)
       
    35 
       
    36 class geonet(anbieter):
       
    37     section="geonet"
       
    38     default_conf="iro.conf"
       
    39     max_recipients=50
       
    40 
       
    41     def __init__(self):
       
    42         self.smtp=SMTP(self.default_conf,self.section)
       
    43 
       
    44     def createMailaddress(produkt,number):
       
    45         try:
       
    46             tel=telnum(number)
       
    47             return "%s%s@%s.geonet.de" %(tel.land,tel.number,produkt)
       
    48         except:
       
    49             return number
       
    50 
       
    51     def sendSMS(self,sms,recipients):
       
    52         recps=[]
       
    53         for recpipient in recipients:
       
    54             recps.append(self.createMailadress(recpipient))
       
    55         self.sendMail(Mail(self.smtp.send_from,sms.content,"",[]),recps)
       
    56 
       
    57     def sendFAX(self,fax,recipients):
       
    58         recps=[]
       
    59         for recpipient in recipients:
       
    60             recps.append(self.createMailadress(recpipient))
       
    61         self.sendMail(Mail(self.smtp.send_from,"","",fax.attachments),recps)