diff options
| author | Thibault Delavallée <tde@openerp.com> | 2013-05-22 13:40:07 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2013-05-22 13:40:07 +0200 |
| commit | d4d6e882668cfdc7c4634a0e30a047d0c83c75a7 (patch) | |
| tree | bd23f90705bc7ea3ad284b44f49a79be9b2dce93 | |
| parent | 0d01d958fa5cc28bdc9cf1fc13e0c9dbe530d78f (diff) | |
| parent | faefb9fad17d02a7da941703c92e5651fb788c25 (diff) | |
[IMP] [IMP] mail: now defines a catchall email alias, used to format the
reply_to of notification emails when having a document without alias, or for
private discussions.
bzr revid: tde@openerp.com-20130522114007-vlbkzghz278545zn
| -rw-r--r-- | addons/base_setup/res_config_view.xml | 2 | ||||
| -rw-r--r-- | addons/fetchmail/fetchmail_view.xml | 20 | ||||
| -rw-r--r-- | addons/mail/data/mail_data.xml | 6 | ||||
| -rw-r--r-- | addons/mail/mail_mail.py | 36 | ||||
| -rw-r--r-- | addons/mail/res_config.py | 3 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_features.py | 4 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_gateway.py | 100 |
7 files changed, 145 insertions, 26 deletions
diff --git a/addons/base_setup/res_config_view.xml b/addons/base_setup/res_config_view.xml index 9e026184c9d..8c48f5d7a6b 100644 --- a/addons/base_setup/res_config_view.xml +++ b/addons/base_setup/res_config_view.xml @@ -31,7 +31,7 @@ <group> <label for="id" string="Email"/> <div name="email"> - <div> + <div name="email.outgoing_server"> <button type="action" name="%(base.action_ir_mail_server_list)d" string="Configure outgoing email servers" class="oe_link"/> diff --git a/addons/fetchmail/fetchmail_view.xml b/addons/fetchmail/fetchmail_view.xml index 4e653adce28..5ee17c61b6f 100644 --- a/addons/fetchmail/fetchmail_view.xml +++ b/addons/fetchmail/fetchmail_view.xml @@ -97,15 +97,17 @@ <record id="inherit_view_general_configuration" model="ir.ui.view"> <field name="name">General Settings</field> <field name="model">base.config.settings</field> - <field name="inherit_id" ref="base_setup.view_general_configuration"/> - <field name="arch" type="xml"> - <div name="email" position="inside"> - <button type="action" - name="%(action_email_server_tree)d" - string="Configure the incoming email gateway" class="oe_link"/> - </div> - </field> - </record> + <field name="inherit_id" ref="base_setup.view_general_configuration"/> + <field name="arch" type="xml"> + <div name="email.outgoing_server" position="after"> + <div name="email.incoming_server"> + <button type="action" + name="%(action_email_server_tree)d" + string="Configure the incoming email gateway" class="oe_link"/> + </div> + </div> + </field> + </record> <menuitem diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml index 02cfd626768..4e935e4aa88 100644 --- a/addons/mail/data/mail_data.xml +++ b/addons/mail/data/mail_data.xml @@ -40,6 +40,12 @@ <field name="args">()</field> </record> + <!-- Catchall Email Alias --> + <record id="icp_mail_catchall_alias" model="ir.config_parameter"> + <field name="key">mail.catchall.alias</field> + <field name="value">catchall</field> + </record> + <!-- Discussion subtype for messaging / Chatter --> <record id="mt_comment" model="mail.message.subtype"> <field name="name">Discussions</field> diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 95fbac478d6..22fa7815c5e 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -93,31 +93,41 @@ class mail_mail(osv.Model): """ Return a specific reply_to: alias of the document through message_get_reply_to or take the email_from """ + # if value specified: directly return it if values.get('reply_to'): return values.get('reply_to') - email_reply_to = False - # model, res_id: comes from values OR related message - model = values.get('model') - res_id = values.get('res_id') - if values.get('mail_message_id') and (not model or not res_id): + mailgateway = True # tells whether the answer will go through the mailgateway, leading to the formatting of reply_to <Followers of ...> + ir_config_parameter = self.pool.get("ir.config_parameter") + catchall_domain = ir_config_parameter.get_param(cr, uid, "mail.catchall.domain", context=context) + + # model, res_id, email_from, reply_to: comes from values OR related message + message = None + if values.get('mail_message_id'): message = self.pool.get('mail.message').browse(cr, uid, values.get('mail_message_id'), context=context) - if not model: - model = message.model - if not res_id: - res_id = message.res_id + model = values.get('model', message and message.model or False) + res_id = values.get('res_id', message and message.res_id or False) + email_from = values.get('email_from', message and message.email_from or False) + email_reply_to = message and message.reply_to or False # if model and res_id: try to use ``message_get_reply_to`` that returns the document alias - if model and res_id and hasattr(self.pool[model], 'message_get_reply_to'): + if not email_reply_to and model and res_id and hasattr(self.pool[model], 'message_get_reply_to'): email_reply_to = self.pool[model].message_get_reply_to(cr, uid, [res_id], context=context)[0] + # no alias reply_to -> catchall alias + if not email_reply_to: + catchall_alias = ir_config_parameter.get_param(cr, uid, "mail.catchall.alias", context=context) + if catchall_domain and catchall_alias: + email_reply_to = '%s@%s' % (catchall_alias, catchall_domain) # no alias reply_to -> reply_to will be the email_from, only the email part - if not email_reply_to and values.get('email_from'): - emails = tools.email_split(values.get('email_from')) + if not email_reply_to and email_from: + emails = tools.email_split(email_from) if emails: email_reply_to = emails[0] + if emails[0].split('@')[1] != catchall_domain: + mailgateway = False # format 'Document name <email_address>' - if email_reply_to and model and res_id: + if email_reply_to and model and res_id and mailgateway: document_name = self.pool[model].name_get(cr, SUPERUSER_ID, [res_id], context=context)[0] if document_name: # sanitize document name diff --git a/addons/mail/res_config.py b/addons/mail/res_config.py index 91606e1c720..c19eb4a38ee 100644 --- a/addons/mail/res_config.py +++ b/addons/mail/res_config.py @@ -23,11 +23,12 @@ import urlparse from openerp.osv import osv, fields + class project_configuration(osv.TransientModel): _inherit = 'base.config.settings' _columns = { - 'alias_domain' : fields.char('Alias Domain', + 'alias_domain': fields.char('Alias Domain', help="If you have setup a catch-all email domain redirected to " "the OpenERP server, enter the domain name here."), } diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py index e1bef837010..678e4398da4 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -419,8 +419,8 @@ class test_mail(TestMailBase): 'message_post: notification email sent to more than one email address instead of a precise partner') self.assertIn(sent_email['email_to'][0], test_emailto, 'message_post: notification email email_to incorrect') - self.assertEqual(sent_email['reply_to'], '"Followers of Pigs" <r@r>', - 'message_post: notification email reply_to incorrect: should name Followers of Pigs, and have raoul email') + self.assertEqual(sent_email['reply_to'], 'r@r', # was '"Followers of Pigs" <r@r>', but makes no sense + 'message_post: notification email reply_to incorrect: should have raoul email') self.assertEqual(_mail_subject, sent_email['subject'], 'message_post: notification email subject incorrect') self.assertIn(html_sanitize(_body2), sent_email['body'], diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index e4269d59d8b..4a8571c30b3 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -123,6 +123,106 @@ class TestMailgateway(TestMailBase): self.assertEqual(partner_info['partner_id'], p_b_id, 'mail_thread: message_find_partner_from_emails wrong partner found') + def test_05_mail_message_mail_mail(self): + """ Tests designed for testing email values based on mail.message, aliases, ... """ + cr, uid = self.cr, self.uid + + # Data: clean catchall domain + param_ids = self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.domain')]) + self.registry('ir.config_parameter').unlink(cr, uid, param_ids) + + # Do: create a mail_message with a reply_to, without message-id + msg_id = self.mail_message.create(cr, uid, {'subject': 'Subject', 'body': 'Body', 'reply_to': 'custom@example.com'}) + msg = self.mail_message.browse(cr, uid, msg_id) + # Test: message content + self.assertIn('reply_to', msg.message_id, + 'mail_message: message_id should be specific to a mail_message with a given reply_to') + self.assertEqual('custom@example.com', msg.reply_to, + 'mail_message: incorrect reply_to') + # Do: create a mail_mail with the previous mail_message and specified reply_to + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'reply_to': 'other@example.com', 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, 'other@example.com', + 'mail_mail: reply_to should be equal to the one coming from creation values') + # Do: create a mail_mail with the previous mail_message + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, msg.reply_to, + 'mail_mail: reply_to should be equal to the one coming from the mail_message') + + # Do: create a mail_message without a reply_to + msg_id = self.mail_message.create(cr, uid, {'subject': 'Subject', 'body': 'Body', 'model': 'mail.group', 'res_id': self.group_pigs_id, 'email_from': False}) + msg = self.mail_message.browse(cr, uid, msg_id) + # Test: message content + self.assertIn('mail.group', msg.message_id, + 'mail_message: message_id should contain model') + self.assertIn('%s' % self.group_pigs_id, msg.message_id, + 'mail_message: message_id should contain res_id') + self.assertFalse(msg.reply_to, + 'mail_message: should not generate a reply_to address when not specified') + # Do: create a mail_mail based on the previous mail_message + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertFalse(mail.reply_to, + 'mail_mail: reply_to should not have been guessed') + # Update message + self.mail_message.write(cr, uid, [msg_id], {'email_from': 'someone@example.com'}) + msg.refresh() + # Do: create a mail_mail based on the previous mail_message + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, msg.email_from, + 'mail_mail: reply_to should equal to mail_message.email_from when having no document or default alias') + + # Data: set catchall domain + self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', 'schlouby.fr') + self.registry('ir.config_parameter').unlink(cr, uid, self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.alias')])) + + # Do: create a mail_mail based on the previous mail_message + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, '"Followers of Pigs" <group+pigs@schlouby.fr>', + 'mail_mail: reply_to should equal the mail.group alias') + + # Update message + self.mail_message.write(cr, uid, [msg_id], {'res_id': False, 'email_from': 'someone@schlouby.fr'}) + msg.refresh() + # Do: create a mail_mail based on the previous mail_message + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, msg.email_from, + 'mail_mail: reply_to should equal the mail_message email_from') + + # Data: set catchall alias + self.registry('ir.config_parameter').set_param(self.cr, self.uid, 'mail.catchall.alias', 'gateway') + + # Do: create a mail_mail based on the previous mail_message + mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, 'gateway@schlouby.fr', + 'mail_mail: reply_to should equal the catchall email alias') + + # Do: create a mail_mail + mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, 'gateway@schlouby.fr', + 'mail_mail: reply_to should equal the catchall email alias') + + # Do: create a mail_mail + mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel', 'reply_to': 'someone@example.com'}) + mail = self.mail_mail.browse(cr, uid, mail_id) + # Test: mail_mail content + self.assertEqual(mail.reply_to, 'someone@example.com', + 'mail_mail: reply_to should equal the rpely_to given to create') + def test_10_message_process(self): """ Testing incoming emails processing. """ cr, uid, user_raoul = self.cr, self.uid, self.user_raoul |
