Browse Source

Merge pull request #367 from yelizariev/9.0-cleanup-2

commit is created by 👷‍♂️ Merge Bot: https://odoo-devops.readthedocs.io/en/latest/git/github-merge-bot.html
9.0
Mitchell Admin 3 years ago
committed by GitHub
parent
commit
fcf58335e0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      mail_check_immediately/README.rst
  2. 2
      mail_check_immediately/__init__.py
  3. 17
      mail_check_immediately/__openerp__.py
  4. 4
      mail_check_immediately/doc/changelog.rst
  5. 66
      mail_check_immediately/models.py
  6. BIN
      mail_check_immediately/static/description/icon.png
  7. 47
      mail_check_immediately/static/description/index.html
  8. BIN
      mail_check_immediately/static/description/issue.png
  9. BIN
      mail_check_immediately/static/description/screenshot.png
  10. 55
      mail_check_immediately/static/src/js/main.js
  11. 25
      mail_check_immediately/static/src/xml/main.xml
  12. 9
      mail_check_immediately/views.xml
  13. 48
      mail_fix_553/README.rst
  14. 2
      mail_fix_553/__init__.py
  15. 12
      mail_fix_553/__openerp__.py
  16. 15
      mail_fix_553/data.xml
  17. 165
      mail_fix_553/mail_fix_553.py
  18. BIN
      mail_fix_553/static/description/icon.png

8
mail_check_immediately/README.rst

@ -1,8 +0,0 @@
.. image:: https://itpp.dev/images/infinity-readme.png
:alt: Tested and maintained by IT Projects Labs
:target: https://itpp.dev
Check mail immediately
======================
Description: https://apps.odoo.com/apps/modules/8.0/mail_check_immediately/

2
mail_check_immediately/__init__.py

@ -1,2 +0,0 @@
# -*- coding: utf-8 -*-
from . import models

17
mail_check_immediately/__openerp__.py

@ -1,17 +0,0 @@
# -*- coding: utf-8 -*-
{
'name': 'Check mail immediately',
'version': '1.0.1',
'author': 'IT-Projects LLC, Ivan Yelizariev',
'license': 'LGPL-3',
"category": "Discuss",
'website': 'https://twitter.com/yelizariev',
'depends': ['base', 'web', 'fetchmail', 'mail'],
'data': [
'views.xml',
],
'qweb': [
"static/src/xml/main.xml",
],
'installable': False
}

4
mail_check_immediately/doc/changelog.rst

@ -1,4 +0,0 @@
`1.0.1`
-------
- FIX: incorrectly displayed last updated time when multiple threads (--workers)

66
mail_check_immediately/models.py

@ -1,66 +0,0 @@
# -*- coding: utf-8 -*-
import datetime
from openerp.tools.translate import _
from openerp import tools
from openerp import exceptions
from openerp import models, fields, api
class FetchMailServer(models.Model):
_inherit = 'fetchmail.server'
_name = 'fetchmail.server'
_last_updated = None
run_time = fields.Datetime(string="Launch time")
def _run_time(self):
if not self._last_updated:
self._last_updated = tools.datetime.now()
src_tstamp_str = self._last_updated.strftime(tools.misc.DEFAULT_SERVER_DATETIME_FORMAT)
src_format = tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
dst_format = tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
dst_tz_name = self._context.get('tz') or self.env.user.tz
_now = tools.misc.server_to_local_timestamp(src_tstamp_str, src_format, dst_format, dst_tz_name)
return _now
@api.model
def _fetch_mails(self):
if self._context.get('run_fetchmail_manually'):
# if interval less than 5 seconds
if self._last_updated and (datetime.datetime.now() - self._last_updated) < datetime.timedelta(0, 5):
raise exceptions.Warning(_('Error'), _('Task can be started no earlier than 5 seconds.'))
super(FetchMailServer, self)._fetch_mails()
res = self.env['fetchmail.server'].sudo().with_context(tz=self.env.user.tz).search([('state', '=', 'done')])
if res:
res[0].run_time = self._run_time()
class FetchMailImmediately(models.AbstractModel):
_name = 'fetch_mail.imm'
@api.model
def get_last_update_time(self):
res = self.env['fetchmail.server'].sudo().with_context(tz=self.env.user.tz).search([('state', '=', 'done')])
array = [r.run_time for r in res]
if array:
return array[0]
else:
return None
@api.model
def run_fetchmail_manually(self):
fetchmail_task = self.env.ref('fetchmail.ir_cron_mail_gateway_action')
fetchmail_model = self.env['fetchmail.server'].sudo()
fetchmail_task._try_lock()
fetchmail_model.with_context(run_fetchmail_manually=True)._fetch_mails()

