From 1513a9ae77e9cba0909cfb97da4f5548b7012da1 Mon Sep 17 00:00:00 2001 From: "YSA (Openerp)" Date: Tue, 1 Feb 2011 17:13:08 +0530 Subject: [PATCH 01/58] [IMP] clean email_template module, merge email_template and mail_gateway module, developed email_gateway module. task ID-2007. bzr revid: ysa@tinyerp.com-20110201114308-nwb7qzj8ko99eerw --- addons/{mail_gateway => email}/__init__.py | 3 +- addons/email/__openerp__.py | 46 ++++ .../email_smtp_server.py} | 106 +++----- .../email_smtp_server_view.xml} | 55 ++--- .../email/email_template_scheduler_data.xml | 15 ++ .../email_view.xml} | 0 .../mail_gateway.py => email/emails.py} | 2 +- addons/{mail_gateway => email}/i18n/de.po | 0 addons/{mail_gateway => email}/i18n/es.po | 0 addons/{mail_gateway => email}/i18n/fr.po | 0 addons/{mail_gateway => email}/i18n/hu.po | 0 addons/{mail_gateway => email}/i18n/it.po | 0 addons/{mail_gateway => email}/i18n/lt.po | 0 addons/{mail_gateway => email}/i18n/lv.po | 0 .../i18n/mail_gateway.pot | 0 addons/{mail_gateway => email}/i18n/nl.po | 0 addons/{mail_gateway => email}/i18n/pl.po | 0 addons/{mail_gateway => email}/i18n/pt.po | 0 addons/{mail_gateway => email}/i18n/pt_BR.po | 0 addons/{mail_gateway => email}/i18n/ro.po | 0 addons/{mail_gateway => email}/i18n/ru.po | 0 addons/{mail_gateway => email}/i18n/sl.po | 0 .../{mail_gateway => email}/i18n/sr@latin.po | 0 addons/{mail_gateway => email}/i18n/sv.po | 0 addons/{mail_gateway => email}/i18n/zh_CN.po | 0 addons/{mail_gateway => email}/res_partner.py | 0 .../res_partner_view.xml | 0 .../scripts/__init__.py | 0 .../scripts/openerp_mailgate/__init__.py | 0 .../openerp_mailgate/openerp_mailgate.py | 0 .../security/ir.model.access.csv | 0 addons/email_gateway/__init__.py | 25 ++ .../__openerp__.py | 5 +- addons/email_gateway/email_gateway.py | 231 ++++++++++++++++++ addons/email_gateway/email_gateway_view.xml | 119 +++++++++ .../security/ir.model.access.csv | 1 + addons/email_template/__init__.py | 2 - addons/email_template/__openerp__.py | 6 +- addons/email_template/email_template.py | 126 +--------- .../email_template/email_template_mailbox.py | 213 ---------------- .../email_template_mailbox_view.xml | 134 ---------- addons/email_template/email_template_view.xml | 49 +--- .../email_template_workflow.xml | 64 ----- .../security/ir.model.access.csv | 3 - addons/email_template/wizard/__init__.py | 1 + .../wizard/email_template_preview.py | 135 ++++++++++ .../wizard/email_template_preview_view.xml | 50 ++++ .../wizard/email_template_send_wizard.py | 24 +- 48 files changed, 705 insertions(+), 710 deletions(-) rename addons/{mail_gateway => email}/__init__.py (96%) create mode 100644 addons/email/__openerp__.py rename addons/{email_template/email_template_account.py => email/email_smtp_server.py} (86%) rename addons/{email_template/email_template_account_view.xml => email/email_smtp_server_view.xml} (66%) create mode 100644 addons/email/email_template_scheduler_data.xml rename addons/{mail_gateway/mail_gateway_view.xml => email/email_view.xml} (100%) rename addons/{mail_gateway/mail_gateway.py => email/emails.py} (99%) rename addons/{mail_gateway => email}/i18n/de.po (100%) rename addons/{mail_gateway => email}/i18n/es.po (100%) rename addons/{mail_gateway => email}/i18n/fr.po (100%) rename addons/{mail_gateway => email}/i18n/hu.po (100%) rename addons/{mail_gateway => email}/i18n/it.po (100%) rename addons/{mail_gateway => email}/i18n/lt.po (100%) rename addons/{mail_gateway => email}/i18n/lv.po (100%) rename addons/{mail_gateway => email}/i18n/mail_gateway.pot (100%) rename addons/{mail_gateway => email}/i18n/nl.po (100%) rename addons/{mail_gateway => email}/i18n/pl.po (100%) rename addons/{mail_gateway => email}/i18n/pt.po (100%) rename addons/{mail_gateway => email}/i18n/pt_BR.po (100%) rename addons/{mail_gateway => email}/i18n/ro.po (100%) rename addons/{mail_gateway => email}/i18n/ru.po (100%) rename addons/{mail_gateway => email}/i18n/sl.po (100%) rename addons/{mail_gateway => email}/i18n/sr@latin.po (100%) rename addons/{mail_gateway => email}/i18n/sv.po (100%) rename addons/{mail_gateway => email}/i18n/zh_CN.po (100%) rename addons/{mail_gateway => email}/res_partner.py (100%) rename addons/{mail_gateway => email}/res_partner_view.xml (100%) rename addons/{mail_gateway => email}/scripts/__init__.py (100%) rename addons/{mail_gateway => email}/scripts/openerp_mailgate/__init__.py (100%) rename addons/{mail_gateway => email}/scripts/openerp_mailgate/openerp_mailgate.py (100%) rename addons/{mail_gateway => email}/security/ir.model.access.csv (100%) create mode 100644 addons/email_gateway/__init__.py rename addons/{mail_gateway => email_gateway}/__openerp__.py (94%) create mode 100644 addons/email_gateway/email_gateway.py create mode 100644 addons/email_gateway/email_gateway_view.xml create mode 100644 addons/email_gateway/security/ir.model.access.csv delete mode 100644 addons/email_template/email_template_mailbox.py delete mode 100644 addons/email_template/email_template_mailbox_view.xml delete mode 100644 addons/email_template/email_template_workflow.xml create mode 100644 addons/email_template/wizard/email_template_preview.py create mode 100644 addons/email_template/wizard/email_template_preview_view.xml diff --git a/addons/mail_gateway/__init__.py b/addons/email/__init__.py similarity index 96% rename from addons/mail_gateway/__init__.py rename to addons/email/__init__.py index 6526541a068..b78d77029a9 100644 --- a/addons/mail_gateway/__init__.py +++ b/addons/email/__init__.py @@ -19,8 +19,9 @@ # ############################################################################## -import mail_gateway +import emails import res_partner +import email_smtp_server # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email/__openerp__.py b/addons/email/__openerp__.py new file mode 100644 index 00000000000..c15aef98a2a --- /dev/null +++ b/addons/email/__openerp__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +{ + 'name': 'Email Gateway System', + 'version': '1.0', + 'category': 'Generic Modules/Mail Service', + 'description': """The generic email gateway system allows to send and receive emails + * History for Emails + * Easy Integration with any Module""", + 'author': 'OpenERP SA', + 'website': 'http://www.openerp.com', + 'depends': ['base', 'base_tools'], + 'init_xml': [], + 'update_xml': [ + "email_view.xml", + "res_partner_view.xml", + 'email_smtp_server_view.xml', + 'security/ir.model.access.csv', +# 'email_smtp_server_data.xml' + + ], + 'demo_xml': [], + 'installable': True, + 'active': False, + 'certificate': '001056784984222247309', +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/email_template_account.py b/addons/email/email_smtp_server.py similarity index 86% rename from addons/email_template/email_template_account.py rename to addons/email/email_smtp_server.py index 462baa1672d..baf5fcc0f40 100644 --- a/addons/email_template/email_template_account.py +++ b/addons/email/email_smtp_server.py @@ -65,11 +65,11 @@ def extract_emails_from_dict(addresses={}): result['all-recipients'].extend(emails) return result -class email_template_account(osv.osv): +class email_smtp_server(osv.osv): """ Object to store email account settings """ - _name = "email_template.account" + _name = "email.smtp_server" _known_content_types = ['multipart/mixed', 'multipart/alternative', 'multipart/related', @@ -81,14 +81,8 @@ class email_template_account(osv.osv): size=64, required=True, readonly=True, select=True, help="The description is used as the Sender name along with the provided From Email, \ -unless it is already specified in the From Email, e.g: John Doe ", +unless it is already specified in the From Email, e.g: John Doe ", states={'draft':[('readonly', False)]}), - 'auto_delete': fields.boolean('Auto Delete', size=64, readonly=True, - help="Permanently delete emails after sending", - states={'draft':[('readonly', False)]}), - 'user':fields.many2one('res.users', - 'Related User', required=True, - readonly=True, states={'draft':[('readonly', False)]}), 'email_id': fields.char('From Email', size=120, required=True, readonly=True, states={'draft':[('readonly', False)]} , @@ -112,33 +106,16 @@ unless it is already specified in the From Email, e.g: John Doe ", states={'draft':[('readonly', False)]}), 'smtptls':fields.boolean('TLS', states={'draft':[('readonly', False)]}, readonly=True), - + 'smtpssl':fields.boolean('SSL/TLS (only in python 2.6)', states={'draft':[('readonly', False)]}, readonly=True), - 'send_pref':fields.selection([ - ('html', 'HTML, otherwise Text'), - ('text', 'Text, otherwise HTML'), - ('alternative', 'Both HTML & Text (Alternative)'), - ('mixed', 'Both HTML & Text (Mixed)') - ], 'Mail Format', required=True), - 'company':fields.selection([ - ('yes', 'Yes'), - ('no', 'No') - ], 'Corporate', - readonly=True, - help="Select if this mail account does not belong " \ - "to specific user but to the organization as a whole. " \ - "eg: info@companydomain.com", - required=True, states={ - 'draft':[('readonly', False)] - }), - 'state':fields.selection([ ('draft', 'Initiated'), ('suspended', 'Suspended'), ('approved', 'Approved') ], 'State', required=True, readonly=True), + 'default': fields.boolean('Default', help="Only one account can be default at a time"), } _defaults = { @@ -154,12 +131,9 @@ unless it is already specified in the From Email, e.g: John Doe ", 'state':lambda * a:'draft', 'smtpport':lambda *a:25, 'smtpserver':lambda *a:'localhost', - 'company':lambda *a:'yes', - 'user':lambda self, cursor, user, context:user, - 'send_pref':lambda *a: 'html', 'smtptls':lambda *a:True, } - + _sql_constraints = [ ( 'email_uniq', @@ -167,46 +141,34 @@ unless it is already specified in the From Email, e.g: John Doe ", 'Another setting already exists with this email ID !') ] - def name_get(self, cr, uid, ids, context=None): - return [(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)] - - def _constraint_unique(self, cursor, user, ids, context=None): - """ - This makes sure that you dont give personal - users two accounts with same ID (Validated in sql constaints) - However this constraint exempts company accounts. - Any no of co accounts for a user is allowed - """ - if self.read(cursor, user, ids, ['company'])[0]['company'] == 'no': - accounts = self.search(cursor, user, [ - ('user', '=', user), - ('company', '=', 'no') - ]) - if len(accounts) > 1 : - return False - else : - return True + def _constraint_unique(self, cr, uid, ids, context=None): + default_ids = self.search(cr, uid, [('default','=',True)]) + if len(default_ids) > 1: + return False else: return True - + _constraints = [ (_constraint_unique, - 'Error: You are not allowed to have more than 1 account.', + 'Error: You are not allowed to set default more than 1 account.', []) ] + def name_get(self, cr, uid, ids, context=None): + return [(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)] + def get_outgoing_server(self, cursor, user, ids, context=None): """ Returns the Out Going Connection (SMTP) object - + @attention: DO NOT USE except_osv IN THIS METHOD @param cursor: Database Cursor @param user: ID of current user - @param ids: ID/list of ids of current object for + @param ids: ID/list of ids of current object for which connection is required First ID will be chosen from lists @param context: Context - + @return: SMTP server object or Exception """ #Type cast ids to integer @@ -214,7 +176,7 @@ unless it is already specified in the From Email, e.g: John Doe ", ids = ids[0] this_object = self.browse(cursor, user, ids, context=context) if this_object: - if this_object.smtpserver and this_object.smtpport: + if this_object.smtpserver and this_object.smtpport: try: if this_object.smtpssl: serv = smtplib.SMTP_SSL(this_object.smtpserver, this_object.smtpport) @@ -234,14 +196,14 @@ unless it is already specified in the From Email, e.g: John Doe ", return serv raise Exception(_("SMTP SERVER or PORT not specified")) raise Exception(_("Core connection for the given ID does not exist")) - + def check_outgoing_connection(self, cursor, user, ids, context=None): """ checks SMTP credentials and confirms if outgoing connection works (Attached to button) @param cursor: Database Cursor @param user: ID of current user - @param ids: list of ids of current object for + @param ids: list of ids of current object for which connection is required @param context: Context """ @@ -255,7 +217,7 @@ unless it is already specified in the From Email, e.g: John Doe ", _("Out going connection test failed"), _("Reason: %s") % error ) - + def do_approval(self, cr, uid, ids, context=None): #TODO: Check if user has rights self.write(cr, uid, ids, {'state':'approved'}, context=context) @@ -279,12 +241,12 @@ unless it is already specified in the From Email, e.g: John Doe ", else: logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id) return False - + #**************************** MAIL SENDING FEATURES ***********************# - + def send_mail(self, cr, uid, ids, addresses, subject='', body=None, payload=None, message_id=None, context=None): #TODO: Replace all this with a single email object if body is None: @@ -294,7 +256,7 @@ unless it is already specified in the From Email, e.g: John Doe ", if context is None: context = {} logger = netsvc.Logger() - for id in ids: + for id in ids: core_obj = self.browse(cr, uid, id, context) serv = self.smtp_connection(cr, uid, id) if serv: @@ -307,7 +269,7 @@ unless it is already specified in the From Email, e.g: John Doe ", text_part = MIMEMultipart(_subtype=text_subtype) payload_part.attach(text_part) else: - # otherwise a single multipart/mixed will do the whole job + # otherwise a single multipart/mixed will do the whole job payload_part = text_part = MIMEMultipart(_subtype=text_subtype) if subject: @@ -322,7 +284,7 @@ unless it is already specified in the From Email, e.g: John Doe ", payload_part['From'] = sender_name + " <" + core_obj.email_id + ">" payload_part['Organization'] = tools.ustr(core_obj.user.company_id.name) payload_part['Date'] = formatdate() - addresses_l = extract_emails_from_dict(addresses) + addresses_l = extract_emails_from_dict(addresses) if addresses_l['To']: payload_part['To'] = u','.join(addresses_l['To']) if addresses_l['CC']: @@ -430,28 +392,28 @@ unless it is already specified in the From Email, e.g: John Doe ", e) ) return date_as_date - + def send_receive(self, cr, uid, ids, context=None): for id in ids: ctx = context.copy() ctx['filters'] = [('account_id', '=', id)] self.pool.get('email_template.mailbox').send_all_mail(cr, uid, [], context=ctx) return True - + def decode_header_text(self, text): """ Decode internationalized headers RFC2822. - To, CC, BCC, Subject fields can contain + To, CC, BCC, Subject fields can contain text slices with different encodes, like: - =?iso-8859-1?Q?Enric_Mart=ED?= , + =?iso-8859-1?Q?Enric_Mart=ED?= , =?Windows-1252?Q?David_G=F3mez?= Sometimes they include extra " character at the beginning/ end of the contact name, like: "=?iso-8859-1?Q?Enric_Mart=ED?=" - and decode_header() does not work well, so we use regular + and decode_header() does not work well, so we use regular expressions (?= ? ? ?=) to split the text slices """ if not text: - return text + return text p = re.compile("(=\?.*?\?.\?.*?\?=)") text2 = '' try: @@ -465,6 +427,6 @@ unless it is already specified in the From Email, e.g: John Doe ", return text return text2 -email_template_account() +email_smtp_server() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/email_template_account_view.xml b/addons/email/email_smtp_server_view.xml similarity index 66% rename from addons/email_template/email_template_account_view.xml rename to addons/email/email_smtp_server_view.xml index 00429efc16c..f1504825327 100644 --- a/addons/email_template/email_template_account_view.xml +++ b/addons/email/email_smtp_server_view.xml @@ -2,19 +2,19 @@ - + - + - - email_template.account.form - email_template.account + + email.smtp_server.form + email.smtp_server form -
+ + @@ -25,18 +25,14 @@ - - - - @@ -51,53 +47,46 @@ - - email_template.account.tree - email_template.account + + email.smtp_server.tree + email.smtp_server tree - - - - email_template.account.search - email_template.account + + email_smtp.server.search + email.smtp_server search - + - - - - - - - Accounts - email_template.account + + Smtp Server + email.smtp_server form form,tree - + {'group_by': [], 'search_default_draft': 1, 'search_default_my': 1} - + - + @@ -113,8 +102,8 @@ - + diff --git a/addons/email/email_template_scheduler_data.xml b/addons/email/email_template_scheduler_data.xml new file mode 100644 index 00000000000..f2ee000c16a --- /dev/null +++ b/addons/email/email_template_scheduler_data.xml @@ -0,0 +1,15 @@ + + + + + Administrator + + + example@test.com + draft + + localhost + + + + diff --git a/addons/mail_gateway/mail_gateway_view.xml b/addons/email/email_view.xml similarity index 100% rename from addons/mail_gateway/mail_gateway_view.xml rename to addons/email/email_view.xml diff --git a/addons/mail_gateway/mail_gateway.py b/addons/email/emails.py similarity index 99% rename from addons/mail_gateway/mail_gateway.py rename to addons/email/emails.py index 156586c2edd..b23aea0c901 100644 --- a/addons/mail_gateway/mail_gateway.py +++ b/addons/email/emails.py @@ -220,7 +220,7 @@ class mailgate_message(osv.osv): action_data = False action_pool = self.pool.get('ir.actions.act_window') message_pool = self.browse(cr ,uid, ids, context=context)[0] - att_ids = [x.id for x in message_pool.attachment_ids] + att_ids = [x.id for x in message_pool.attachment_ids] action_ids = action_pool.search(cr, uid, [('res_model', '=', 'ir.attachment')]) if action_ids: action_data = action_pool.read(cr, uid, action_ids[0], context=context) diff --git a/addons/mail_gateway/i18n/de.po b/addons/email/i18n/de.po similarity index 100% rename from addons/mail_gateway/i18n/de.po rename to addons/email/i18n/de.po diff --git a/addons/mail_gateway/i18n/es.po b/addons/email/i18n/es.po similarity index 100% rename from addons/mail_gateway/i18n/es.po rename to addons/email/i18n/es.po diff --git a/addons/mail_gateway/i18n/fr.po b/addons/email/i18n/fr.po similarity index 100% rename from addons/mail_gateway/i18n/fr.po rename to addons/email/i18n/fr.po diff --git a/addons/mail_gateway/i18n/hu.po b/addons/email/i18n/hu.po similarity index 100% rename from addons/mail_gateway/i18n/hu.po rename to addons/email/i18n/hu.po diff --git a/addons/mail_gateway/i18n/it.po b/addons/email/i18n/it.po similarity index 100% rename from addons/mail_gateway/i18n/it.po rename to addons/email/i18n/it.po diff --git a/addons/mail_gateway/i18n/lt.po b/addons/email/i18n/lt.po similarity index 100% rename from addons/mail_gateway/i18n/lt.po rename to addons/email/i18n/lt.po diff --git a/addons/mail_gateway/i18n/lv.po b/addons/email/i18n/lv.po similarity index 100% rename from addons/mail_gateway/i18n/lv.po rename to addons/email/i18n/lv.po diff --git a/addons/mail_gateway/i18n/mail_gateway.pot b/addons/email/i18n/mail_gateway.pot similarity index 100% rename from addons/mail_gateway/i18n/mail_gateway.pot rename to addons/email/i18n/mail_gateway.pot diff --git a/addons/mail_gateway/i18n/nl.po b/addons/email/i18n/nl.po similarity index 100% rename from addons/mail_gateway/i18n/nl.po rename to addons/email/i18n/nl.po diff --git a/addons/mail_gateway/i18n/pl.po b/addons/email/i18n/pl.po similarity index 100% rename from addons/mail_gateway/i18n/pl.po rename to addons/email/i18n/pl.po diff --git a/addons/mail_gateway/i18n/pt.po b/addons/email/i18n/pt.po similarity index 100% rename from addons/mail_gateway/i18n/pt.po rename to addons/email/i18n/pt.po diff --git a/addons/mail_gateway/i18n/pt_BR.po b/addons/email/i18n/pt_BR.po similarity index 100% rename from addons/mail_gateway/i18n/pt_BR.po rename to addons/email/i18n/pt_BR.po diff --git a/addons/mail_gateway/i18n/ro.po b/addons/email/i18n/ro.po similarity index 100% rename from addons/mail_gateway/i18n/ro.po rename to addons/email/i18n/ro.po diff --git a/addons/mail_gateway/i18n/ru.po b/addons/email/i18n/ru.po similarity index 100% rename from addons/mail_gateway/i18n/ru.po rename to addons/email/i18n/ru.po diff --git a/addons/mail_gateway/i18n/sl.po b/addons/email/i18n/sl.po similarity index 100% rename from addons/mail_gateway/i18n/sl.po rename to addons/email/i18n/sl.po diff --git a/addons/mail_gateway/i18n/sr@latin.po b/addons/email/i18n/sr@latin.po similarity index 100% rename from addons/mail_gateway/i18n/sr@latin.po rename to addons/email/i18n/sr@latin.po diff --git a/addons/mail_gateway/i18n/sv.po b/addons/email/i18n/sv.po similarity index 100% rename from addons/mail_gateway/i18n/sv.po rename to addons/email/i18n/sv.po diff --git a/addons/mail_gateway/i18n/zh_CN.po b/addons/email/i18n/zh_CN.po similarity index 100% rename from addons/mail_gateway/i18n/zh_CN.po rename to addons/email/i18n/zh_CN.po diff --git a/addons/mail_gateway/res_partner.py b/addons/email/res_partner.py similarity index 100% rename from addons/mail_gateway/res_partner.py rename to addons/email/res_partner.py diff --git a/addons/mail_gateway/res_partner_view.xml b/addons/email/res_partner_view.xml similarity index 100% rename from addons/mail_gateway/res_partner_view.xml rename to addons/email/res_partner_view.xml diff --git a/addons/mail_gateway/scripts/__init__.py b/addons/email/scripts/__init__.py similarity index 100% rename from addons/mail_gateway/scripts/__init__.py rename to addons/email/scripts/__init__.py diff --git a/addons/mail_gateway/scripts/openerp_mailgate/__init__.py b/addons/email/scripts/openerp_mailgate/__init__.py similarity index 100% rename from addons/mail_gateway/scripts/openerp_mailgate/__init__.py rename to addons/email/scripts/openerp_mailgate/__init__.py diff --git a/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py b/addons/email/scripts/openerp_mailgate/openerp_mailgate.py similarity index 100% rename from addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py rename to addons/email/scripts/openerp_mailgate/openerp_mailgate.py diff --git a/addons/mail_gateway/security/ir.model.access.csv b/addons/email/security/ir.model.access.csv similarity index 100% rename from addons/mail_gateway/security/ir.model.access.csv rename to addons/email/security/ir.model.access.csv diff --git a/addons/email_gateway/__init__.py b/addons/email_gateway/__init__.py new file mode 100644 index 00000000000..4ce06ccc868 --- /dev/null +++ b/addons/email_gateway/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +import email_gateway + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mail_gateway/__openerp__.py b/addons/email_gateway/__openerp__.py similarity index 94% rename from addons/mail_gateway/__openerp__.py rename to addons/email_gateway/__openerp__.py index e91257fd148..6748493ebe7 100644 --- a/addons/mail_gateway/__openerp__.py +++ b/addons/email_gateway/__openerp__.py @@ -28,11 +28,10 @@ * Easy Integration with any Module""", 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', - 'depends': ['base'], + 'depends': ['base','email'], 'init_xml': [], 'update_xml': [ - "mail_gateway_view.xml", - "res_partner_view.xml", + "email_gateway_view.xml", 'security/ir.model.access.csv' ], diff --git a/addons/email_gateway/email_gateway.py b/addons/email_gateway/email_gateway.py new file mode 100644 index 00000000000..b153d200e5c --- /dev/null +++ b/addons/email_gateway/email_gateway.py @@ -0,0 +1,231 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL () +# +# 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 +# +############################################################################## + +from osv import osv, fields +import time +import tools +import binascii +import email +from email.header import decode_header +from email.utils import parsedate +import base64 +import re +from tools.translate import _ +import logging +import xmlrpclib + +_logger = logging.getLogger('mailgate') + +def format_date_tz(date, tz=None): + if not date: + return 'n/a' + format = tools.DEFAULT_SERVER_DATETIME_FORMAT + return tools.server_to_local_timestamp(date, format, format, tz) + +class email_message(osv.osv): + ''' + Mailgateway Message + ''' + def open_document(self, cr, uid, ids, context=None): + """ To Open Document + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: the ID of messages + @param context: A standard dictionary + """ + action_data = False + if ids: + message_id = ids[0] + mailgate_data = self.browse(cr, uid, message_id, context=context) + model = mailgate_data.model + res_id = mailgate_data.res_id + + action_pool = self.pool.get('ir.actions.act_window') + action_ids = action_pool.search(cr, uid, [('res_model', '=', model)]) + if action_ids: + action_data = action_pool.read(cr, uid, action_ids[0], context=context) + action_data.update({ + 'domain' : "[('id','=',%d)]"%(res_id), + 'nodestroy': True, + 'context': {} + }) + return action_data + + def open_attachment(self, cr, uid, ids, context=None): + """ To Open attachments + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: the ID of messages + @param context: A standard dictionary + """ + action_data = False + action_pool = self.pool.get('ir.actions.act_window') + message_pool = self.browse(cr ,uid, ids, context=context)[0] + att_ids = [x.id for x in message_pool.attachment_ids] + action_ids = action_pool.search(cr, uid, [('res_model', '=', 'ir.attachment')]) + if action_ids: + action_data = action_pool.read(cr, uid, action_ids[0], context=context) + action_data.update({ + 'domain': [('id','in',att_ids)], + 'nodestroy': True + }) + return action_data + + def truncate_data(self, cr, uid, data, context=None): + data_list = data and data.split('\n') or [] + if len(data_list) > 3: + res = '\n\t'.join(data_list[:3]) + '...' + else: + res = '\n\t'.join(data_list) + return res + + def _get_display_text(self, cr, uid, ids, name, arg, context=None): + if context is None: + context = {} + tz = context.get('tz') + result = {} + for message in self.browse(cr, uid, ids, context=context): + msg_txt = '' + if message.history: + msg_txt += (message.email_from or '/') + _(' wrote on ') + format_date_tz(message.date, tz) + ':\n\t' + if message.description: + msg_txt += self.truncate_data(cr, uid, message.description, context=context) + else: + msg_txt = (message.user_id.name or '/') + _(' on ') + format_date_tz(message.date, tz) + ':\n\t' + if message.name == _('Opportunity'): + msg_txt += _("Converted to Opportunity") + elif message.name == _('Note'): + msg_txt = (message.user_id.name or '/') + _(' added note on ') + format_date_tz(message.date, tz) + ':\n\t' + msg_txt += self.truncate_data(cr, uid, message.description, context=context) + elif message.name == _('Stage'): + msg_txt += _("Changed Stage to: ") + message.description + else: + msg_txt += _("Changed Status to: ") + message.name + result[message.id] = msg_txt + return result + + _name = 'email.message' + _description = 'Email Message' + _order = 'date desc' + _columns = { + 'name':fields.text('Subject', readonly=True), + 'model': fields.char('Object Name', size=128, select=1, readonly=True), + 'res_id': fields.integer('Resource ID', select=1, readonly=True), + 'ref_id': fields.char('Reference Id', size=256, readonly=True, help="Message Id in Email Server.", select=True), + 'date': fields.datetime('Date', readonly=True), + 'history': fields.boolean('Is History?', readonly=True), + 'user_id': fields.many2one('res.users', 'User Responsible', readonly=True), + 'message': fields.text('Description', readonly=True), + 'email_from': fields.char('From', size=128, help="Email From", readonly=True), + 'email_to': fields.char('To', help="Email Recipients", size=256, readonly=True), + 'email_cc': fields.char('Cc', help="Carbon Copy Email Recipients", size=256, readonly=True), + 'email_bcc': fields.char('Bcc', help='Blind Carbon Copy Email Recipients', size=256, readonly=True), + 'message_id': fields.char('Message Id', size=1024, readonly=True, help="Message Id on Email.", select=True), + 'references': fields.text('References', readonly=True, help="References emails."), + 'description': fields.text('Description', readonly=True), + 'partner_id': fields.many2one('res.partner', 'Partner', required=False), + 'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments', readonly=True), + 'display_text': fields.function(_get_display_text, method=True, type='text', size="512", string='Display Text'), + 'reply_to':fields.char('Reply-To', size=250, readonly=True), + } + + def init(self, cr): + cr.execute("""SELECT indexname + FROM pg_indexes + WHERE indexname = 'mailgate_message_res_id_model_idx'""") + if not cr.fetchone(): + cr.execute("""CREATE INDEX mailgate_message_res_id_model_idx + ON mailgate_message (model, res_id)""") + +# def run_mail_scheduler(self, cursor, user, context=None): +# """ +# This method is called by OpenERP Scheduler +# to periodically send emails +# """ +# try: +# self.send_all_mail(cursor, user, context=context) +# except Exception, e: +# LOGGER.notifyChannel( +# "Email Template", +# netsvc.LOG_ERROR, +# _("Error sending mail: %s") % e) +# +# def send_all_mail(self, cr, uid, ids=None, context=None): +# if ids is None: +# ids = [] +# if context is None: +# context = {} +# filters = [('folder', '=', 'outbox'), ('state', '!=', 'sending')] +# if 'filters' in context.keys(): +# for each_filter in context['filters']: +# filters.append(each_filter) +# ids = self.search(cr, uid, filters, context=context) +# self.write(cr, uid, ids, {'state':'sending'}, context) +# self.send_this_mail(cr, uid, ids, context) +# return True +# +# def send_this_mail(self, cr, uid, ids=None, context=None): +# #previous method to send email (link with email account can be found at the revision 4172 and below +# result = True +# attachment_pool = self.pool.get('ir.attachment') +# for id in (ids or []): +# try: +# account_obj = self.pool.get('email.smtp_server') +# values = self.read(cr, uid, id, [], context) +# payload = {} +# if values['attachments_ids']: +# for attid in values['attachments_ids']: +# attachment = attachment_pool.browse(cr, uid, attid, context)#,['datas_fname','datas']) +# payload[attachment.datas_fname] = attachment.datas +# result = account_obj.send_mail(cr, uid, +# [values['account_id'][0]], +# {'To':values.get('email_to') or u'', +# 'CC':values.get('email_cc') or u'', +# 'BCC':values.get('email_bcc') or u'', +# 'Reply-To':values.get('reply_to') or u''}, +# values['subject'] or u'', +# {'text':values.get('body_text') or u'', 'html':values.get('body_html') or u''}, +# payload=payload, +# message_id=values['message_id'], +# context=context) +# if result == True: +# account = account_obj.browse(cr, uid, values['account_id'][0], context=context) +# if account.auto_delete: +# self.write(cr, uid, id, {'folder': 'trash'}, context=context) +# self.unlink(cr, uid, [id], context=context) +# # Remove attachments for this mail +# attachment_pool.unlink(cr, uid, values['attachments_ids'], context=context) +# else: +# self.write(cr, uid, id, {'folder':'sent', 'state':'na', 'date_mail':time.strftime("%Y-%m-%d %H:%M:%S")}, context) +# else: +# error = result['error_msg'] +# +# except Exception, error: +# logger = netsvc.Logger() +# logger.notifyChannel("email-template", netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (id, error)) +# self.write(cr, uid, id, {'state':'na'}, context) +# return result + +email_message() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_gateway/email_gateway_view.xml b/addons/email_gateway/email_gateway_view.xml new file mode 100644 index 00000000000..b8f8415c389 --- /dev/null +++ b/addons/email_gateway/email_gateway_view.xml @@ -0,0 +1,119 @@ + + + + + + email.message.form + email.message + form + + + + + + + + + + + + + + + + + + + + + + + +