diff -r 000000000000 -r a3b6e531f0d2 iro/anbieter/geonet.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iro/anbieter/geonet.py Thu Oct 22 10:00:01 2009 +0200 @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +#Copyright (C) 2009 Sandro Knauß + +#This program is free software; you can redistribute it and/or modify it under the terms +#of the GNU General Public License as published by the Free Software Foundation; +#either version 3 of the License, or any later version. +#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +#See the GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program; if not, see . + +from smtp import SMTP +from anbieter import anbieter +from telnumber import telnumber + +from email import Encoders +from email.MIMEMultipart import MIMEMultipart +from email.MIMEBase import MIMEBase +from email.MIMEText import MIMEText + +class Mail(MIMEMultipart): + def __init__(self,send_from,header,cont,attachments): + MIMEMultipart.__init__(self) + self['From'] = send_from + self['Subject']=header + self.attach(MIMEText(cont)) + for attachment in attachments: + part = MIMEBase('application', mimetypes.guess_type(attachment)[0]) + part.set_payload( open(attachment,"rb").read() ) + Encoders.encode_base64(part) + art.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) + self.attach(part) + +class geonet(anbieter): + section="geonet" + default_conf="iro.conf" + max_recipients=50 + + def __init__(self): + self.smtp=SMTP(self.default_conf,self.section) + + def createMailaddress(produkt,number): + try: + tel=telnum(number) + return "%s%s@%s.geonet.de" %(tel.land,tel.number,produkt) + except: + return number + + def sendSMS(self,sms,recipients): + recps=[] + for recpipient in recipients: + recps.append(self.createMailadress(recpipient)) + self.sendMail(Mail(self.smtp.send_from,sms.content,"",[]),recps) + + def sendFAX(self,fax,recipients): + recps=[] + for recpipient in recipients: + recps.append(self.createMailadress(recpipient)) + self.sendMail(Mail(self.smtp.send_from,"","",fax.attachments),recps)