BIN
mail_check_immediately/static/description/icon.png

Before

Width: 100  |  Height: 100  |  Size: 2.1 KiB

47
mail_check_immediately/static/description/index.html

@ -1,47 +0,0 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Check mail immediately</h2>
<h3 class="oe_slogan">Keep your inbox up to date</h3>
</div>
<div class="oe_span12">
<div class="oe_demo oe_picture oe_screenshot">
<img src="screenshot.png?"/>
</div>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2>Protect your business</h2>
</div>
<div class="oe_span6">
<p class="oe_mt32">
<a href="https://github.com/odoo/odoo/issues/7464">Sometimes</a> odoo mail fetching system doesn't work for really long time. It could be a real problem, if you will not notice it on time. Until this issue is fixed, you can restart odoo every time when you see that last fetching time is more than 5 minutes.
</p>
</div>
<div class="oe_span6">
<div class="oe_picture">
<img src="issue.png?3"/>
</div>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2>Need our service?</h2>
<p class="oe_mt32">Contact us by <a href="mailto:it@it-projects.info">email</a> or fill out <a href="https://www.it-projects.info/page/website.contactus " target="_blank">request form</a></p>
<ul>
<li><a href="mailto:it@it-projects.info">it@it-projects.info <i class="fa fa-envelope-o"></i></a></li>
<li><a href="https://www.it-projects.info/page/website.contactus " target="_blank">
https://www.it-projects.info/page/website.contactus <i class="fa fa-list-alt"></i></a></li>
</ul>
</div>
</div>
</section>

BIN
mail_check_immediately/static/description/issue.png

Before

Width: 217  |  Height: 140  |  Size: 8.5 KiB

BIN
mail_check_immediately/static/description/screenshot.png

Before

Width: 840  |  Height: 447  |  Size: 88 KiB

55
mail_check_immediately/static/src/js/main.js

@ -1,55 +0,0 @@
openerp.mail_check_immediately = function(instance, local) {
instance.mail.Wall.include({
init: function(){
this._super.apply(this, arguments);
var _this = this;
this.imm_model = new instance.web.Model('fetch_mail.imm');
this.events['click a.oe_fetch_new_mails'] = function(){
_this.run_fetchmail_manually();
};
},
start: function() {
var _this = this;
this._super();
this.get_last_fetched_time();
this.get_time_loop = setInterval(function(){
_this.get_last_fetched_time();
}, 30000);
},
run_fetchmail_manually: function(){
var _this = this;
this.imm_model.call('run_fetchmail_manually', {context: new instance.web.CompoundContext()}).then(function(){
_this.get_last_fetched_time();
});
},
get_last_fetched_time: function(){
var _this = this;
this.imm_model.call('get_last_update_time', {context: new instance.web.CompoundContext()}).then(function(res){
var value;
if (res)
value = $.timeago(res);
value = value || 'undefined';
_this.$el.find('span.oe_view_manager_fetch_mail_imm_field').html(value);
});
},
destroy: function(){
clearInterval(this.get_time_loop);
this._super.apply(this, arguments);
}
});
};

25
mail_check_immediately/static/src/xml/main.xml

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<templates>
<t t-name="fetch_mail_immediately.header">
<tr class="oe_header_row">
<td t-att-colspan="colspan or '3'">
<div class="oe_view_manager_fetch_mail_imm">
<em>
<span>Mails fetched:</span>
<a href="#" class="oe_fetch_new_mails" title="Click to fetch mails now">
<span class="oe_view_manager_fetch_mail_imm_field"></span>
</a>
</em>
</div>
</td>
<td></td>
</tr>
</t>
<t t-extend="mail.wall">
<t t-jquery="tr.oe_header_row_top" t-operation="after">
<t t-call="fetch_mail_immediately.header">
<t t-set="colspan" t-value="2"/>
</t>
</t>
</t>
</templates>

9
mail_check_immediately/views.xml

@ -1,9 +0,0 @@
<openerp>
<data>
<template id="assets_backend_inherited_check_mail" name="Check mail immediately bar" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/mail_check_immediately/static/src/js/main.js"></script>
</xpath>
</template>
</data>
</openerp>

48
mail_fix_553/README.rst

