iro/anbieter/geonet.py
author Sandro Knauß <knauss@netzguerilla.net>
Thu, 22 Oct 2009 10:00:01 +0200
changeset 0 a3b6e531f0d2
permissions -rw-r--r--
[svn r93] creating iro package branch

# -*- coding: utf-8 -*-
#Copyright (C) 2009  Sandro Knauß <bugs@sandroknauss.de>

#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 <http://www.gnu.org/licenses/>.

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)