view MoinMoin/i18n/ @ 61:b29594d7d381

revert mail Header() changes imported from: moin--main--1.5--patch-63
author Thomas Waldmann <>
date Fri, 30 Sep 2005 18:17:53 +0000
parents 26270b13f6df
children b39b2ed6574c
line wrap: on
line source

#!/usr/bin/env python
    read mail text from standard input and 
    send an email to all i18n maintainers
    %(lang)s will be replaced by language
    @copyright: 2004 Thomas Waldmann
    @license: GNU GPL, see COPYING for details

mail_from = ''
mail_subject = 'MoinMoin i18n notification'

mail_smarthost = 'localhost'
mail_login = None
charset = 'iso-8859-1'

from meta import languages

def sendmail(mfrom, mto, subject, text):
    Send a mail to the address(es) in 'to', with the given subject and
    mail body 'text'.
    Return a tuple of success or error indicator and message.

    TODO: code duplicated from MoinMoin/util/
    @param mfrom: source email address
    @param to: target email address
    @param subject: subject of email
    @param text: email body text
    @rtype: tuple
    @return: (is_ok, msg)
    import smtplib, socket, os
    from email.MIMEText import MIMEText
    from email.Header import Header
    from email.Utils import formatdate
    global charset, mail_smarthost, mail_login
    # Create a text/plain message
    msg = MIMEText(text, 'plain', charset)
    msg['From'] = mfrom
    msg['To'] = ', '.join(mto)
    msg['Subject'] = Header(subject, charset)
    msg['Date'] = formatdate()
        server = smtplib.SMTP(mail_smarthost)
            if mail_login:
                user, pwd = mail_login.split()
                server.login(user, pwd)
            server.sendmail(mail_from, mto, msg.as_string())
            except AttributeError:
                # in case the connection failed, SMTP has no "sock" attribute
    except smtplib.SMTPException, e:
        return (0, str(e))
    except (os.error, socket.error), e:
        return (0, "Connection to mailserver '%(server)s' failed: %(reason)s" % {
            'server': mail_smarthost, 
            'reason': str(e)

    return (1, "Mail sent OK")

def notify_maintainer(lang, mail_text):
    mailaddr = languages[lang][4]
    rc = None
    if mailaddr and mailaddr.find('***vacant***') < 0:
        text = mail_text % locals()
        rc = sendmail(mail_from, [mailaddr], mail_subject, text)
    return rc

if __name__ == '__main__':
    langs = languages.keys()
    langs.remove('en') # nothing to do for english, so remove it

    #langs = ['da', 'hr', 'ja', 'nb', 'pt', 'sr', 'sv', ] # for testing

    import sys
    mail_text =

    if len(mail_text) > 10: # do not send mails w/o real content
        for lang in langs:
            notify_maintainer(lang, mail_text)