@ -1,48 +0,0 @@
.. image:: https://itpp.dev/images/infinity-readme.png
:alt: Tested and maintained by IT Projects Labs
:target: https://itpp.dev
Fix mail error 553
==================
Module updates 'FROM' field to portal@MYDOMAIN.COM value in order to fix 553 error on a mail service that checks FROM field.
E.g:
* Customer send email from USER@CUSTOMER.com to info@MYDOMAIN.COM
* odoo accept email and try to send notifcation to related odoo users. E.g to admin@gmail.com.
* By default odoo prepare notification email with parameters as follows:
* FROM: user@CUSTOMER.com
* TO: admin@gmail.com
if you mail service provider, e.g. pdd.yandex.ru, doesn't allow emails with a FROM value differ from ...@MYDOMAIN.COM, then you get 553. This is why you need to update FROM value to portal@MYDOMAIN.COM
Configuration
=============
You can configure default alias at Settings -> System Parameters -> mail.catchall.alias_from
You can configure name for default alias at Settings -> System Parameters -> mail.catchall.name_alias_from
You can configure name for default alias at Settings -> System Parameters -> mail.catchall.name_alias_from
Known issues / Roadmap
======================
The module is consist of redefined send function from mail.mail
model. So it is just copy pasted source code with some
modification. This function is changed very rarely, but sometime it
can happens and the module should be updated. You can check commits
for mail_mail.py here:
https://github.com/odoo/odoo/commits/8.0/addons/mail/mail_mail.py
Tested on `Odoo 8.0 <https://github.com/odoo/odoo/commit/d023c079ed86468436f25da613bf486a4a17d625>`_
Status
======
Related issues at odoo's tracker:
* https://github.com/odoo/odoo/issues/5864
* https://github.com/odoo/odoo/issues/3347
Fix: https://github.com/odoo-dev/odoo/commit/a4597fe34fcfa8dae28b156410080346bb33af33

2
mail_fix_553/__init__.py

@ -1,2 +0,0 @@
# -*- coding: utf-8 -*-
from . import mail_fix_553

12
mail_fix_553/__openerp__.py

@ -1,12 +0,0 @@
# -*- coding: utf-8 -*-
{
"name": "Fix mail error 553",
"version": "0.3",
"author": "IT-Projects LLC, Ivan Yelizariev",
'license': 'LGPL-3',
"category": "Discuss",
"website": "https://yelizariev.github.io",
"depends": ["base", "mail"],
"data": ["data.xml"],
'installable': False
}

15
mail_fix_553/data.xml

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Catchall Email Alias -->
<record id="icp_mail_catchall_alias_from" model="ir.config_parameter">
<field name="key">mail.catchall.alias_from</field>
<field name="value">portal</field>
</record>
<!-- Name for Catchall Email Alias -->
<record id="icp_mail_catchall_name_alias_from" model="ir.config_parameter">
<field name="key">mail.catchall.name_alias_from</field>
<field name="value">Odoo</field>
</record>
</data>
</openerp>

165
mail_fix_553/mail_fix_553.py

