view data/plugin/action/submitemail.py @ 622:12465aa315be

add code from ActionMarket/FormSubmit (form_submit-1.7.tar.gz) - outdated code for moin 1.7/1.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 25 Mar 2013 17:09:15 +0100
parents
children 5f499a634857
line wrap: on
line source
# -*- coding: iso-8859-1 -*-

"""
    MoinMoin - submitemail Action
    
    Send submited data email address specified in targetemail CGI parameter

    @copyright: 2008 by Peter Bodi <petrdll@centrum.sk>
    @license: GNU GPL, see COPYING for details.
"""

import os, sys, codecs

from MoinMoin import wikiutil
from MoinMoin.action import ActionBase
from MoinMoin.Page import Page
from MoinMoin.mail.sendmail import sendmail

from submitbase import SubmitBase

def execute(pagename, request):
    submitemail(pagename, request).render()

class submitemail(SubmitBase):          
    
    def __init__(self, pagename, request):
        SubmitBase.__init__(self, pagename, request)
        
        self.targetemail = ""
        self.subject = "Moinmoin mail"
        
        if(request.form.has_key("targetemail")):
            self.targetemail = request.form.get("targetemail")[0]
        
    def build_content(self):
        """ Builds simple 'label: value' string """
        text = ""
        for label in self.labels:
            index = self.labels.index(label)
            label = label.decode('utf-8')
            value = self.values[index]
            text += "%(label)s: %(value)s \n" % {'label': label, 'value':value}
        
        return text
        
    def submit(self):
        SubmitBase.submit(self)   
        text = self.build_content()
        status, msg = sendmail(self.request, self.targetemail, self.subject, text, mail_from=self.targetemail)
        self.msg = self._(msg)
        if status!=1:
            raise Exception(self.msg)