bzr revid: hmo@tinyerp.com-20110404050444-xnpa5pi0uj71a5gc
This commit is contained in:
Harry (OpenERP)
2011-04-04 10:34:44 +05:30
49 changed files with 277 additions and 930 deletions
@@ -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 )
+1 -1
View File
@@ -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):
+2 -2
View File
@@ -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,
+14 -14
View File
@@ -308,7 +308,7 @@ class crm_case(object):
return {'value': {'phone': address.phone}}
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None):
mailgate_pool = self.pool.get('mailgate.thread')
mailgate_pool = self.pool.get('email.thread')
return mailgate_pool.history(cr, uid, cases, keyword, history=history,\
subject=subject, email=email, \
details=details, email_from=email_from,\
@@ -458,7 +458,7 @@ class crm_case(object):
raise osv.except_osv(_('Error!'), ("Partner Email is not specified in Case"))
if not case.user_id.user_email:
raise osv.except_osv(_('Error!'), ("User Email is not specified in Case"))
if destination and case.section_id.user_id:
case_email = case.section_id.user_id.user_email
else:
@@ -487,18 +487,18 @@ class crm_case(object):
attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send)
# Send an email
subject = "Reminder: [%s] %s" % (str(case.id), case.name, )
email_message_obj.email_send(cr, uid,
src,
[dest],
subject,
body,
model='crm.case',
reply_to=case.section_id.reply_to,
openobject_id=str(case.id),
attach=attach_to_send
)
self._history(cr, uid, [case], _('Send'), history=True, subject=subject, email=dest, details=body, email_from=src)
subject = "Reminder: [%s] %s" % (str(case.id), case.name, )
email_message_obj.schedule_with_attach(cr, uid,
src,
[dest],
subject,
body,
model='crm.case',
reply_to=case.section_id.reply_to,
openobject_id=str(case.id),
attach=attach_to_send
)
self._history(cr, uid, [case], _('Send'), history=True, subject=subject, email=dest, details=body, email_from=src)
return True
def _check(self, cr, uid, ids=False, context=None):
+1 -1
View File
@@ -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
+3 -15
View File
@@ -40,7 +40,7 @@ class crm_lead(crm_case, osv.osv):
_name = "crm.lead"
_description = "Lead/Opportunity"
_order = "date_action, priority, id desc"
_inherit = ['mailgate.thread','res.partner.address']
_inherit = ['email.thread','res.partner.address']
def _compute_day(self, cr, uid, ids, fields, args, context=None):
"""
@param cr: the current row, from the database cursor,
@@ -326,7 +326,7 @@ class crm_lead(crm_case, osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
@@ -343,7 +343,7 @@ class crm_lead(crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
res = thread_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
if res:
vals.update(res)
@@ -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}}
+2 -2
View File
@@ -199,13 +199,13 @@
<field name="date"/>
<field name="email_to" widget="char" size="512"/>
<field name="email_cc" widget="char" size="512"/>
<field name="name" colspan="4" widget="char" size="512"/>
<field name="subject" colspan="4" widget="char" size="512"/>
<field name="history" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<field name="body" colspan="4" nolabel="1" height="250"/>
<button colspan="4" string="Reply"
name="%(email.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
+1 -1
View File
@@ -42,7 +42,7 @@ class crm_meeting(crm_case, osv.osv):
_name = 'crm.meeting'
_description = "Meeting"
_order = "id desc"
_inherit = ['mailgate.thread',"calendar.event"]
_inherit = ['email.thread',"calendar.event"]
_columns = {
# From crm.case
'name': fields.char('Summary', size=124, required=True, states={'done': [('readonly', True)]}),
+2 -2
View File
@@ -155,13 +155,13 @@
<field name="date"/>
<field name="email_to" size="512"/>
<field name="email_cc" size="512"/>
<field name="name" colspan="4" attrs="{'invisible': [('history', '=', True)]}"/>
<field name="subject" colspan="4" attrs="{'invisible': [('history', '=', True)]}"/>
<field name="display_text" colspan="4" attrs="{'invisible': [('history', '=', False)]}"/>
<field name="history" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Details">
<field name="description" colspan="4" nolabel="1"/>
<field name="body" colspan="4" nolabel="1"/>
<group attrs="{'invisible': [('history', '!=', True)]}">
<button colspan="4"
string="Reply"
+1 -1
View File
@@ -32,7 +32,7 @@ class crm_phonecall(crm_case, osv.osv):
_name = "crm.phonecall"
_description = "Phonecall"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
# From crm.case
'id': fields.integer('ID'),
+2 -2
View File
@@ -28,13 +28,13 @@
"access_res_partner_address_manager","res.partner.address.crm.user.manager","base.model_res_partner_address","base.group_sale_manager",1,0,0,0
"access_res_partner_category_manager","res.partner.category.crm.manager","base.model_res_partner_category","base.group_sale_manager",1,0,0,0
"email_email_message_manager","email.email.message.manager","email.model_email_message","base.group_sale_manager",1,0,0,0
"email_thread_manager","email.mailgate.thread.manager","email.model_mailgate_thread","base.group_sale_manager",1,1,1,1
"email_thread_manager","email.mailgate.thread.manager","email.model_email_thread","base.group_sale_manager",1,1,1,1
"access_calendar_attendee_crm_user","calendar.attendee.crm.user","model_calendar_attendee","base.group_sale_salesman",1,1,1,0
"access_calendar_attendee_crm_manager","calendar.attendee.crm.manager","model_calendar_attendee","base.group_sale_manager",1,1,1,1
"access_res_partner","res.partner.crm.user","base.model_res_partner","base.group_sale_salesman",1,1,1,0
"access_res_partner_address","res.partner.address.crm.user","base.model_res_partner_address","base.group_sale_salesman",1,1,1,0
"access_res_partner_category","res.partner.category.crm.user","base.model_res_partner_category","base.group_sale_salesman",1,1,1,0
"email_mailgate_thread","email.mailgate.thread","email.model_mailgate_thread","base.group_sale_salesman",1,1,1,1
"email_mailgate_thread","email.mailgate.thread","email.model_email_thread","base.group_sale_salesman",1,1,1,1
"email_gateway_email_message_user","email.email.message.user","email.model_email_message","base.group_sale_salesman",1,1,1,1
"access_crm_case_categ_manager","crm.case.categ manager","model_crm_case_categ","base.group_sale_manager",1,1,1,1
"access_base_action_rule_manager","base.action.rule manager","model_base_action_rule","base.group_sale_manager",1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
28 access_res_partner_address_manager res.partner.address.crm.user.manager base.model_res_partner_address base.group_sale_manager 1 0 0 0
29 access_res_partner_category_manager res.partner.category.crm.manager base.model_res_partner_category base.group_sale_manager 1 0 0 0
30 email_email_message_manager email.email.message.manager email.model_email_message base.group_sale_manager 1 0 0 0
31 email_thread_manager email.mailgate.thread.manager email.model_mailgate_thread email.model_email_thread base.group_sale_manager 1 1 1 1
32 access_calendar_attendee_crm_user calendar.attendee.crm.user model_calendar_attendee base.group_sale_salesman 1 1 1 0
33 access_calendar_attendee_crm_manager calendar.attendee.crm.manager model_calendar_attendee base.group_sale_manager 1 1 1 1
34 access_res_partner res.partner.crm.user base.model_res_partner base.group_sale_salesman 1 1 1 0
35 access_res_partner_address res.partner.address.crm.user base.model_res_partner_address base.group_sale_salesman 1 1 1 0
36 access_res_partner_category res.partner.category.crm.user base.model_res_partner_category base.group_sale_salesman 1 1 1 0
37 email_mailgate_thread email.mailgate.thread email.model_mailgate_thread email.model_email_thread base.group_sale_salesman 1 1 1 1
38 email_gateway_email_message_user email.email.message.user email.model_email_message base.group_sale_salesman 1 1 1 1
39 access_crm_case_categ_manager crm.case.categ manager model_crm_case_categ base.group_sale_manager 1 1 1 1
40 access_base_action_rule_manager base.action.rule manager model_base_action_rule base.group_sale_manager 1 1 1 1
+2 -2
View File
@@ -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,
+7 -19
View File
@@ -41,7 +41,7 @@ class crm_claim(crm.crm_case, osv.osv):
_name = "crm.claim"
_description = "Claim"
_order = "priority,date desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Claim Subject', size=128, required=True),
@@ -83,7 +83,7 @@ class crm_claim(crm.crm_case, osv.osv):
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
}
def stage_next(self, cr, uid, ids, context=None):
stage = super(crm_claim, self).stage_next(cr, uid, ids, context=context)
if stage:
@@ -97,7 +97,7 @@ class crm_claim(crm.crm_case, osv.osv):
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context)
self.history(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name)
return stage
def _get_stage_id(self, cr, uid, context=None):
"""Finds type of stage according to object.
@param self: The object pointer
@@ -171,7 +171,7 @@ class crm_claim(crm.crm_case, osv.osv):
self.write(cr, uid, [ids[i]], {'stage_id' : stage_id})
return res
def message_new(self, cr, uid, msg, context=None):
"""
Automatically calls when new email message arrives
@@ -180,7 +180,7 @@ class crm_claim(crm.crm_case, osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
@@ -197,7 +197,7 @@ class crm_claim(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
res = thread_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
if res:
vals.update(res)
@@ -221,7 +221,7 @@ class crm_claim(crm.crm_case, osv.osv):
@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 update mail’s IDs
@param ids: List of update mail’s IDs
"""
if isinstance(ids, (str, int, long)):
ids = [ids]
@@ -253,18 +253,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()
+1 -1
View File
@@ -31,7 +31,7 @@ class crm_fundraising(crm.crm_case, osv.osv):
_name = "crm.fundraising"
_description = "Fund Raising"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
'id': fields.integer('ID'),
'name': fields.char('Name', size=128, required=True),
+4 -16
View File
@@ -39,7 +39,7 @@ class crm_helpdesk(crm.crm_case, osv.osv):
_name = "crm.helpdesk"
_description = "Helpdesk"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Name', size=128, required=True),
@@ -104,7 +104,7 @@ class crm_helpdesk(crm.crm_case, osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
@@ -121,7 +121,7 @@ class crm_helpdesk(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
res = thread_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
if res:
vals.update(res)
@@ -145,7 +145,7 @@ class crm_helpdesk(crm.crm_case, osv.osv):
@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 update mail’s IDs
@param ids: List of update mail’s IDs
"""
if isinstance(ids, (str, int, long)):
ids = [ids]
@@ -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:
+1 -2
View File
@@ -19,9 +19,8 @@
#
##############################################################################
import email_smtp_server
import email_message
import email_gateway
import email_thread
import res_partner
import wizard
+1 -1
View File
@@ -37,7 +37,7 @@ The generic email system allows to send and receive emails.
'update_xml': [
"wizard/email_compose_message_view.xml",
"email_view.xml",
"email_gateway_view.xml",
"email_thread_view.xml",
"res_partner_view.xml",
'security/ir.model.access.csv',
'email_data.xml',
+2 -12
View File
@@ -1,17 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="email_smtp_server_administrator0" model="email.smtp_server">
<field name="name">Administrator</field>
<field eval="1" name="default"/>
<field eval="1" name="smtptls"/>
<field name="email_id">example@test.com</field>
<field name="state">draft</field>
<field eval="25" name="smtpport"/>
<field name="smtpserver">localhost</field>
<field eval="0" name="smtpssl"/>
</record>
<record forcecreate="True" id="ir_cron_mail_scheduler_action" model="ir.cron">
<record forcecreate="True" id="ir_cron_mail_scheduler_action" model="ir.cron">
<field name="name">Email scheduler</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
@@ -19,7 +9,7 @@
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'email.message'" name="model"/>
<field eval="'run_mail_scheduler'" name="function"/>
<field eval="'process_email_queue'" name="function"/>
<field eval="'()'" name="args"/>
</record>
</data>
+88 -95
View File
@@ -63,10 +63,10 @@ def format_date_tz(date, tz=None):
format = tools.DEFAULT_SERVER_DATETIME_FORMAT
return tools.server_to_local_timestamp(date, format, format, tz)
class email_message_template(osv.osv_memory):
_name = 'email.message.template'
class email_message_common(osv.osv_memory):
_name = 'email.message.common'
_columns = {
'name':fields.text('Subject', translate=True),
'subject':fields.text('Subject', translate=True),
'model': fields.char('Object Name', size=128, select=1),
'res_id': fields.integer('Resource ID', select=1),
'date': fields.datetime('Date'),
@@ -79,20 +79,22 @@ class email_message_template(osv.osv_memory):
'references': fields.text('References', help="References emails."),
'reply_to':fields.char('Reply-To', size=250),
'sub_type': fields.char('Sub Type', size=32),
'headers': fields.char('x_headers',size=256),
'headers': fields.text('x_headers'),
'priority':fields.integer('Priority'),
'description': fields.text('Description', translate=True),
'smtp_server_id':fields.many2one('email.smtp_server', 'SMTP Server'),
'body': fields.text('Description', translate=True),
'body_html': fields.text('HTML', help="Contains HTML version of email"),
'smtp_server_id':fields.many2one('ir.mail_server', 'SMTP Server'),
}
_rec_name='subject'
_sql_constraints = []
email_message_template()
email_message_common()
class email_message(osv.osv):
'''
Email Message
'''
_inherit = 'email.message.template'
_inherit = 'email.message.common'
_name = 'email.message'
_description = 'Email Message'
_order = 'date desc'
@@ -160,59 +162,33 @@ class email_message(osv.osv):
for message in self.browse(cr, uid, ids, context=context):
msg_txt = ''
if message.history:
msg_txt += _('%s wrote on %s:\n\t') % (message.email_from or '/', format_date_tz(message.date, tz))
if message.description:
msg_txt += self.truncate_data(cr, uid, message.description, context=context)
msg_txt += (message.email_from or '/') + _(' wrote on ') + format_date_tz(message.date, tz) + ':\n\t'
if message.body:
msg_txt += self.truncate_data(cr, uid, message.body, context=context)
else:
msg_txt = _('%s on %s:\n\t') % (message.user_id.name or '/', format_date_tz(message.date, tz))
msg_txt += message.name
msg_txt = (message.user_id.name or '/') + _(' on ') + format_date_tz(message.date, tz) + ':\n\t'
msg_txt += message.subject
result[message.id] = msg_txt
return result
_columns = {
'message': fields.text('Description'),
'partner_id': fields.many2one('res.partner', 'Partner'),
'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments'),
'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([
('draft', 'Draft'),
('sending', 'Sending'),
('waiting', 'Waiting'),
('outgoing', 'Outgoing'),
('sent', 'Sent'),
('received', 'Received'),
('exception', 'Exception'),
], 'State', readonly=True),
'auto_delete': fields.boolean('Auto Delete', help="Permanently delete emails after sending"),
}
_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
@@ -221,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]
@@ -249,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 '',
@@ -266,20 +225,21 @@ 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',
'state': 'outgoing',
'auto_delete': auto_delete
}
email_msg_id = self.create(cr, uid, msg_vals, context)
if attach:
attachment_ids = []
for attachment in attach:
attachment_data = {
'name': (subject or '') + _(' (Email Attachment)'),
'name': attachment[0],
'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,
}
@@ -289,7 +249,7 @@ class email_message(osv.osv):
return email_msg_id
def process_retry(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state':'waiting'}, context)
return self.write(cr, uid, ids, {'state':'outgoing'}, context)
def process_email_queue(self, cr, uid, ids=None, context=None):
if ids is None:
@@ -297,39 +257,16 @@ 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':'outgoing'}, context)
for message in self.browse(cr, uid, ids, context):
try:
attachments = []
for attach in message.attachment_ids:
attachments.append((attach.datas_fname ,base64.b64decode(attach.datas)))
smtp_server = message.smtp_server_id
if not smtp_server:
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.smtpserver 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:
@@ -340,6 +277,62 @@ class email_message(osv.osv):
self.write(cr, uid, [message.id], {'state':'exception'}, context)
return ids
def send_email(self, cr, uid, ids, auto_commit=False, context=None):
if context is None:
context = {}
attachment = []
smtp_server_obj = self.pool.get('ir.mail_server')
attachment_pool = self.pool.get('ir.attachment')
for message in self.browse(cr, uid, ids, context):
try:
smtp_server = message.smtp_server_id
if not smtp_server:
smtp_ids = smtp_server_obj.search(cr, uid, [])
if smtp_ids:
smtp_server = smtp_server_obj.browse(cr, uid, smtp_ids, context)[0]
attachments = []
for attach in message.attachment_ids:
attachments.append((attach.datas_fname ,base64.b64decode(attach.datas)))
if message.state in ['outgoing', 'exception']:
msg = smtp_server_obj.pack_message(cr, uid, message.subject, message.body,
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)
res = smtp_server_obj.send_email(cr, uid, message.email_from,
message.email_to and message.email_to.split(',') or [],
msg,
mail_server_id = message.smtp_server_id.id or None,
smtp_server=smtp_server and smtp_server.smtp_host or None,
smtp_port=smtp_server and smtp_server.smtp_port or None,
smtp_user=smtp_server and smtp_server.smtp_user or None,
smtp_password=smtp_server and smtp_server.smtp_pass or None,
ssl=smtp_server and smtp_server.smtp_ssl or False,
tsl=smtp_server and smtp_server.smtp_tsl,
debug=message.debug)
else:
raise osv.except_osv(_('Error !'), _('No messages in outgoing or exception state!'))
sent_emails = self.search(cr, uid, [('state','=','sent'), ('auto_delete','=',True)], context=context)
if sent_emails:
for sent in self.browse(cr, uid, sent_emails, context):
if sent.attachment_ids:
attachment_pool.unlink(cr, uid, [attachment.id for attachment in sent.attachment_ids], context=context)
self.unlink(cr, uid, sent.id, context=context)
if auto_commit == True:
cr.commit()
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") % (message.id, error))
self.write(cr, uid, [message.id], {'state':'exception'}, context)
return False
return True
# OLD Code.
# def send_all_mail(self, cr, uid, ids=None, context=None):
# if ids is None:
-376
View File
@@ -1,376 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 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/>
#
##############################################################################
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" <d@b.com> , 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 <john@doe.com>",
),
'email_id': fields.char('From Email',
size=120, required=True,
help="eg: 'john@doe.com' or 'John Doe <john@doe.com>'"),
'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'<Empty Message>')
## 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'<p>&lt;Empty Message&gt;</p>').replace('\n', '<br/>').replace('\r', '<br/>')
# 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?= <enricmarti@company.com>,
# =?Windows-1252?Q?David_G=F3mez?= <david@company.com>
# Sometimes they include extra " character at the beginning/
# end of the contact name, like:
# "=?iso-8859-1?Q?Enric_Mart=ED?=" <enricmarti@company.com>
# 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:
@@ -34,12 +34,12 @@ import xmlrpclib
_logger = logging.getLogger('mailgate')
class mailgate_thread(osv.osv):
class email_thread(osv.osv):
'''
Mailgateway Thread
Email Thread
'''
_name = 'mailgate.thread'
_description = 'Mailgateway Thread'
_name = 'email.thread'
_description = 'Email Thread'
_columns = {
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', readonly=True),
@@ -71,7 +71,7 @@ class mailgate_thread(osv.osv):
def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None):
raise Exception, _('Method is not implemented')
def message_followers(self, cr, uid, ids, context=None):
def thread_followers(self, cr, uid, ids, context=None):
""" Get a list of emails of the people following this thread
"""
res = {}
@@ -86,9 +86,6 @@ class mailgate_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 mailgate_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 mailgate_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,23 +164,10 @@ class mailgate_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)
return True
mailgate_thread()
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 mailgate_tool(osv.osv_memory):
_name = 'email.server.tools'
_description = "Email Server Tools"
def _decode_header(self, text):
"""Returns unicode() string conversion of the the given encoded smtp header"""
@@ -194,45 +178,6 @@ class mailgate_tool(osv.osv_memory):
def to_email(self,text):
return re.findall(r'([^ ,<@]+@[^> ,]+)',text)
def history(self, cr, uid, model, res_ids, msg, attach, context=None):
"""This function creates history for mails fetched
@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 model: OpenObject Model
@param res_ids: Ids of the record of OpenObject model created
@param msg: Email details
@param attach: Email attachments
"""
if isinstance(res_ids, (int, long)):
res_ids = [res_ids]
msg_pool = self.pool.get('email.message')
for res_id in res_ids:
case = self.pool.get(model).browse(cr, uid, res_id, context=context)
partner_id = hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False
if not partner_id and model == 'res.partner':
partner_id = res_id
msg_data = {
'name': msg.get('subject', 'No subject'),
'date': msg.get('date'),
'description': msg.get('body', msg.get('from')),
'history': True,
'partner_id': partner_id,
'model': model,
'email_cc': msg.get('cc'),
'email_from': msg.get('from'),
'email_to': msg.get('to'),
'message_id': msg.get('message-id'),
'references': msg.get('references') or msg.get('in-reply-to'),
'res_id': res_id,
'user_id': uid,
'folder': 'inbox',
'attachment_ids': [(6, 0, attach)]
}
msg_pool.create(cr, uid, msg_data, context=context)
return True
def email_forward(self, cr, uid, model, res_ids, msg, email_error=False, context=None):
"""Sends an email to all people following the thread
@param res_id: Id of the record of OpenObject model created from the email message
@@ -242,8 +187,8 @@ class mailgate_tool(osv.osv_memory):
model_pool = self.pool.get(model)
for res in model_pool.browse(cr, uid, res_ids, context=context):
message_followers = model_pool.message_followers(cr, uid, [res.id])[res.id]
message_followers_emails = self.to_email(','.join(filter(None, message_followers)))
thread_followers = model_pool.thread_followers(cr, uid, [res.id])[res.id]
message_followers_emails = self.to_email(','.join(filter(None, thread_followers)))
message_recipients = self.to_email(','.join(filter(None,
[self._decode_header(msg['from']),
self._decode_header(msg['to']),
@@ -298,12 +243,12 @@ class mailgate_tool(osv.osv_memory):
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)
@@ -486,6 +431,14 @@ class mailgate_tool(osv.osv_memory):
return res
mailgate_tool()
email_thread()
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)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -3,8 +3,8 @@
<data>
<record model="ir.ui.view" id="view_mailgate_thread_form">
<field name="name">mailgate.thread.form</field>
<field name="model">mailgate.thread</field>
<field name="name">email.thread.form</field>
<field name="model">email.thread</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Mailgateway Thread">
@@ -14,7 +14,7 @@
<field name="display_text"/>
</tree>
<form string="Mailgate History">
<field name="name" widget="char"/>
<field name="subject" widget="char"/>
<field name="date"/>
<field name="user_id"/>
<field name="message_id"/>
@@ -41,8 +41,8 @@
</record>
<record model="ir.ui.view" id="view_mailgate_thread_tree">
<field name="name">mailgate.thread.tree</field>
<field name="model">mailgate.thread</field>
<field name="name">email.thread.tree</field>
<field name="model">email.thread</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Mailgateway Thread">
@@ -54,7 +54,7 @@
<!-- Emails action-->
<record model="ir.actions.act_window" id="action_view_mailgate_thread">
<field name="name">Mailgateway Threads</field>
<field name="res_model">mailgate.thread</field>
<field name="res_model">email.thread</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_mailgate_thread_tree"/>
@@ -87,4 +87,4 @@
</record>
</data>
</openerp>
</openerp>
+8 -88
View File
@@ -12,7 +12,7 @@
<field name="arch" type="xml">
<form string="Email message">
<group colspan="4" col="6">
<field name="name" widget="char" size="512"/>
<field name="subject" widget="char" size="512"/>
<field name="date"/>
<field name="user_id" string="User"/>
<field name="partner_id" readonly="1" />
@@ -40,11 +40,11 @@
<field name="references" widget="char" size="4096"/>
</group>
<separator string="Description" colspan="4"/>
<field name="description" nolabel="1" colspan="4"/>
<group col="4" colspan="4" attrs="{'invisible':[('folder','not in',['drafts','outbox'])]}">
<field name="body" nolabel="1" colspan="4"/>
<group col="4" colspan="4">
<separator string="" colspan="4"/>
<field name="state"/>
<button name="process_queue" string="Send" type="object" icon="gtk-execute" states='draft,waiting,sending'/>
<button name="process_email_queue" string="Send" type="object" icon="gtk-execute" states='draft,waiting,sending'/>
<button name="process_retry" string="Re-Try" type="object" icon="gtk-execute" states='exception'/>
</group>
</page>
@@ -55,12 +55,12 @@
<page string="Advanced">
<group col="4" colspan="4">
<field name="smtp_server_id"/>
<field name="folder"/>
<field name="sub_type"/>
<field name="headers"/>
<field name="priority"/>
<field name="debug"/>
<field name="history"/>
<field name="auto_delete"/>
</group>
</page>
</notebook>
@@ -73,14 +73,13 @@
<field name="model">email.message</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree colors="gray:folder in ('trash')" string="Emails">
<tree string="Emails">
<field name="date"/>
<field name="name"/>
<field name="subject"/>
<field name="email_from"/>
<field name="user_id" string="User"/>
<field name="message_id" string="Message" invisible="1"/>
<field name="partner_id" invisible="1"/>
<field name="folder"/>
<field name="state"/>
<button name="open_document" string="Open Document" type="object" icon="gtk-jump-to"/>
<button name="open_attachment" string="Open Attachments" type="object" icon="gtk-jump-to"/>
@@ -94,16 +93,11 @@
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Email Search">
<filter icon="terp-document-new" string="Draft" domain="[('folder','=','drafts')]"/>
<filter icon="terp-personal" string="Inbox" domain="[('folder','=','inbox')]"/>
<filter icon="terp-check" string="Outbox" domain="[('folder','=','outbox')]"/>
<filter icon="terp-partner" string="Sent Items" domain="[('folder','=','sent')]"/>
<filter icon="terp-mail_delete" string="Trash" domain="[('folder','=','trash')]"/>
<separator orientation="vertical"/>
<filter icon="terp-call-start" string="Waiting" domain="[('state','=','waiting')]"/>
<filter icon="terp-gtk-stop" string="Exception" domain="[('state','=','exception')]"/>
<field name="email_from"/>
<field name="name"/>
<field name="subject"/>
<field name="date"/>
<field name="user_id" string="User"/>
<field name="partner_id" string="Partner Name"/>
@@ -150,82 +144,8 @@
parent="menu_email_message_tools"
action="action_view_mail_message" />
<record model="ir.ui.view" id="email_smtp_server_form">
<field name="name">email.smtp_server.form</field>
<field name="model">email.smtp_server</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Smtp Server Configuration">
<group colspan="4">
<field name="name"/>
<field name="default"/>
</group>
<notebook colspan="4">
<page string="Configuration">
<separator string="Server Information" colspan="4"/>
<group colspan="4" col="8">
<field name="smtpserver"/>
<field name="smtpport"/>
<field name="smtpssl"/>
<field name="smtptls"/>
</group>
<separator string="User Information" colspan="4"/>
<group col="6" colspan="4">
<field name="email_id"/>
<field name="smtpuname"/>
<field name="smtppass" password="True"/>
</group>
<separator string="" colspan="4"/>
<label string="" colspan="2"/>
<button name="test_smtp_connection" type="object" string="Test Connection" icon="gtk-network" colspan="2"/>
</page>
</notebook>
</form>
</field>
</record>
<record model="ir.ui.view" id="email_smtp_server_tree">
<field name="name">email.smtp_server.tree</field>
<field name="model">email.smtp_server</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="SMTP Server">
<field name="name"/>
<field name="email_id"/>
<field name="smtpserver"/>
<field name="default"/>
<button name="test_smtp_connection" type="object" string="Test Connection" icon="gtk-network"/>
</tree>
</field>
</record>
<record id="view_email_smtp_server_search" model="ir.ui.view">
<field name="name">email_smtp.server.search</field>
<field name="model">email.smtp_server</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Smtp Server">
<field name="name"/>
<field name="email_id"/>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_email_smtp_server_tree_all">
<field name="name">Outgoing Servers</field>
<field name="res_model">email.smtp_server</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="email_smtp_server_tree" />
<field name="context">{'group_by': [], 'search_default_draft': 1, 'search_default_my': 1}</field>
<field name="search_view_id" ref="view_email_smtp_server_search"/>
</record>
<menuitem name="Email" id="menu_config_email" parent="base.menu_lunch_survey_root" sequence="20"/>
<menuitem name="Outgoing Servers" id="menu_email_smtp_server_all" parent="menu_config_email" action="action_email_smtp_server_tree_all"/>
</data>
</openerp>
@@ -54,7 +54,7 @@ class email_parser(object):
try:
# pass message as bytes because we don't know its encoding until we parse its headers
# and hence can't convert it to utf-8 for transport
res_id = self.rpc('email.server.tools', 'process_email', self.model, xmlrpclib.Binary(message), custom_values)
res_id = self.rpc('email.thread', 'process_email', self.model, xmlrpclib.Binary(message), custom_values)
except Exception:
logger = logging.getLogger('mail-gateway')
logger.warning('Failed to process incoming email. Source of the failed mail is available at debug level.', exc_info=True)
+1 -2
View File
@@ -1,4 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_email_smtp_server","email.smtp_server","model_email_smtp_server",,1,0,0,0
"access_email_message","email.message","model_email_message",,1,0,0,0
"access_mailgate_thread","mailgate.thread","model_mailgate_thread",,1,0,0,0
"access_mailgate_thread","mailgate.thread","model_email_thread",,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
access_email_smtp_server email.smtp_server model_email_smtp_server 1 0 0 0
2 access_email_message email.message model_email_message 1 0 0 0
3 access_mailgate_thread mailgate.thread model_mailgate_thread model_email_thread 1 0 0 0
+13 -18
View File
@@ -25,7 +25,7 @@ import tools
class email_compose_message(osv.osv_memory):
_name = 'email.compose.message'
_inherit = 'email.message.template'
_inherit = 'email.message.common'
_description = 'This is the wizard for Compose E-mail'
def default_get(self, cr, uid, fields, context=None):
@@ -43,8 +43,8 @@ class email_compose_message(osv.osv_memory):
if not vals:
return result
if 'name' in fields:
result.update({'name' : vals.get('name','')})
if 'subject' in fields:
result.update({'subject' : vals.get('name','')})
if 'email_to' in fields:
result.update({'email_to' : vals.get('email_to','')})
@@ -52,8 +52,8 @@ class email_compose_message(osv.osv_memory):
if 'email_from' in fields:
result.update({'email_from' : vals.get('email_from','')})
if 'description' in fields:
result.update({'description' : vals.get('description','')})
if 'body' in fields:
result.update({'body' : vals.get('description','')})
if 'model' in fields:
result.update({'model' : vals.get('model','')})
@@ -135,11 +135,11 @@ class email_compose_message(osv.osv_memory):
message_pool = self.pool.get('email.message')
if message_id:
message_data = message_pool.browse(cr, uid, message_id, context)
subject = tools.ustr(message_data and message_data.name or '')
subject = tools.ustr(message_data and message_data.subject or '')
if context.get('mail','') == 'reply':
subject = "Re :- " + subject
description = message_data and message_data.description and message_data.description or ''
description = message_data and message_data.body or ''
message_body = False
if context.get('mail','') == 'reply':
header = '-------- Original Message --------'
@@ -150,8 +150,8 @@ class email_compose_message(osv.osv_memory):
description = '\n'.join([header, sender, email_to, sentdate, desc])
result.update({
'description' : description,
'name' : subject,
'body' : description,
'subject' : subject,
'message_id' : message_data and message_data.message_id or False,
'attachment_ids' : message_data and message_pool.read(cr, uid, message_id, ['attachment_ids'])['attachment_ids'] or [],
'res_id' : message_data and message_data.res_id or False,
@@ -183,25 +183,20 @@ class email_compose_message(osv.osv_memory):
result.update({
'email_from': vals.get('email_from',''),
'email_to': vals.get('email_to',''),
'name': vals.get('name',''),
'description': vals.get('description',''),
'subject': vals.get('name',''),
'body': vals.get('description',''),
'email_cc': vals.get('email_cc',''),
'email_bcc': vals.get('email_bcc',''),
'reply_to': vals.get('reply_to',''),
})
return {'value': result}
def on_change_smtp_server(self, cr, uid, ids, smtp_server_id, email_from, context=None):
if not email_from and smtp_server_id:
email_smtp_server_pool = self.pool.get("email.smtp_server")
email_from = email_smtp_server_pool.browse(cr, uid, smtp_server_id, context).email_id or False
return {'value':{'email_from': email_from}}
def save_to_drafts(self, cr, uid, ids, context=None):
if context is None:
context = {}
email_id = self.save_to_mailbox(cr, uid, ids, context=context)
self.pool.get('email.message').write(cr, uid, email_id, {'folder':'drafts', 'state': 'draft'}, context)
self.pool.get('email.message').write(cr, uid, email_id, {'state': 'outgoing'}, context)
return {'type': 'ir.actions.act_window_close'}
def send_mail(self, cr, uid, ids, context=None):
@@ -223,7 +218,7 @@ class email_compose_message(osv.osv_memory):
references = mail.references and mail.references + "," + mail.message_id or mail.message_id
else:
message_id = mail.message_id
email_id = email_message_pool.email_send(cr, uid, mail.email_from, mail.email_to, mail.name, mail.description,
email_id = email_message_pool.schedule_with_attach(cr, uid, mail.email_from, mail.email_to, mail.subject, mail.body,
model=mail.model, email_cc=mail.email_cc, email_bcc=mail.email_bcc, reply_to=mail.reply_to,
attach=attachment, message_id=message_id, references=references, openobject_id=int(mail.res_id), debug=mail.debug,
subtype=mail.sub_type, x_headers=mail.headers, priority=mail.priority, smtp_server_id=mail.smtp_server_id and mail.smtp_server_id.id, context=context)
@@ -12,19 +12,18 @@
<field name="model" invisible="1"/>
<field name="res_id" invisible="context.get('active_model','') != 'ir.ui.menu'"
colspan="4" on_change="on_change_referred_doc(model, res_id, context)"/>
<field name="smtp_server_id" widget="selection" colspan="4"
on_change="on_change_smtp_server(smtp_server_id, email_from)"/>
<field name="smtp_server_id" widget="selection" colspan="4"/>
<field name="email_from" colspan="4" required="1"/>
<field name="email_to" colspan="4" required="1"/>
<field name="email_cc" colspan="4"/>
<field name="email_bcc" colspan="4"/>
<field name="reply_to" colspan="4"/>
<field name="name" colspan="4" widget="char" size="512"/>
<field name="subject" colspan="4" widget="char" size="512"/>
</group>
<separator string="" colspan="4"/>
<notebook colspan="4">
<page string="Body">
<field name="description" colspan="4" nolabel="1"/>
<field name="body" colspan="4" nolabel="1"/>
</page>
<page string="Attachments">
<label string="Add here all attachments of the current document you want to include in the Email." colspan="4"/>
+26 -76
View File
@@ -33,7 +33,7 @@ import pooler
class email_template(osv.osv):
"Templates for sending Email"
_inherit = 'email.message.template'
_inherit = 'email.message.common'
_name = "email.template"
_description = 'Email Templates for Models'
@@ -124,13 +124,6 @@ This is useful for CRM leads for example"),
'Wizard Button',
help="Button in the side bar of the form view of this Resource that will invoke the Window Action",
readonly=True),
'allowed_groups':fields.many2many(
'res.groups',
'template_group_rel',
'templ_id', 'group_id',
string="Allowed User Groups",
help="Only users from these groups will be"
" allowed to send mails from this Template"),
'model_object_field':fields.many2one(
'ir.model.fields',
string="Field",
@@ -138,37 +131,36 @@ This is useful for CRM leads for example"),
"\nIf it is a relationship field you will be able to "
"choose the nested values in the box below\n(Note:If "
"there are no values make sure you have selected the"
" correct model)",
store=False),
" correct model)"),
'sub_object':fields.many2one(
'ir.model',
'Sub-model',
help='When a relation field is used this field'
' will show you the type of field you have selected',
store=False),
' will show you the type of field you have selected'),
'sub_model_object_field':fields.many2one(
'ir.model.fields',
'Sub Field',
help="When you choose relationship fields "
"this field will specify the sub value you can use.",
store=False),
"this field will specify the sub value you can use."),
'null_value':fields.char(
'Null Value',
help="This Value is used if the field is empty",
size=50, store=False),
size=50),
'copyvalue':fields.char(
'Expression',
size=100,
help="Copy and paste the value in the "
"location you want to use a system value.",
store=False),
'table_html':fields.text(
'HTML code',
help="Copy this html code to your HTML message"
" body for displaying the info in your mail.",
store=False),
"location you want to use a system value."),
'auto_delete': fields.boolean('Auto Delete', help="Permanently delete emails after sending"),
'model': fields.related('model_id','model', type='char', size=128, string='Object'),
'model': fields.related('model_id','model', type='char', size=128, string='Object', help="Placeholders can be used here."),
'email_from': fields.char('From', size=128, help="Email From. Placeholders can be used here."),
'email_to': fields.char('To', size=256, help="Email Recipients. Placeholders can be used here."),
'email_cc': fields.char('Cc', size=256, help="Carbon Copy Email Recipients. Placeholders can be used here."),
'email_bcc': fields.char('Bcc', size=256, help="Blind Carbon Copy Email Recipients. Placeholders can be used here."),
'message_id': fields.char('Message Id', size=1024, select=1, help="Message Id on Email. Placeholders can be used here."),
'reply_to':fields.char('Reply-To', size=250, help="Placeholders can be used here."),
'body': fields.text('Description', translate=True, help="Placeholders can be used here."),
'body_html': fields.text('HTML', help="Contains HTML version of email. Placeholders can be used here."),
}
_sql_constraints = [
@@ -220,10 +212,6 @@ This is useful for CRM leads for example"),
except:
raise osv.except_osv(_("Warning"), _("Deletion of Record failed"))
def delete_action(self, cr, uid, ids, context=None):
self.unlink_action(cr, uid, ids, context=context)
return True
def unlink(self, cr, uid, ids, context=None):
self.unlink_action(cr, uid, ids, context=context)
return super(email_template, self).unlink(cr, uid, ids, context=context)
@@ -360,14 +348,14 @@ This is useful for CRM leads for example"),
return {'value':result}
def _generate_email(self, cr, uid, template_id, record_id, context=None):
def generate_email(self, cr, uid, template_id, record_id, context=None):
"""
Generates an email from the template for
record record_id of target object
"""
if context is None:
context = {}
smtp_pool = self.pool.get('email.smtp_server')
smtp_pool = self.pool.get('ir.mail_server')
email_message_pool = self.pool.get('email.message')
report_xml_pool = self.pool.get('ir.actions.report.xml')
template = self.get_email_template(cr, uid, template_id, record_id, context)
@@ -375,7 +363,7 @@ This is useful for CRM leads for example"),
if not smtp_server_id and template.smtp_server_id:
smtp_server_id = template.smtp_server_id.id
else:
smtp_ids = smtp_pool.search(cr, uid, [('default','=',True)])
smtp_ids = smtp_pool.search(cr, uid, [])
smtp_server_id = smtp_ids and smtp_ids[0]
smtp_server = smtp_pool.browse(cr, uid, smtp_server_id, context=context)
# determine name of sender, either it is specified in email_id
@@ -394,8 +382,9 @@ This is useful for CRM leads for example"),
'email_cc': self.get_template_value(cr, uid, template.email_cc, model, record_id, context),
'email_bcc': self.get_template_value(cr, uid, template.email_bcc, model, record_id, context),
'reply_to': self.get_template_value(cr, uid, template.reply_to, model, record_id, context),
'name': self.get_template_value(cr, uid, template.subject, model, record_id, context),
'description': self.get_template_value(cr, uid, template.description, model, record_id, context),
'subject': self.get_template_value(cr, uid, template.subject, model, record_id, context),
'body': self.get_template_value(cr, uid, template.description, model, record_id, context),
'auto_delete': self.get_template_value(cr, uid, template.auto_delete, model, record_id, context),
#'body_html': self.get_template_value(cr, uid, template.body_html, model, record_id, context),
}
@@ -405,7 +394,7 @@ This is useful for CRM leads for example"),
elif template['track_campaign_item']:
# get appropriate message-id
values.update({'message_id': tools.misc.generate_tracking_message_id(record_id)})
values.update({'message_id': smtp_pool.generate_tracking_message_id(record_id)})
#Use signatures if allowed
if template.user_signature:
@@ -444,53 +433,14 @@ This is useful for CRM leads for example"),
#Send emails
context.update({'notemplate':True})
email_id = email_message_pool.email_send(cr, uid, values.get('email_from'), values.get('email_to'), values.get('name'), values.get('description'),
model=model, email_cc=values.get('email_cc'), email_bcc=values.get('email_bcc'), reply_to=values.get('reply_to'),
attach=attachment, message_id=values.get('message_id'), openobject_id=record_id, debug=True, subtype='plain', x_headers={}, priority='3', smtp_server_id=smtp_server.id, context=context)
email_id = email_message_pool.schedule_with_attach(cr, uid, values.get('email_from'), values.get('email_to'), values.get('name'),
values.get('description'), model=model, email_cc=values.get('email_cc'), email_bcc=values.get('email_bcc'),
reply_to=values.get('reply_to'), attach=attachment, message_id=values.get('message_id'), openobject_id=record_id,
debug=True, subtype='plain', x_headers={}, priority='3', smtp_server_id=smtp_server.id, auto_delete=values.get('auto_delete'), context=context)
email_message_pool.write(cr, uid, email_id, {'template_id': context.get('template_id',template.id)})
return email_id
def generate_email(self, cr, uid, template_id, record_id, context=None):
if context is None:
context = {}
email_id = self._generate_email(cr, uid, template_id, record_id, context)
return email_id
email_template()
class email_message(osv.osv):
_inherit = 'email.message'
_columns = {
'template_id': fields.many2one('email.template', 'Email-Template', readonly=True),
}
def process_email_queue(self, cr, uid, ids=None, context=None):
result = super(email_message, self).process_email_queue(cr, uid, ids, context)
attachment_obj = self.pool.get('ir.attachment')
for message in self.browse(cr, uid, result, context):
if message.template_id and message.template_id.auto_delete:
self.unlink(cr, uid, [id], context=context)
attachment_ids = [x.id for x in message.attachments_ids]
attachment_obj.unlink(cr, uid, attachment_ids, context=context)
return result
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):
if context is None:
context = {}
notemplate = context.get('notemplate', True)
if (not notemplate) and model and openobject_id:
template_pool = self.pool.get('email.template')
template_ids = template_pool.search(cr, uid, [('model','=',model)])
if template_ids and len(template_ids):
template_id = template_ids[0]
return template_pool.generate_email(cr, uid, template_id, openobject_id, context=context)
return super(email_message, self).email_send(cr, uid, email_from, email_to, subject, body, model=model, email_cc=email_cc, email_bcc=email_bcc, reply_to=reply_to, attach=attach,
message_id=message_id, references=references, openobject_id=openobject_id, debug=debug, subtype=subtype, x_headers=x_headers, priority=priority, smtp_server_id=smtp_server_id, context=context)
email_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+2 -16
View File
@@ -33,7 +33,7 @@
<field name="subject" colspan="4" required="1"/>
<notebook>
<page string="Body">
<field name="description" colspan="4" nolabel="1"/>
<field name="body" colspan="4" nolabel="1"/>
</page>
<!-- <page string="Body (Raw HTML)">
<field name="def_body_html" colspan="4" nolabel="1"/>
@@ -70,7 +70,7 @@
<button name="create_action" string="Create Action" type="object" icon="gtk-execute" colspan="2" attrs="{'invisible':[('ref_ir_act_window','!=',False), ('ref_ir_value','!=',False)]}"/>
<field name="ref_ir_act_window"/>
<field name="ref_ir_value"/>
<button name="delete_action" string="Delete Action" type="object" icon="gtk-delete" colspan="2" attrs="{'invisible':[('ref_ir_act_window','=',False), ('ref_ir_value','=',False)]}"/>
<button name="unlink_action" string="Delete Action" type="object" icon="gtk-delete" colspan="2" attrs="{'invisible':[('ref_ir_act_window','=',False), ('ref_ir_value','=',False)]}"/>
</group>
<group colspan="2" col="2">
<separator string="Advanced Options" colspan="2"/>
@@ -155,19 +155,5 @@
<menuitem name="Templates" id="menu_email_template_all_tools"
parent="email.menu_email_message_tools" action="action_email_template_tree_all" />
<!-- Inherit email.message view -->
<record model="ir.ui.view" id="view_email_message_template_form">
<field name="name">email.message.template.form</field>
<field name="model">email.message</field>
<field name="inherit_id" ref="email.view_email_message_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="debug" position="after">
<field name="template_id"/>
</field>
</field>
</record>
</data>
</openerp>
@@ -44,8 +44,8 @@ class email_compose_message(osv.osv_memory):
result.update({
'template_id' : template.id,
'smtp_server_id' : template.smtp_server_id.id,
'description' : _get_template_value('description') or False,
'name' : _get_template_value('subject') or False,
'body' : _get_template_value('body') or False,
'subject' : _get_template_value('subject') or False,
'attachment_ids' : template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] or [],
'res_id' : res_id or False,
'email_to' : _get_template_value('email_to') or False,
@@ -92,11 +92,11 @@ class email_compose_message(osv.osv_memory):
if 'email_bcc' in fields:
result.update({'email_bcc' : vals.get('email_bcc', False)})
if 'name' in fields:
result.update({'name' : vals.get('name', False)})
if 'subject' in fields:
result.update({'subject' : vals.get('name', False)})
if 'description' in fields:
result.update({'description' : vals.get('description', False)})
if 'body' in fields:
result.update({'body' : vals.get('description', False)})
if 'reply_to' in fields:
result.update({'reply_to' : vals.get('reply_to', False)})
@@ -93,13 +93,14 @@ class email_template_preview(osv.osv_memory):
if template.message_id:
vals['message_id'] = self.get_template_value(cr, uid, message_id, model, res_id, context)
elif template.track_campaign_item:
vals['message_id'] = tools.misc.generate_tracking_message_id(res_id)
smtp_server_obj = self.pool.get('ir.mail_server')
vals['message_id'] = smtp_server_obj.generate_tracking_message_id(res_id)
vals['subject'] = self.get_template_value(cr, uid, template.subject, model, res_id, context)
description = self.get_template_value(cr, uid, template.description, model, res_id, context) or ''
description = self.get_template_value(cr, uid, template.body, model, res_id, context) or ''
if template.user_signature:
signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
description += '\n' + signature
vals['description'] = description
vals['body'] = description
vals['report_name'] = self.get_template_value(cr, uid, template.report_name, model, res_id, context)
return {'value':vals}
@@ -24,7 +24,7 @@
<separator string= "Body" colspan="2" />
<!--<separator string= "Body(Html)" colspan="2" />-->
<newline/>
<field name="description" nolabel="1" colspan="2" readonly="1"/>
<field name="body" nolabel="1" colspan="2" readonly="1"/>
<!-- <field name="body_html" nolabel="1" colspan="2" readonly="1"/>-->
</group>
<field name="report_name" colspan="2" readonly="1"/>
@@ -91,8 +91,8 @@ class email_template_send_wizard(osv.osv_memory):
if 'subject' in fields:
result['subject'] = _get_template_value('subject')
if 'description' in fields:
result['description'] = _get_template_value('description')
if 'body' in fields:
result['body'] = _get_template_value('description')
#if 'body_html' in fields:
# result['body_html'] = _get_template_value('body_html')
@@ -132,7 +132,7 @@ class email_template_send_wizard(osv.osv_memory):
if context is None:
context = {}
mailid = self.save_to_mailbox(cr, uid, ids, context=context)
self.pool.get('email.message').write(cr, uid, mailid, {'folder':'drafts', 'state': 'draft'}, context)
self.pool.get('email.message').write(cr, uid, mailid, {'state': 'outgoing'}, context)
return {'type': 'ir.actions.act_window_close'}
def send_mail(self, cr, uid, ids, context=None):
@@ -170,7 +170,7 @@ class email_template_send_wizard(osv.osv_memory):
email_ids = []
for template in self.browse(cr, uid, ids, context=context):
for record_id in context.get('src_rec_ids',[]):
email_id = self._generate_email(cr, uid, template.id, record_id, context)
email_id = self.generate_email(cr, uid, template.id, record_id, context)
email_ids.append(email_id)
return email_ids
+2 -2
View File
@@ -282,7 +282,7 @@ class event_registration(osv.osv):
"""Event Registration"""
_name= 'event.registration'
_description = __doc__
_inherit = 'mailgate.thread'
_inherit = 'email.thread'
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
@@ -547,7 +547,7 @@ class event_registration(osv.osv):
subject = _('Auto Confirmation: [%s] %s') %(regestration.id, regestration.name)
body = regestration.event_id.mail_confirm
if subject or body:
email_message_obj.email_send(cr, uid, src, email_to, subject, body, model='event.registration', email_cc=email_cc, openobject_id=regestration.id)
email_message_obj.schedule_with_attach(cr, uid, src, email_to, subject, body, model='event.registration', email_cc=email_cc, openobject_id=regestration.id)
self.history(cr, uid, [regestration], subject, history = True, \
email=email_to, details=body, \
subject=subject, email_from=src, \
+3 -3
View File
@@ -161,7 +161,7 @@ class email_server(osv.osv):
def fetch_mail(self, cr, uid, ids, context=None):
if context is None:
context = {}
email_tool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
action_pool = self.pool.get('ir.actions.server')
context.update({'get_server': True})
for server in self.browse(cr, uid, ids, context=context):
@@ -174,7 +174,7 @@ class email_server(osv.osv):
result, data = imap_server.search(None, '(UNSEEN)')
for num in data[0].split():
result, data = imap_server.fetch(num, '(RFC822)')
res_id = email_tool.process_email(cr, user, server.object_id.model, data[0][1], attach=server.attach, context=context)
res_id = thread_pool.process_email(cr, user, server.object_id.model, data[0][1], attach=server.attach, context=context)
if res_id and server.action_id:
action_pool.run(cr, user, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]})
@@ -196,7 +196,7 @@ class email_server(osv.osv):
for num in range(1, numMsgs + 1):
(header, msges, octets) = pop_server.retr(num)
msg = '\n'.join(msges)
res_id = email_tool.process_email(cr, user, server.object_id.model, msg, attach=server.attach, context=context)
res_id = thread_pool.process_email(cr, user, server.object_id.model, msg, attach=server.attach, context=context)
if res_id and server.action_id:
action_pool.run(cr, user, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]})
+1 -1
View File
@@ -229,7 +229,7 @@ class hr_evaluation(osv.osv):
sub = phase.email_subject
dest = [child.work_email]
if dest:
email_message_obj.email_send(cr, uid, evaluation.employee_id.work_email, dest, sub, body, model='hr_evaluation.evaluation')
email_message_obj.schedule_with_attach(cr, uid, evaluation.employee_id.work_email, dest, sub, body, model='hr_evaluation.evaluation')
self.write(cr, uid, ids, {'state':'wait'}, context=context)
return True
@@ -35,7 +35,7 @@ class hr_evaluation_reminder(osv.osv_memory):
current_interview = hr_evaluation_interview_obj.browse(cr, uid, evaluation_data.get('evaluation_id'))
if current_interview.state == "waiting_answer" and current_interview.user_to_review_id.work_email :
msg = " Hello %s, \n\n Kindly post your response for '%s' survey interview. \n\n Thanks," %(current_interview.user_to_review_id.name, current_interview.survey_id.title)
email_message_obj.email_send(cr, uid, tools.config['email_from'], [current_interview.user_to_review_id.work_email],\
email_message_obj.schedule_with_attach(cr, uid, tools.config['email_from'], [current_interview.user_to_review_id.work_email],\
'Reminder to fill up Survey', msg, model='hr.evaluation.reminder')
return {'type': 'ir.actions.act_window_close'}
+3 -14
View File
@@ -82,7 +82,7 @@ class hr_applicant(crm.crm_case, osv.osv):
_name = "hr.applicant"
_description = "Applicant"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
def _compute_day(self, cr, uid, ids, fields, args, context=None):
"""
@@ -308,7 +308,7 @@ class hr_applicant(crm.crm_case, osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
attach_obj = self.pool.get('ir.attachment')
subject = msg.get('subject')
@@ -326,7 +326,7 @@ class hr_applicant(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from'))
res = thread_pool.get_partner(cr, uid, msg.get('from'))
if res:
vals.update(res)
res = self.create(cr, uid, vals, context=context)
@@ -380,17 +380,6 @@ class hr_applicant(crm.crm_case, osv.osv):
res = self.write(cr, uid, ids, vals, 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 case_open(self, cr, uid, ids, *args):
"""
@param self: The object pointer
@@ -208,7 +208,7 @@ class XMLRpcConn(object):
if attachments:
result = self.MakeAttachment([rec], mail)
attachment_ids = result.get(model, {}).get(res_id, [])
execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','history',model, res_id, msg, attachment_ids)
execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.thread','history',model, res_id, msg, attachment_ids)
new_msg += """- {0} : {1}\n""".format(object_name,str(rec[2]))
flag = True
@@ -298,7 +298,7 @@ class XMLRpcConn(object):
endCut = message_id.find(">")
message_id = message_id[startCut:endCut+1]
email.replace_header('Message-Id',message_id)
id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','process_email',section, str(email))
id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.thread','process_email',section, str(email))
if id > 0:
flag = True
return flag
+1 -1
View File
@@ -113,7 +113,7 @@ class project_task_close(osv.osv_memory):
to_adr.append(data.manager_email)
if data.partner_warn and data.partner_email:
to_adr.append(data.partner_email)
mail_id = email_message_obj.email_send(cr, uid, from_adr, to_adr, subject, tools.ustr(body), model='project.task.close', email_bcc=[from_adr])
mail_id = email_message_obj.schedule_with_attach(cr, uid, from_adr, to_adr, subject, tools.ustr(body), model='project.task.close', email_bcc=[from_adr])
if not mail_id:
raise osv.except_osv(_('Error'), _("Couldn't send mail! Check the email ids and smtp configuration settings"))
return {}
+3 -15
View File
@@ -46,7 +46,7 @@ class project_issue(crm.crm_case, osv.osv):
_name = "project.issue"
_description = "Project Issue"
_order = "priority, id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
def case_open(self, cr, uid, ids, *args):
"""
@@ -374,7 +374,7 @@ class project_issue(crm.crm_case, osv.osv):
"""
if context is None:
context = {}
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject') or _('No Title')
body = msg.get('body')
@@ -391,7 +391,7 @@ class project_issue(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from'))
res = thread_pool.get_partner(cr, uid, msg.get('from'))
if res:
vals.update(res)
context.update({'state_to' : 'draft'})
@@ -455,18 +455,6 @@ class project_issue(crm.crm_case, osv.osv):
res = self.write(cr, uid, ids, vals)
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 copy(self, cr, uid, id, default=None, context=None):
issue = self.read(cr, uid, id, ['name'], context=context)
if not default:
+2 -2
View File
@@ -113,13 +113,13 @@
<field name="date"/>
<field name="email_to" widget="char" size="512"/>
<field name="email_cc" widget="char" size="512"/>
<field name="name" colspan="4" widget="char" size="512"/>
<field name="subject" colspan="4" widget="char" size="512"/>
<field name="history" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<field name="body" colspan="4" nolabel="1" height="250"/>
<button colspan="4" string="Reply"
name="%(email.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
+7 -10
View File
@@ -25,7 +25,7 @@ import binascii
class project_tasks(osv.osv):
_name = "project.task"
_inherit = ['mailgate.thread','project.task']
_inherit = ['email.thread','project.task']
_columns={
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)], readonly=True),
@@ -38,7 +38,7 @@ class project_tasks(osv.osv):
# @param cr: the current row, from the database cursor,
# @param uid: the current user’s ID for security checks
# """
mailgate_obj = self.pool.get('email.server.tools')
thread_obj = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
msg_from = msg.get('from')
@@ -49,7 +49,7 @@ class project_tasks(osv.osv):
'description': body,
'planned_hours' : 0.0,
}
res = mailgate_obj.get_partner(cr, uid, msg_from)
res = thread_obj.get_partner(cr, uid, msg_from)
if res:
data.update(res)
res = self.create(cr, uid, data)
@@ -69,8 +69,8 @@ class project_tasks(osv.osv):
return res
def message_update(self, cr, uid, id, msg, data={}, default_act='pending'):
mailgate_obj = self.pool.get('email.server.tools')
msg_actions, body_data = mailgate_obj.msg_act_get(msg)
thread_obj = self.pool.get('email.thread')
msg_actions, body_data = thread_obj.msg_act_get(msg)
data.update({
'description': body_data,
})
@@ -93,7 +93,7 @@ class project_tasks(osv.osv):
getattr(self,act)(cr, uid, [id])
return True
def message_followers(self, cr, uid, ids, context=None):
def thread_followers(self, cr, uid, ids, context=None):
res = []
if isinstance(ids, (str, int, long)):
select = [ids]
@@ -106,11 +106,8 @@ class project_tasks(osv.osv):
return len(res) and res[0] or False
return res
def msg_send(self, cr, uid, id, *args, **argv):
return True
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None):
mailgate_pool = self.pool.get('mailgate.thread')
mailgate_pool = self.pool.get('email.thread')
return mailgate_pool.history(cr, uid, cases, keyword, history=history,\
subject=subject, email=email, \
details=details, email_from=email_from,\
+1 -1
View File
@@ -326,7 +326,7 @@ class project_scrum_meeting(osv.osv):
body += _('\n*Tasks since yesterday:\n_______________________%s\n*Task for Today:\n_______________________ %s\n\n*Blocks encountered:\n_______________________ %s') %(meeting_id.question_yesterday,meeting_id.question_today, meeting_id.question_blocks or _('No Blocks'))
body += _("\n\nThank you,\n%s") % user.name
sub_name = meeting_id.name or _('Scrum Meeting of %s') % meeting_id.date
flag = email_message_obj.email_send(cr, uid, user_email , [email], sub_name, body, model='project.scrum.meeting', reply_to=None, openobject_id=str(meeting_id.id))
flag = email_message_obj.schedule_with_attach(cr, uid, user_email , [email], sub_name, body, model='project.scrum.meeting', reply_to=None, openobject_id=str(meeting_id.id))
if not flag:
return False
return True
@@ -101,8 +101,8 @@ class project_scrum_email(osv.osv_memory):
if data.scrum_master_email == data.product_owner_email:
data.product_owner_email = False
if data.scrum_master_email:
email_message_obj.email_send(cr, uid, user_email, [data.scrum_master_email], data.subject, body, model='project.scrum.email', reply_to=user_email)
email_message_obj.schedule_with_attach(cr, uid, user_email, [data.scrum_master_email], data.subject, body, model='project.scrum.email', reply_to=user_email)
if data.product_owner_email:
email_message_obj.email_send(cr, uid, user_email, [data.product_owner_email], data.subject, body, model='project.scrum.email', reply_to=user_email)
email_message_obj.schedule_with_attach(cr, uid, user_email, [data.product_owner_email], data.subject, body, model='project.scrum.email', reply_to=user_email)
return {'type': 'ir.actions.act_window_close'}
project_scrum_email()
+1 -1
View File
@@ -462,7 +462,7 @@ class share_create(osv.osv_memory):
body += _("This additional data has been automatically added to your current access.\n")
body += _("You may use your existing login and password to view it. As a reminder, your login is %s.\n") % result_line.login
if not email_message_obj.email_send(cr, uid,
if not email_message_obj.schedule_with_attach(cr, uid,
user.user_email,
[email_to],
subject,
+2 -2
View File
@@ -429,7 +429,7 @@ class survey_question_wiz(osv.osv_memory):
if user_email and resp_email:
user_name = user_obj.browse(cr, uid, uid, context=context).name
mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " Give Response Of " + survey_data.title + " Survey.\n\n Thanks,"
email_message_obj.email_send(cr, uid, user_email, [resp_email], "Survey Answer Of " + str(user_name) , mail, model='survey.question.wiz', attach = attachments)
email_message_obj.schedule_with_attach(cr, uid, user_email, [resp_email], "Survey Answer Of " + str(user_name) , mail, model='survey.question.wiz', attach = attachments)
xml_form = etree.Element('form', {'string': _('Complete Survey Answer')})
etree.SubElement(xml_form, 'separator', {'string': 'Complete Survey', 'colspan': "4"})
@@ -448,7 +448,7 @@ class survey_question_wiz(osv.osv_memory):
@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 uid: the current user’s ID for security checks,
@param res_ids: List of survey answer IDs,
@param report_name: name of the report,
@param file_name: To give file name of the report,
@@ -152,7 +152,7 @@ class survey_send_invitation(osv.osv_memory):
mail = record['mail']%{'login':addr.email, 'passwd':user.password, \
'name' : addr.name}
if record['send_mail_existing']:
email_message_obj.email_send(cr, uid, record['mail_from'], [addr.email] , \
email_message_obj.schedule_with_attach(cr, uid, record['mail_from'], [addr.email] , \
record['mail_subject_existing'] , mail, model='survey.send.invitation')
existing+= "- %s (Login: %s, Password: %s)\n" % (user.name, addr.email, \
user.password)
@@ -163,7 +163,7 @@ class survey_send_invitation(osv.osv_memory):
mail = record['mail']%{'login': user_email.login, \
'passwd': user_email.password, 'name': addr.name}
if record['send_mail_existing']:
email_message_obj.email_send(cr, uid, record['mail_from'], [addr.email],\
email_message_obj.schedule_with_attach(cr, uid, record['mail_from'], [addr.email],\
record['mail_subject_existing'], mail, model='survey.send.invitation')
res_user+= "- %s (Login: %s, Password: %s)\n" % \
(user_email.name, user_email.login, user_email.password)
@@ -172,7 +172,7 @@ class survey_send_invitation(osv.osv_memory):
out+= addr.email + ',' + passwd + '\n'
mail= record['mail'] % {'login' : addr.email, 'passwd' : passwd, 'name' : addr.name}
if record['send_mail']:
ans = email_message_obj.email_send(cr, uid, record['mail_from'], [addr.email], \
ans = email_message_obj.schedule_with_attach(cr, uid, record['mail_from'], [addr.email], \
record['mail_subject'], mail, model='survey.send.invitation', attach = attachments)
if ans:
+8 -8
View File
@@ -24,8 +24,8 @@ import base64
import email
import tools
import binascii
class email_server_tools(osv.osv_memory):
_inherit = "email.server.tools"
class email_thread(osv.osv):
_inherit = "email.thread"
def history_message(self, cr, uid, model, res_id, message, context=None):
#@param message: string of mail which is read from EML File
attachment_pool = self.pool.get('ir.attachment')
@@ -127,7 +127,7 @@ class email_server_tools(osv.osv_memory):
msg['body'] = body
msg['attachments'] = attachments
return msg
email_server_tools()
email_thread()
class thunderbird_partner(osv.osv_memory):
_name = "thunderbird.partner"
@@ -149,8 +149,8 @@ class thunderbird_partner(osv.osv_memory):
ref_ids = str(dictcreate.get('ref_ids')).split(';')
msg = dictcreate.get('message')
mail = msg
msg = self.pool.get('email.server.tools').parse_message(msg)
server_tools_pool = self.pool.get('email.server.tools')
msg = self.pool.get('email.thread').parse_message(msg)
thread_pool = self.pool.get('email.thread')
message_id = msg.get('message-id', False)
msg_pool = self.pool.get('email.message')
msg_ids = []
@@ -191,7 +191,7 @@ class thunderbird_partner(osv.osv_memory):
res['datas'] = base64.b64encode(mail)
res['res_id'] = res_id
obj_attch.create(cr, uid, res)
server_tools_pool.history_message(cr, uid, model, res_id, msg_new)
thread_pool.history_message(cr, uid, model, res_id, msg_new)
res_ids.append(res_id)
return len(res_ids)
@@ -199,7 +199,7 @@ class thunderbird_partner(osv.osv_memory):
dictcreate = dict(vals)
model = str(dictcreate.get('model'))
message = dictcreate.get('message')
return self.pool.get('email.server.tools').process_email(cr, uid, model, message, attach=True, context=None)
return self.pool.get('email.thread').process_email(cr, uid, model, message, attach=True, context=None)
def search_message(self, cr, uid, message, context=None):
#@param message: string of mail which is read from EML File
@@ -207,7 +207,7 @@ class thunderbird_partner(osv.osv_memory):
references = []
dictcreate = dict(message)
msg = dictcreate.get('message')
msg = self.pool.get('email.server.tools').parse_message(msg)
msg = self.pool.get('email.thread').parse_message(msg)
message_id = msg.get('message-id')
refs = msg.get('references',False)
references = False