Browse Source

Merge dafc09dc86 into 5ff085d627

pull/403/merge
Enric Tobella 5 years ago
committed by GitHub
parent
commit
e859a60f56
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .travis.yml
  2. 72
      mail_drop_target/README.rst
  3. 3
      mail_drop_target/__init__.py
  4. 17
      mail_drop_target/__manifest__.py
  5. 3
      mail_drop_target/models/__init__.py
  6. 40
      mail_drop_target/models/mail_thread.py
  7. 2
      mail_drop_target/readme/CONTRIBUTORS.rst
  8. 3
      mail_drop_target/readme/DESCRIPTION.rst
  9. 2
      mail_drop_target/readme/ROADMAP.rst
  10. 8
      mail_drop_target/readme/USAGE.rst
  11. BIN
      mail_drop_target/static/description/icon.png
  12. 3
      mail_drop_target/static/src/css/mail_drop_target.css
  13. 78
      mail_drop_target/static/src/js/mail_drop_target.js
  14. 11
      mail_drop_target/views/templates.xml
  15. 1
      oca_dependencies.txt

1
.travis.yml

@ -27,6 +27,7 @@ env:
install:
- pip install https://github.com/mattgwwalker/msg-extractor/tarball/master
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly

72
mail_drop_target/README.rst

@ -0,0 +1,72 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==========================
Drag & drop emails to Odoo
==========================
This module was written to allow users to drag&drop emails from their desktop to Odoo.
It supports as well RFC822 .eml files as Outlook .msg (those only if `an extra library <https://github.com/mattgwwalker/msg-extractor>`_ is installed) files.
Usage
=====
To use this module, you need to:
#. save your emails on the desktop / somewhere in the file system
#. drag them to your browser, and drop them on the chatter of the record you want to attach your email to
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0
Known issues / Roadmap
======================
* most mail clients won't allow you to drag mails directly from the mail client, you'll need some plugin for that
* for corporate environments, it might be feasible to support imap URLs and get the mail in question on the server side
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Libraries
---------
* `msg-extractor <https://github.com/mattgwwalker/msg-extractor>`_
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

3
mail_drop_target/__init__.py

@ -0,0 +1,3 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models

17
mail_drop_target/__manifest__.py

@ -0,0 +1,17 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Drag & drop emails to Odoo",
"version": "11.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Discuss",
"summary": "Attach emails to Odoo by dragging them from your desktop",
"depends": [
'mail',
'web_drop_target',
],
"data": [
'views/templates.xml',
],
}

3
mail_drop_target/models/__init__.py

@ -0,0 +1,3 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import mail_thread

40
mail_drop_target/models/mail_thread.py

@ -0,0 +1,40 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from base64 import b64decode
try:
from ExtractMsg import Message
except ImportError:
Message = None
from odoo import _, api, exceptions, models
class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
@api.model
def message_process_msg(
self, model, message, custom_values=None, save_original=False,
strip_attachments=False, thread_id=None,
):
"""Convert message to RFC2822 and pass to message_process"""
if not Message:
raise exceptions.UserError(
_('Install the msg-extractor library to handle .msg files')
)
message_msg = Message(b64decode(message))
message_email = self.env['ir.mail_server'].build_email(
message_msg.sender, message_msg.to.split(','), message_msg.subject,
# prefer html bodies to text
message_msg._getStream('__substg1.0_10130102') or message_msg.body,
email_cc=message_msg.cc,
headers={'date': message_msg.date},
attachments=[
(attachment.longFilename, attachment.data)
for attachment in message_msg.attachments
],
)
return self.message_process(
model, message_email.as_string(), custom_values=custom_values,
save_original=save_original, strip_attachments=strip_attachments,
thread_id=thread_id,
)

2
mail_drop_target/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
* Holger Brunn <hbrunn@therp.nl>
* Enric Tobella <etobella@creublanca.es>

3
mail_drop_target/readme/DESCRIPTION.rst

@ -0,0 +1,3 @@
This module was written to allow users to drag&drop emails from their desktop to Odoo.
It supports as well RFC822 .eml files as Outlook .msg (those only if `an extra library <https://github.com/mattgwwalker/msg-extractor>`_ is installed) files.

2
mail_drop_target/readme/ROADMAP.rst

@ -0,0 +1,2 @@
* most mail clients won't allow you to drag mails directly from the mail client, you'll need some plugin for that
* for corporate environments, it might be feasible to support imap URLs and get the mail in question on the server side

8
mail_drop_target/readme/USAGE.rst

@ -0,0 +1,8 @@
To use this module, you need to:
#. save your emails on the desktop / somewhere in the file system
#. drag them to your browser, and drop them on the chatter of the record you want to attach your email to
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/10.0

BIN
mail_drop_target/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

3
mail_drop_target/static/src/css/mail_drop_target.css

@ -0,0 +1,3 @@
.o-mail-drag-over {
filter: blur(2px);
}

78
mail_drop_target/static/src/js/mail_drop_target.js

@ -0,0 +1,78 @@
//-*- coding: utf-8 -*-
//Copyright 2018 Therp BV <https://therp.nl>
//License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
odoo.define('mail_drop_target', function(require)
{
var Chatter = require('mail.Chatter');
var web_drop_target = require('web_drop_target');
Chatter.include(web_drop_target.DropTargetMixin);
Chatter.include({
_drop_allowed_types: ['message/rfc822'],
_get_drop_item: function(e) {
var dataTransfer = e.originalEvent.dataTransfer;
if(
dataTransfer.items.length == 1 &&
dataTransfer.items[0].type == '' &&
dataTransfer.items[0].kind == 'file'
) {
// this might be an outlook msg file
return dataTransfer.items[0];
}
return this._super.apply(this, arguments);
},
_handle_drop_items: function(drop_items, e) {
var self = this;
_.each(drop_items, function(item, e) {
return self._handle_file_drop_proxy(item, e);
});
},
_handle_file_drop_proxy: function(item, e) {
var self = this;
var file = item;
if(!file || !(file instanceof Blob)) {
return;
}
var reader = new FileReader();
reader.onloadend = self.proxy(
_.partial(self._handle_file_drop, file, reader, e)
);
reader.onerror = self.proxy('_file_reader_error_handler');
reader.readAsArrayBuffer(file);
},
_handle_file_drop: function(drop_file, reader, e) {
var self = this,
mail_processor = '',
data = '';
if (drop_file.name.endsWith('.msg')) {
mail_processor = 'message_process_msg';
data = base64js.fromByteArray(
new Uint8Array(reader.result)
);
} else {
mail_processor = 'message_process';
var reader_array = new Uint8Array(reader.result);
data = ""
for (var i = 0; i < reader_array.length; i++) {
data += String.fromCharCode(parseInt(reader_array[i]));
}
}
// TODO: read some config parameter if this should set
// some of the context keys to suppress mail.thread's behavior
return this._rpc({
model:'mail.thread',
method:mail_processor,
args: [this.record.model, data],
kwargs: {
thread_id: this.record.data.id,
}
})
.then(function() {
self.trigger_up('reload',{});
});
}
});
});

11
mail_drop_target/views/templates.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend" name="mail_drop_target assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/mail_drop_target/static/src/js/mail_drop_target.js"></script>
<link rel="stylesheet" href="/mail_drop_target/static/src/css/mail_drop_target.css"/>
</xpath>
</template>
</data>
</openerp>

1
oca_dependencies.txt

@ -1 +1,2 @@
server-tools
web https://github.com/tegin/web 11.0-web_drop_target_add_multi_upload
Loading…
Cancel
Save