mirror of https://github.com/OCA/social.git
[ADD] mail_drop_target PoC
parent
64d82c98bb
commit
fe3be81a4d
|
@ -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.
|
|
@ -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
|
|
@ -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',
|
||||
],
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# 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,
|
||||
)
|
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
|
@ -0,0 +1,3 @@
|
|||
.o-mail-drag-over {
|
||||
filter: blur(2px);
|
||||
}
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
|
@ -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>
|
Loading…
Reference in New Issue