From 2fe7c51e361ade79eef9af67f11a96a5fc24b035 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Mon, 21 Mar 2011 19:01:56 +0530 Subject: [PATCH] [REM] email.smtp_server: removed email.smtp_server and did changes in email module bzr revid: rha@tinyerp.com-20110321133156-y57yw6sekshnw9ns --- .../wizard/account_followup_print.py | 2 +- addons/base_action_rule/base_action_rule.py | 2 +- addons/base_calendar/base_calendar.py | 4 +- addons/crm/crm.py | 2 +- addons/crm/crm_action_rule.py | 2 +- addons/crm/crm_lead.py | 12 - addons/crm/wizard/crm_send_email.py | 4 +- addons/crm_claim/crm_claim.py | 12 - addons/crm_helpdesk/crm_helpdesk.py | 12 - addons/email/__init__.py | 2 +- addons/email/email_data.xml | 14 +- addons/email/email_message.py | 80 +--- addons/email/email_smtp_server.py | 376 ------------------ addons/email/email_thread.py | 18 +- addons/email/email_view.xml | 95 +---- addons/email/security/ir.model.access.csv | 1 - addons/email/wizard/email_compose_message.py | 9 +- .../wizard/email_compose_message_view.xml | 3 +- addons/email_template/email_template.py | 30 +- addons/email_template/email_template_view.xml | 18 +- .../wizard/email_template_preview_view.xml | 2 +- .../wizard/email_template_send_wizard.py | 4 +- addons/event/event.py | 2 +- addons/hr_evaluation/hr_evaluation.py | 2 +- .../wizard/hr_evaluation_mail.py | 2 +- addons/hr_recruitment/hr_recruitment.py | 11 - addons/project/wizard/project_task_close.py | 2 +- addons/project_issue/project_issue.py | 12 - addons/project_mailgate/project_mailgate.py | 3 - addons/project_scrum/project_scrum.py | 2 +- .../wizard/project_scrum_email.py | 4 +- addons/share/wizard/share_wizard.py | 2 +- addons/survey/wizard/survey_answer.py | 4 +- .../survey/wizard/survey_send_invitation.py | 6 +- 34 files changed, 70 insertions(+), 686 deletions(-) delete mode 100644 addons/email/email_smtp_server.py diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py index 02f463a78eb..49b83973b66 100644 --- a/addons/account_followup/wizard/account_followup_print.py +++ b/addons/account_followup/wizard/account_followup_print.py @@ -278,7 +278,7 @@ class account_followup_print_all(osv.osv_memory): msg = '' if dest: try: - email_message_obj.email_send(cr, uid, src, dest, sub, body, model='account.followup.print.all') + email_message_obj.schedule_with_attach(cr, uid, src, dest, sub, body, model='account.followup.print.all') msg_sent += partner.name + '\n' except Exception, e: raise osv.except_osv('Error !', e ) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index a2432050f1b..02e929f6a28 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -315,7 +315,7 @@ the rule to mark CC(mail to any other person defined in actions)."), if not emailfrom: raise osv.except_osv(_('Error!'), _("No E-Mail ID Found for your Company address!")) - return email_message_obj.email_send(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id)) + return email_message_obj.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id)) def do_check(self, cr, uid, action, obj, context=None): diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index 7cfed6711b4..d49594f4a60 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -507,7 +507,7 @@ property or property parameter."), body = html_invitation % body_vals if mail_to and email_from: attach = self.get_ics_file(cr, uid, res_obj, context=context) - email_message_obj.email_send(cr, uid, + email_message_obj.schedule_with_attach(cr, uid, email_from, mail_to, sub, @@ -893,7 +893,7 @@ From: for att in alarm.attendee_ids: mail_to.append(att.user_id.address_id.email) if mail_to: - email_message_obj.email_send(cr, uid, + email_message_obj.schedule_with_attach(cr, uid, tools.config.get('email_from', False), mail_to, sub, diff --git a/addons/crm/crm.py b/addons/crm/crm.py index cbf246edb31..687cd836d1a 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -488,7 +488,7 @@ class crm_case(object): # Send an email subject = "Reminder: [%s] %s" % (str(case.id), case.name, ) - email_message_obj.email_send(cr, uid, + email_message_obj.schedule_with_attach(cr, uid, src, [dest], subject, diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index d877c074020..acb7801c7c9 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -66,7 +66,7 @@ this if you want the rule to send an email to the partner."), if not emailfrom: raise osv.except_osv(_('Error!'), _("No E-Mail ID Found for your Company address!")) - return email_message_obj.email_send(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id)) + return email_message_obj.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id)) def do_check(self, cr, uid, action, obj, context=None): """ @param self: The object pointer diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 6c3fa3d71f6..557403a8b5a 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -399,18 +399,6 @@ class crm_lead(crm_case, osv.osv): res = self.write(cr, uid, [case.id], values, context=context) return res - def msg_send(self, cr, uid, id, *args, **argv): - - """ Send The Message - @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param ids: List of email’s IDs - @param *args: Return Tuple Value - @param **args: Return Dictionary of Keyword Value - """ - return True - def on_change_optin(self, cr, uid, ids, optin): return {'value':{'optin':optin,'optout':False}} diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py index d130dab712e..71c83b20c33 100644 --- a/addons/crm/wizard/crm_send_email.py +++ b/addons/crm/wizard/crm_send_email.py @@ -45,7 +45,7 @@ class crm_send_new_email(osv.osv_memory): 'body': fields.text('Message Body', required=True), 'state': fields.selection(AVAILABLE_STATES, string='Set New State To', required=True), 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id', 'Attachment'), - 'html': fields.boolean('HTML formatting?', help="Select this if you want to send email with HTML formatting."), + 'html': fields.boolean('HTML formatting?', help="Select this if you want to send email with HTML formatting."), } def action_send(self, cr, uid, ids, context=None): @@ -111,7 +111,7 @@ class crm_send_new_email(osv.osv_memory): if obj.html: subtype = 'html' - flag = email_message_obj.email_send(cr, uid, + flag = email_message_obj.schedule_with_attach(cr, uid, email_from, emails, obj.subject, diff --git a/addons/crm_claim/crm_claim.py b/addons/crm_claim/crm_claim.py index 94b541b83d7..afb49152b1f 100644 --- a/addons/crm_claim/crm_claim.py +++ b/addons/crm_claim/crm_claim.py @@ -238,18 +238,6 @@ class crm_claim(crm.crm_case, osv.osv): res = self.write(cr, uid, [case.id], values, context=context) return res - def msg_send(self, cr, uid, id, *args, **argv): - - """ Send The Message - @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param ids: List of email’s IDs - @param *args: Return Tuple Value - @param **args: Return Dictionary of Keyword Value - """ - return True - crm_claim() diff --git a/addons/crm_helpdesk/crm_helpdesk.py b/addons/crm_helpdesk/crm_helpdesk.py index 3493e03bc79..4e0289bcff0 100644 --- a/addons/crm_helpdesk/crm_helpdesk.py +++ b/addons/crm_helpdesk/crm_helpdesk.py @@ -177,18 +177,6 @@ class crm_helpdesk(crm.crm_case, osv.osv): res = self.write(cr, uid, [case.id], values, context=context) return res - def msg_send(self, cr, uid, id, *args, **argv): - - """ Send The Message - @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param ids: List of email’s IDs - @param *args: Return Tuple Value - @param **args: Return Dictionary of Keyword Value - """ - return True - crm_helpdesk() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email/__init__.py b/addons/email/__init__.py index 95b26dd215f..d4d786ed27f 100644 --- a/addons/email/__init__.py +++ b/addons/email/__init__.py @@ -19,7 +19,7 @@ # ############################################################################## -import email_smtp_server +#import email_smtp_server import email_message import email_thread import res_partner diff --git a/addons/email/email_data.xml b/addons/email/email_data.xml index cd824172473..8423222ea9b 100644 --- a/addons/email/email_data.xml +++ b/addons/email/email_data.xml @@ -1,17 +1,7 @@ - - Administrator - - - example@test.com - draft - - localhost - - - + Email scheduler 1 @@ -19,7 +9,7 @@ -1 - + diff --git a/addons/email/email_message.py b/addons/email/email_message.py index 81120f733da..c024de29253 100644 --- a/addons/email/email_message.py +++ b/addons/email/email_message.py @@ -83,7 +83,7 @@ class email_message_common(osv.osv_memory): 'priority':fields.integer('Priority'), 'body': fields.text('Description', translate=True), 'body_html': fields.text('HTML', help="Contains HTML version of email"), - 'smtp_server_id':fields.many2one('email.smtp_server', 'SMTP Server'), + 'smtp_server_id':fields.many2one('ir.mail.server', 'SMTP Server'), } _rec_name='subject' @@ -177,13 +177,6 @@ class email_message(osv.osv): 'display_text': fields.function(_get_display_text, method=True, type='text', size="512", string='Display Text'), 'debug':fields.boolean('Debug', readonly=True), 'history': fields.boolean('History', readonly=True), - 'folder':fields.selection([ - ('drafts', 'Drafts'), - ('inbox', 'Inbox'), - ('outbox', 'Outbox'), - ('trash', 'Trash'), - ('sent', 'Sent Items'), - ], 'Folder'), 'state':fields.selection([ ('outgoing', 'Outgoing'), ('sent', 'Sent'), @@ -194,26 +187,8 @@ class email_message(osv.osv): } _defaults = { - 'state': lambda * a: 'draft', - 'folder': lambda * a: 'outbox', } -# def unlink(self, cr, uid, ids, context=None): -# """ -# It just changes the folder of the item to "Trash", if it is no in Trash folder yet, -# or completely deletes it if it is already in Trash. -# """ -# to_update = [] -# to_remove = [] -# for mail in self.browse(cr, uid, ids, context=context): -# if mail.folder == 'trash': -# to_remove.append(mail.id) -# else: -# to_update.append(mail.id) -# # Changes the folder to trash -# self.write(cr, uid, to_update, {'folder': 'trash'}, context=context) -# return super(email_message, self).unlink(cr, uid, to_remove, context=context) - def init(self, cr): cr.execute("""SELECT indexname FROM pg_indexes @@ -222,25 +197,8 @@ class email_message(osv.osv): cr.execute("""CREATE INDEX email_message_res_id_model_idx ON email_message (model, res_id)""") -# def process_queue(self, cr, uid, ids, arg): -# self.process_email_queue(cr, uid, ids=ids) -# return True - -# def run_mail_scheduler(self, cursor, user, context=None): -# """ -# This method is called by OpenERP Scheduler -# to periodically send emails -# """ -# try: -# self.process_email_queue(cursor, user, context=context) -# except Exception, e: -# LOGGER.notifyChannel( -# "Email Template", -# netsvc.LOG_ERROR, -# _("Error sending mail: %s") % e) - - def email_send(self, cr, uid, email_from, email_to, subject, body, model=False, email_cc=None, email_bcc=None, reply_to=False, attach=None, - message_id=False, references=False, openobject_id=False, debug=False, subtype='plain', x_headers={}, priority='3', smtp_server_id=False, context=None): + def schedule_with_attach(self, cr, uid, email_from, email_to, subject, body, model=False, email_cc=None, email_bcc=None, reply_to=False, attach=None, + message_id=False, references=False, openobject_id=False, debug=False, subtype='plain', x_headers={}, priority='3', smtp_server_id=False, context=None, auto_delete=False): attachment_obj = self.pool.get('ir.attachment') if email_to and type(email_to) != list: email_to = [email_to] @@ -250,11 +208,11 @@ class email_message(osv.osv): email_bcc = [email_bcc] msg_vals = { - 'name': subject, + 'subject': subject, 'model': model or '', 'date': time.strftime('%Y-%m-%d'), 'user_id': uid, - 'description': body, + 'body': body, 'email_from': email_from, 'email_to': email_to and ','.join(email_to) or '', 'email_cc': email_cc and ','.join(email_cc) or '', @@ -267,7 +225,6 @@ class email_message(osv.osv): 'headers': x_headers or False, 'priority': priority, 'debug': debug, - 'folder': 'outbox', 'history': True, 'smtp_server_id': smtp_server_id, 'state': 'waiting', @@ -277,10 +234,10 @@ class email_message(osv.osv): attachment_ids = [] for attachment in attach: attachment_data = { - 'name': (subject or '') + _(' (Email Attachment)'), + 'subject': (subject or '') + _(' (Email Attachment)'), 'datas': attachment[1], 'datas_fname': attachment[0], - 'description': subject or _('No Description'), + 'body': subject or _('No Description'), 'res_model':'email.message', 'res_id': email_msg_id, } @@ -298,13 +255,13 @@ class email_message(osv.osv): if context is None: context = {} attachment_obj = self.pool.get('ir.attachment') - smtp_server_obj = self.pool.get('email.smtp_server') + smtp_server_obj = self.pool.get('ir.mail.server') if not ids: - filters = [('folder', '=', 'outbox'), ('state', '=', 'waiting')] + filters = [('state', '=', 'outgoing')] if 'filters' in context: filters.extend(context['filters']) ids = self.search(cr, uid, filters, context=context) - self.write(cr, uid, ids, {'state':'sending', 'folder':'sent'}, context) + self.write(cr, uid, ids, {'state':'sending'}, context) for message in self.browse(cr, uid, ids, context): try: attachments = [] @@ -315,22 +272,7 @@ class email_message(osv.osv): smtp_ids = smtp_server_obj.search(cr, uid, [('default','=',True)]) if smtp_ids: smtp_server = smtp_server_obj.browse(cr, uid, smtp_ids, context)[0] - res = tools.email_send(message.email_from, - message.email_to and message.email_to.split(',') or [], - message.name, message.description, - email_cc=message.email_cc and message.email_cc.split(',') or [], - email_bcc=message.email_bcc and message.email_bcc.split(',') or [], - reply_to=message.reply_to, - attach=attachments, message_id=message.message_id, references = message.references, - openobject_id=message.res_id, - subtype=message.sub_type, - x_headers=message.headers and eval(message.headers) or {}, - priority=message.priority, debug=message.debug, - smtp_server=smtp_server and smtp_server.smtp_host or None, - smtp_port=smtp_server and smtp_server.smtpport or None, - ssl=smtp_server and smtp_server.smtpssl or False, - smtp_user=smtp_server and smtp_server.smtpuname or None, - smtp_password=smtp_server and smtp_server.smtppass or None) + res = self.send_email(cr, uid, ids, auto_commit=True, context=context) if res: self.write(cr, uid, [message.id], {'state':'sent', 'message_id': res}, context) else: diff --git a/addons/email/email_smtp_server.py b/addons/email/email_smtp_server.py deleted file mode 100644 index f9b1be3a597..00000000000 --- a/addons/email/email_smtp_server.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2011 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 -from osv import fields -from tools.translate import _ -import tools - -#import time -#import binascii -#import email -#from email.header import decode_header -#from email.utils import parsedate -#import base64 -#import re -#import logging -#import xmlrpclib - -#_logger = logging.getLogger('mailgate') - -#import re -import smtplib -#import base64 -#from email import Encoders -#from email.mime.base import MIMEBase -#from email.mime.multipart import MIMEMultipart -#from email.mime.text import MIMEText -#from email.header import decode_header, Header -#from email.utils import formatdate -#import netsvc -#import datetime -#import tools -#import logging - -#EMAIL_PATTERN = re.compile(r'([^()\[\] ,<:\\>@";]+@[^()\[\] ,<:\\>@";]+)') # See RFC822 -#def extract_emails(emails_str): -# """ -# Returns a list of email addresses recognized in a string, ignoring the rest of the string. -# extract_emails('a@b.com,c@bcom, "John Doe" , e@b.com') -> ['a@b.com','c@bcom', 'd@b.com', 'e@b.com']" -# """ -# return EMAIL_PATTERN.findall(emails_str) -# -# -#def extract_emails_from_dict(addresses={}): -# """ -# Extracts email addresses from a dictionary with comma-separated address string values, handling -# separately the To, CC, BCC and Reply-To addresses. -# -# :param addresses: a dictionary of addresses in the form {'To': 'a@b.com,c@bcom; d@b.com;e@b.com' , 'CC': 'e@b.com;f@b.com', ... } -# :return: a dictionary with a list of separate addresses for each header (To, CC, BCC), with an additional key 'all-recipients' -# containing all addresses for the 'To', 'CC', 'BCC' entries. -# """ -# result = {'all-recipients':[]} -# keys = ['To', 'CC', 'BCC', 'Reply-To'] -# for each in keys: -# emails = extract_emails(addresses.get(each, u'')) -# while u'' in emails: -# emails.remove(u'') -# result[each] = emails -# if each != 'Reply-To': -# result['all-recipients'].extend(emails) -# return result - -class email_smtp_server(osv.osv): - """ - SMTP Server - """ - _name = "email.smtp_server" - - _columns = { - 'name': fields.char('Name', - size=64, required=True, - select=True, - help="The Name 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 ", - ), - 'email_id': fields.char('From Email', - size=120, required=True, - help="eg: 'john@doe.com' or 'John Doe '"), - 'smtpserver': fields.char('Server', - size=120, required=True, - help="Enter name of outgoing server, eg: smtp.yourdomain.com"), - 'smtpport': fields.integer('SMTP Port', - size=64, required=True, - help="Enter port number, eg: 25 or 587"), - 'smtpuname': fields.char('User Name', - size=120, required=False, - help="Specify the username if your SMTP server requires authentication, " - "otherwise leave it empty."), - 'smtppass': fields.char('Password', - size=120, - required=False), - 'smtptls':fields.boolean('TLS'), - 'smtpssl':fields.boolean('SSL/TLS'), - 'default': fields.boolean('Default', help="Only one account can be default at a time"), - } - - _defaults = { - 'name':lambda self, cursor, user, context:self.pool.get( 'res.users' - ).read(cursor, user, user, ['name'], context)['name'], - 'smtpport': tools.config.get('smtp_port',25), - 'smtpserver': tools.config.get('smtp_server','localhost'), - 'smtpssl': tools.config.get('smtp_ssl',False), - 'smtptls': True, - } - - _sql_constraints = [ - ( - 'email_uniq', - 'unique (email_id)', - 'Another setting already exists with this email ID !') - ] - - def _constraint_unique(self, cr, uid, ids, context=None): - default_ids = self.search(cr, uid, [('default','=',True)]) - if len(default_ids) > 1: - return False - - return True - - _constraints = [ - (_constraint_unique, - 'Error: You must be define one default smtp server 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 test_smtp_connection(self, cr, uid, ids, context=None): - """ - Test SMTP connection works - """ - try: - for smtp_server in self.browse(cr, uid, ids, context=context): - smtp = tools.connect_smtp_server(smtp_server.smtpserver, smtp_server.smtpport, user_name=smtp_server.smtpuname, - user_password=smtp_server.smtppass, ssl=smtp_server.smtpssl, tls=smtp_server.smtptls) - try: - smtp.quit() - except Exception: - # ignored, just a consequence of the previous exception - pass - except Exception, error: - raise osv.except_osv( - _("SMTP Connection: Test failed"), - _("Reason: %s") % error - ) - - raise osv.except_osv(_("SMTP Connection: Test Successfully!"), '') - -# def do_approval(self, cr, uid, ids, context=None): -# #TODO: Check if user has rights -# self.write(cr, uid, ids, {'state':'approved'}, context=context) -## wf_service = netsvc.LocalService("workflow") -# -# def smtp_connection(self, cursor, user, id, context=None): -# """ -# This method should now wrap smtp_connection -# """ -# #This function returns a SMTP server object -# logger = netsvc.Logger() -# core_obj = self.browse(cursor, user, id, context=context) -# if core_obj.smtpserver and core_obj.smtpport and core_obj.state == 'approved': -# try: -# serv = self.get_outgoing_server(cursor, user, id, context) -# except Exception, error: -# logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed on login. Probable Reason:Could not login to server\nError: %s") % (id, error)) -# return False -# #Everything is complete, now return the connection -# return serv -# 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_email(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: -# body = {} -# if payload is None: -# payload = {} -# if context is None: -# context = {} -# logger = netsvc.Logger() -# for id in ids: -# core_obj = self.browse(cr, uid, id, context) -# serv = self.smtp_connection(cr, uid, id) -# if serv: -# try: -# # Need a multipart/mixed wrapper for attachments if content is alternative -# if payload: -# payload_part = MIMEMultipart(_subtype='mixed') -# text_part = MIMEMultipart(_subtype='mixed') -# payload_part.attach(text_part) -# else: -# # otherwise a single multipart/mixed will do the whole job -# payload_part = text_part = MIMEMultipart(_subtype='mixed') -# -# if subject: -# payload_part['Subject'] = subject -# from_email = core_obj.email_id -# if '<' in from_email: -# # We have a structured email address, keep it untouched -# payload_part['From'] = Header(core_obj.email_id, 'utf-8').encode() -# else: -# # Plain email address, construct a structured one based on the name: -# sender_name = Header(core_obj.name, 'utf-8').encode() -# 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) -# if addresses_l['To']: -# payload_part['To'] = u','.join(addresses_l['To']) -# if addresses_l['CC']: -# payload_part['CC'] = u','.join(addresses_l['CC']) -# if addresses_l['Reply-To']: -# payload_part['Reply-To'] = addresses_l['Reply-To'][0] -# if message_id: -# payload_part['Message-ID'] = message_id -# if body.get('text', False): -# temp_body_text = body.get('text', '') -# l = len(temp_body_text.replace(' ', '').replace('\r', '').replace('\n', '')) -# if l == 0: -# body['text'] = u'No Mail Message' -# # Attach parts into message container. -# # According to RFC 2046, the last part of a multipart message, in this case -# # the HTML message, is best and preferred. -## if core_obj.send_pref in ('text', 'mixed', 'alternative'): -## body_text = body.get('text', u'') -## body_text = tools.ustr(body_text) -## text_part.attach(MIMEText(body_text.encode("utf-8"), _charset='UTF-8')) -## if core_obj.send_pref in ('html', 'mixed', 'alternative'): -# html_body = body.get('html', u'') -# if len(html_body) == 0 or html_body == u'': -# html_body = body.get('text', u'

<Empty Message>

').replace('\n', '
').replace('\r', '
') -# html_body = tools.ustr(html_body) -# text_part.attach(MIMEText(html_body.encode("utf-8"), _subtype='html', _charset='UTF-8')) -# -# #Now add attachments if any, wrapping into a container multipart/mixed if needed -# if payload: -# for file in payload: -# part = MIMEBase('application', "octet-stream") -# part.set_payload(base64.decodestring(payload[file])) -# part.add_header('Content-Disposition', 'attachment; filename="%s"' % file) -# Encoders.encode_base64(part) -# payload_part.attach(part) -# except Exception, error: -# logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:MIME Error\nDescription: %s") % (id, error)) -# return {'error_msg': _("Server Send Error\nDescription: %s")%error} -# try: -# serv.sendmail(payload_part['From'], addresses_l['all-recipients'], payload_part.as_string()) -# except Exception, error: -# logging.getLogger('email_template').error(_("Mail from Account %s failed. Probable Reason: Server Send Error\n Description: %s"), id, error, exc_info=True) -# return {'error_msg': _("Server Send Error\nDescription: %s")%error} -# #The mail sending is complete -# serv.close() -# logger.notifyChannel(_("Email Template"), netsvc.LOG_INFO, _("Mail from Account %s successfully Sent.") % (id)) -# return True -# else: -# logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id) -# return {'nodestroy':True,'error_msg': _("Mail from Account %s failed. Probable Reason:Account not approved")% id} -# -# def extracttime(self, time_as_string): -# """ -# TODO: DOC THis -# """ -# logger = netsvc.Logger() -# #The standard email dates are of format similar to: -# #Thu, 8 Oct 2009 09:35:42 +0200 -# date_as_date = False -# convertor = {'+':1, '-':-1} -# try: -# time_as_string = time_as_string.replace(',', '') -# date_list = time_as_string.split(' ') -# date_temp_str = ' '.join(date_list[1:5]) -# if len(date_list) >= 6: -# sign = convertor.get(date_list[5][0], False) -# else: -# sign = False -# try: -# dt = datetime.datetime.strptime( -# date_temp_str, -# "%d %b %Y %H:%M:%S") -# except: -# try: -# dt = datetime.datetime.strptime( -# date_temp_str, -# "%d %b %Y %H:%M") -# except: -# return False -# if sign: -# try: -# offset = datetime.timedelta( -# hours=sign * int( -# date_list[5][1:3] -# ), -# minutes=sign * int( -# date_list[5][3:5] -# ) -# ) -# except Exception, e2: -# """Looks like UT or GMT, just forget decoding""" -# return False -# else: -# offset = datetime.timedelta(hours=0) -# dt = dt + offset -# date_as_date = dt.strftime('%Y-%m-%d %H:%M:%S') -# except Exception, e: -# logger.notifyChannel( -# _("Email Template"), -# netsvc.LOG_WARNING, -# _( -# "Datetime Extraction failed.Date:%s \ -# \tError:%s") % ( -# time_as_string, -# 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.message').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 -# text slices with different encodes, like: -# =?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 -# expressions (?= ? ? ?=) to split the text slices -# """ -# if not text: -# return text -# p = re.compile("(=\?.*?\?.\?.*?\?=)") -# text2 = '' -# try: -# for t2 in p.split(text): -# text2 += ''.join( -# [s.decode( -# t or 'ascii' -# ) for (s, t) in decode_header(t2)] -# ).encode('utf-8') -# except: -# return text -# return text2 - -email_smtp_server() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email/email_thread.py b/addons/email/email_thread.py index e15b3228824..23cfd8595ab 100644 --- a/addons/email/email_thread.py +++ b/addons/email/email_thread.py @@ -86,9 +86,6 @@ class email_thread(osv.osv): res[thread.id] = l return res - def msg_send(self, cr, uid, id, *args, **argv): - raise Exception, _('Method is not implemented') - def history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, \ email_from=False, message_id=False, references=None, attach=None, email_cc=None, \ email_bcc=None, email_date=None, context=None): @@ -134,14 +131,14 @@ class email_thread(osv.osv): if not partner_id and case._name == 'res.partner': partner_id = case.id data = { - 'name': keyword, + 'subject': keyword, 'user_id': uid, 'model' : case._name, 'partner_id': partner_id, 'res_id': case.id, 'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'message_id': message_id, - 'description': details or (hasattr(case, 'description') and case.description or False), + 'body': details or (hasattr(case, 'description') and case.description or False), 'attachment_ids': [(6, 0, attachments)] } @@ -151,13 +148,13 @@ class email_thread(osv.osv): param = ", ".join(param) data = { - 'name': subject or _('History'), + 'subject': subject or _('History'), 'history': True, 'user_id': uid, 'model' : case._name, 'res_id': case.id, 'date': email_date or time.strftime('%Y-%m-%d %H:%M:%S'), - 'description': details, + 'body': details, 'email_to': email, 'email_from': email_from or \ (hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \ @@ -167,7 +164,6 @@ class email_thread(osv.osv): 'partner_id': partner_id, 'references': references, 'message_id': message_id, - 'folder': 'inbox', 'attachment_ids': [(6, 0, attachments)] } obj.create(cr, uid, data, context=context) @@ -247,12 +243,12 @@ class email_thread(osv.osv): model_pool.write(cr, uid, [res_id], custom_values, context=context) else: data = { - 'name': msg.get('subject'), + 'subject': msg.get('subject'), 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'user_id': False, - 'description': msg.get('body'), - 'state' : 'draft', + 'body': msg.get('body'), + #'state' : 'draft', } data.update(self.get_partner(cr, uid, msg.get('from'), context=context)) res_id = model_pool.create(cr, uid, data, context=context) diff --git a/addons/email/email_view.xml b/addons/email/email_view.xml index 0849c766c2c..787cf101418 100644 --- a/addons/email/email_view.xml +++ b/addons/email/email_view.xml @@ -12,7 +12,7 @@
- + @@ -40,11 +40,11 @@ - - + + - +