@ -1,165 +0,0 @@
# -*- coding: utf-8 -*-
import base64
import logging
import re
from email.utils import formataddr
from openerp import tools
from openerp import SUPERUSER_ID
from openerp.addons.base.ir.ir_mail_server import MailDeliveryException
from openerp.osv import osv
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
class MailMail(osv.Model):
_inherit = "mail.mail"
def send(self, cr, uid, ids, auto_commit=False, raise_exception=False, context=None):
# copy-paste from addons/mail/mail_mail.py
""" Sends the selected emails immediately, ignoring their current
state (mails that have already been sent should not be passed
unless they should actually be re-sent).
Emails successfully delivered are marked as 'sent', and those
that fail to be deliver are marked as 'exception', and the
corresponding error mail is output in the server logs.
:param bool auto_commit: whether to force a commit of the mail status
after sending each mail (meant only for scheduler processing);
should never be True during normal transactions (default: False)
:param bool raise_exception: whether to raise an exception if the
email sending process has failed
:return: True
"""
# NEW STUFF
catchall_alias = self.pool['ir.config_parameter'].get_param(cr, uid, "mail.catchall.alias_from", context=context)
catchall_alias_name = self.pool['ir.config_parameter'].get_param(cr, uid, "mail.catchall.name_alias_from", context=context)
catchall_domain = self.pool['ir.config_parameter'].get_param(cr, uid, "mail.catchall.domain", context=context)
correct_email_from = r'@%s>?\s*$' % catchall_domain
default_email_from = '%s@%s' % (catchall_alias, catchall_domain)
context = dict(context or {})
ir_mail_server = self.pool.get('ir.mail_server')
ir_attachment = self.pool['ir.attachment']
for mail in self.browse(cr, SUPERUSER_ID, ids, context=context):
try:
# TDE note: remove me when model_id field is present on mail.message - done here to avoid doing it multiple times in the sub method
if mail.model:
model_id = self.pool['ir.model'].search(cr, SUPERUSER_ID, [('model', '=', mail.model)], context=context)[0]
model = self.pool['ir.model'].browse(cr, SUPERUSER_ID, model_id, context=context)
else:
model = None
if model:
context['model_name'] = model.name
# load attachment binary data with a separate read(), as prefetching all
# `datas` (binary field) could bloat the browse cache, triggerring
# soft/hard mem limits with temporary data.
attachment_ids = [a.id for a in mail.attachment_ids]
attachments = [(a['datas_fname'], base64.b64decode(a['datas']))
for a in ir_attachment.read(cr, SUPERUSER_ID, attachment_ids,
['datas_fname', 'datas'])]
# specific behavior to customize the send email for notified partners
email_list = []
if mail.email_to:
email_list.append(self.send_get_email_dict(cr, uid, mail, context=context))
for partner in mail.recipient_ids:
email_list.append(self.send_get_email_dict(cr, uid, mail, partner=partner, context=context))
# headers
headers = {}
bounce_alias = self.pool['ir.config_parameter'].get_param(cr, uid, "mail.bounce.alias", context=context)
catchall_domain = self.pool['ir.config_parameter'].get_param(cr, uid, "mail.catchall.domain", context=context)
if bounce_alias and catchall_domain:
if mail.model and mail.res_id:
headers['Return-Path'] = '%s-%d-%s-%d@%s' % (bounce_alias, mail.id, mail.model, mail.res_id, catchall_domain)
else:
headers['Return-Path'] = '%s-%d@%s' % (bounce_alias, mail.id, catchall_domain)
if mail.headers:
try:
headers.update(eval(mail.headers))
except Exception:
pass
# Writing on the mail object may fail (e.g. lock on user) which
# would trigger a rollback *after* actually sending the email.
# To avoid sending twice the same email, provoke the failure earlier
mail.write({'state': 'exception'})
mail_sent = False
# build an RFC2822 email.message.Message object and send it without queuing
res = None
for email in email_list:
# NEW STUFF
email_from = mail.email_from
if re.search(correct_email_from, email_from) is None:
email_from = default_email_from
if catchall_alias_name:
email_from = formataddr((catchall_alias_name, email_from))
msg = ir_mail_server.build_email(
email_from=email_from, # NEW STUFF
email_to=email.get('email_to'),
subject=email.get('subject'),
body=email.get('body'),
body_alternative=email.get('body_alternative'),
email_cc=tools.email_split(mail.email_cc),
reply_to=mail.reply_to,
attachments=attachments,
message_id=mail.message_id,
references=mail.references,
object_id=mail.res_id and ('%s-%s' % (mail.res_id, mail.model)),
subtype='html',
subtype_alternative='plain',
headers=headers)
try:
res = ir_mail_server.send_email(cr, uid, msg,
mail_server_id=mail.mail_server_id.id,
context=context)
except AssertionError as error:
if error.message == ir_mail_server.NO_VALID_RECIPIENT:
# No valid recipient found for this particular
# mail item -> ignore error to avoid blocking
# delivery to next recipients, if any. If this is
# the only recipient, the mail will show as failed.
_logger.warning("Ignoring invalid recipients for mail.mail %s: %s",
mail.message_id, email.get('email_to'))
else:
raise
if res:
mail.write({'state': 'sent', 'message_id': res})
mail_sent = True
# /!\ can't use mail.state here, as mail.refresh() will cause an error
# see revid:odo@openerp.com-20120622152536-42b2s28lvdv3odyr in 6.1
if mail_sent:
_logger.info('Mail with ID %r and Message-Id %r successfully sent', mail.id, mail.message_id)
self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=mail_sent)
except MemoryError:
# prevent catching transient MemoryErrors, bubble up to notify user or abort cron job
# instead of marking the mail as failed
_logger.exception('MemoryError while processing mail with ID %r and Msg-Id %r. '
'Consider raising the --limit-memory-hard startup option',
mail.id, mail.message_id)
raise
except Exception as e:
_logger.exception('failed sending mail.mail %s', mail.id)
mail.write({'state': 'exception'})
self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=False)
if raise_exception:
if isinstance(e, AssertionError):
# get the args of the original error, wrap into a value and throw a MailDeliveryException
# that is an except_orm, with name and value as arguments
value = '. '.join(e.args)
raise MailDeliveryException(_("Mail Delivery Failed"), value)
raise
if auto_commit is True:
cr.commit()
return True

BIN
mail_fix_553/static/description/icon.png

Before

Width: 100  |  Height: 100  |  Size: 2.1 KiB

Loading…
Cancel
Save