diff --git a/.travis.yml b/.travis.yml index e50cf05c..01771fdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ virtualenv: system_site_packages: true 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/README.rst b/mail_drop_target/README.rst new file mode 100644 index 00000000..c6dd98c6 --- /dev/null +++ b/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 `_ 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 +`_. 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 `_. + +Libraries +--------- + +* `msg-extractor `_ + +Contributors +------------ + +* Holger Brunn + +Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ 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. diff --git a/mail_drop_target/__init__.py b/mail_drop_target/__init__.py new file mode 100644 index 00000000..24223449 --- /dev/null +++ b/mail_drop_target/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 00000000..e3650437 --- /dev/null +++ b/mail_drop_target/__manifest__.py @@ -0,0 +1,18 @@ +# -*- 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", + "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', + ], +} diff --git a/mail_drop_target/models/__init__.py b/mail_drop_target/models/__init__.py new file mode 100644 index 00000000..1211df53 --- /dev/null +++ b/mail_drop_target/models/__init__.py @@ -0,0 +1,4 @@ +# -*- 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 new file mode 100644 index 00000000..392c3dd4 --- /dev/null +++ b/mail_drop_target/models/mail_thread.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# 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, + ) diff --git a/mail_drop_target/static/description/icon.png b/mail_drop_target/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mail_drop_target/static/description/icon.png differ diff --git a/mail_drop_target/static/src/css/mail_drop_target.css b/mail_drop_target/static/src/css/mail_drop_target.css new file mode 100644 index 00000000..1056f02e --- /dev/null +++ b/mail_drop_target/static/src/css/mail_drop_target.css @@ -0,0 +1,3 @@ +.o-mail-drag-over { + filter: blur(2px); +} diff --git a/mail_drop_target/static/src/js/mail_drop_target.js b/mail_drop_target/static/src/js/mail_drop_target.js new file mode 100644 index 00000000..3a8626ec --- /dev/null +++ b/mail_drop_target/static/src/js/mail_drop_target.js @@ -0,0 +1,55 @@ +//-*- coding: utf-8 -*- +//Copyright 2018 Therp BV +//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'), + web_drop_target = require('web_drop_target'), + Model = require('web.Model'); + + 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_file_drop: function(drop_file, e) { + var self = this, + mail_processor = '', + data = ''; + if(drop_file.name.endsWith('.msg')) { + mail_processor = 'message_process_msg'; + data = base64js.fromByteArray( + new Uint8Array(e.target.result) + ); + } else { + mail_processor = 'message_process'; + data = String.fromCharCode.apply( + null, new Uint8Array(e.currentTarget.result) + ); + } + // 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, + } + ) + .then(function() { + return self.field_manager.reload(); + }); + } + }); +}); diff --git a/mail_drop_target/views/templates.xml b/mail_drop_target/views/templates.xml new file mode 100644 index 00000000..44031fc7 --- /dev/null +++ b/mail_drop_target/views/templates.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt index a89069d5..2325ee77 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ -server-tools \ No newline at end of file +web +server-tools