<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import netsvc
import tools
from osv import fields, osv

class partner_wizard_spam(osv.osv_memory):
    """ Mass Mailing """

    _name = "partner.wizard.spam"
    _description = "Mass Mailing"

    _columns = {
        'email_from': fields.char("Sender's email", size=256, required=True),
        'subject': fields.char('Subject', size=256,required=True),
        'text': fields.text('Message',required=True),
    }

    def mass_mail_send(self, cr, uid, ids, context):
        """
            Send Email

            @param cr: the current row, from the database cursor.
            @param uid: the current user’s ID for security checks.
            @param ids: the ID or list of IDs
            @param context: A standard dictionary
        """

        nbr = 0
        partner_pool = self.pool.get('res.partner')
        data = self.browse(cr, uid, ids, context=context)
        event_pool = self.pool.get('res.partner.event')
        active_ids = context and context.get('active_ids', [])
        partners = partner_pool.browse(cr, uid, active_ids, context)
        for partner in partners:
            for adr in partner.address:
                if adr.email:
                    name = adr.name or partner.name
                    to = '%s <%s>' % (name, adr.email)
    #TODO: add some tests to check for invalid email addresses
    #CHECKME: maybe we should use res.partner/email_send
                    tools.email_send(data.email_from, [to], data.subject, data.text,subtype='html')
                    nbr += 1
            event_pool.create(cr, uid,
                    {'name': 'Email sent through mass mailing',
                     'partner_id': partner.id,
                     'description': data.text })
    #TODO: log number of message sent
        return {'email_sent': nbr}

partner_wizard_spam()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:<commit_msg>[FIX] base : Partner's Spam email wizard fixed<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import netsvc
import tools
from osv import fields, osv

class partner_wizard_spam(osv.osv_memory):
    """ Mass Mailing """

    _name = "partner.wizard.spam"
    _description = "Mass Mailing"

    _columns = {
        'email_from': fields.char("Sender's email", size=256, required=True),
        'subject': fields.char('Subject', size=256,required=True),
        'text': fields.text('Message',required=True),
    }

    def mass_mail_send(self, cr, uid, ids, context):
        """
            Send Email

            @param cr: the current row, from the database cursor.
            @param uid: the current user’s ID for security checks.
            @param ids: the ID or list of IDs
            @param context: A standard dictionary
        """

        nbr = 0
        partner_pool = self.pool.get('res.partner')
        data = self.browse(cr, uid, ids[0], context=context)
        event_pool = self.pool.get('res.partner.event')
        active_ids = context and context.get('active_ids', [])
        partners = partner_pool.browse(cr, uid, active_ids, context)
        for partner in partners:
            for adr in partner.address:
                if adr.email:
                    name = adr.name or partner.name
                    to = '%s <%s>' % (name, adr.email)
    #TODO: add some tests to check for invalid email addresses
    #CHECKME: maybe we should use res.partner/email_send
                    tools.email_send(data.email_from, [to], data.subject, data.text,subtype='html')
                    nbr += 1
            event_pool.create(cr, uid,
                    {'name': 'Email(s) sent through mass mailing',
                     'partner_id': partner.id,
                     'description': data.text })
    #TODO: log number of message sent
        return {'email_sent': nbr}

partner_wizard_spam()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
{'fraction_non_alphanumeric': 0.14995700773860704, 'fraction_numerical': 0.007394668959587274, 'mean_word_length': 2.648682559598494, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139270', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1573, 'n_words': 541}