diff --git a/.travis.yml b/.travis.yml index 749ff18b..f1270a82 100644 --- a/.travis.yml +++ b/.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 diff --git a/mail_drop_target/__init__.py b/mail_drop_target/__init__.py index 24223449..be857487 100644 --- a/mail_drop_target/__init__.py +++ b/mail_drop_target/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models diff --git a/mail_drop_target/__manifest__.py b/mail_drop_target/__manifest__.py index e3650437..2548a1b9 100644 --- a/mail_drop_target/__manifest__.py +++ b/mail_drop_target/__manifest__.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Drag & drop emails to Odoo", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Discuss", diff --git a/mail_drop_target/models/__init__.py b/mail_drop_target/models/__init__.py index 1211df53..23c7dbf0 100644 --- a/mail_drop_target/models/__init__.py +++ b/mail_drop_target/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import mail_thread diff --git a/mail_drop_target/models/mail_thread.py b/mail_drop_target/models/mail_thread.py index 392c3dd4..46640d12 100644 --- a/mail_drop_target/models/mail_thread.py +++ b/mail_drop_target/models/mail_thread.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from base64 import b64decode diff --git a/mail_drop_target/readme/CONTRIBUTORS.rst b/mail_drop_target/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..3f184232 --- /dev/null +++ b/mail_drop_target/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Holger Brunn +* Enric Tobella diff --git a/mail_drop_target/readme/DESCRIPTION.rst b/mail_drop_target/readme/DESCRIPTION.rst new file mode 100644 index 00000000..dfd16753 --- /dev/null +++ b/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 `_ is installed) files. diff --git a/mail_drop_target/readme/ROADMAP.rst b/mail_drop_target/readme/ROADMAP.rst new file mode 100644 index 00000000..6e2dc085 --- /dev/null +++ b/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 diff --git a/mail_drop_target/readme/USAGE.rst b/mail_drop_target/readme/USAGE.rst new file mode 100644 index 00000000..abc1459e --- /dev/null +++ b/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 diff --git a/mail_drop_target/static/src/js/mail_drop_target.js b/mail_drop_target/static/src/js/mail_drop_target.js index 3a8626ec..a6d39e5c 100644 --- a/mail_drop_target/static/src/js/mail_drop_target.js +++ b/mail_drop_target/static/src/js/mail_drop_target.js @@ -4,11 +4,11 @@ odoo.define('mail_drop_target', function(require) { - var Chatter = require('mail.Chatter'), - web_drop_target = require('web_drop_target'), - Model = require('web.Model'); + 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) { @@ -23,32 +23,55 @@ odoo.define('mail_drop_target', function(require) } return this._super.apply(this, arguments); }, - _handle_file_drop: function(drop_file, e) { + + _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')) { + if (drop_file.name.endsWith('.msg')) { mail_processor = 'message_process_msg'; data = base64js.fromByteArray( - new Uint8Array(e.target.result) + new Uint8Array(reader.result) ); } else { mail_processor = 'message_process'; - data = String.fromCharCode.apply( - null, new Uint8Array(e.currentTarget.result) - ); + 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 new Model('mail.thread').call( - mail_processor, - [this.field_manager.dataset.model, data], - { - thread_id: this.field_manager.datarecord.id, + return this._rpc({ + model:'mail.thread', + method:mail_processor, + args: [this.record.model, data], + kwargs: { + thread_id: this.record.data.id, } - ) + }) .then(function() { - return self.field_manager.reload(); + self.trigger_up('reload',{}); }); } }); diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 9c8c9172..f3ae4360 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ server-tools +web