Browse Source

[ADD] mail_drop_target PoC

pull/242/head
Holger Brunn 7 years ago
parent
commit
67e61ff29b
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 1
      .travis.yml
  2. 72
      mail_drop_target/README.rst
  3. 4
      mail_drop_target/__init__.py
  4. 18
      mail_drop_target/__manifest__.py
  5. 4
      mail_drop_target/models/__init__.py
  6. 40
      mail_drop_target/models/mail_thread.py
  7. BIN
      mail_drop_target/static/description/icon.png
  8. 3
      mail_drop_target/static/src/css/mail_drop_target.css
  9. 55
      mail_drop_target/static/src/js/mail_drop_target.js
  10. 11
      mail_drop_target/views/templates.xml
  11. 1
      oca_dependencies.txt

1
.travis.yml

@ -28,6 +28,7 @@ virtualenv:
system_site_packages: true system_site_packages: true
install: 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 - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly - 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.

4
mail_drop_target/__init__.py

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

18
mail_drop_target/__manifest__.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# 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": "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',
],
}

4
mail_drop_target/models/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# 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 @@
# -*- coding: utf-8 -*-
# © 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from StringIO import StringIO
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(StringIO(b64decode(message)))
message_email = self.env['ir.mail_server'].build_email(
message_msg.sender, message_msg.to.split(','), message_msg.subject,
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,
)

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);
}

55
mail_drop_target/static/src/js/mail_drop_target.js

@ -0,0 +1,55 @@
//-*- 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'),
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();
});
}
});
});

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 @@
web
server-tools server-tools
Loading…
Cancel
Save