Bug 361083 - Creating custom actions for mail messages in KMail interface
Summary: Creating custom actions for mail messages in KMail interface
Status: RESOLVED FIXED
Alias: None
Product: kmail2
Classification: Applications
Component: commands and actions (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-28 10:08 UTC by Murz
Modified: 2016-05-11 05:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.3


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Murz 2016-03-28 10:08:36 UTC
Very often users need to do same actions on mail messages, and will be good to have ability for automate those actions.
For example: 
- Create todo or event in external system (not KDE)
- Create ticket in CRM with mail message body and title
- Execute script that parse message body and do some actions
- etc

So will be good to have custom items in right-click menu on message in message list, in which we can write custom script, use tokens with message id, body, text, etc.

Reproducible: Always
Comment 1 Laurent Montel 2016-03-28 11:35:45 UTC
We have plugin support for interface in 5.2 now (new features).
I can improve it to add support for external script.

Now we need to define how to specify that we need body, title etc.

So perhaps plugin provide script name and we can use %t for title (=> I replace %t by title mail) %b (body) etc.
What do you think about it ?
Comment 2 Laurent Montel 2016-03-28 12:04:15 UTC
Git commit db7b7417f3cec5acec2f31d8cc7721437344792f by Montel Laurent.
Committed on 28/03/2016 at 12:00.
Pushed by mlaurent into branch 'master'.

Improve api to support future script support

M  +1    -1    CMakeLists.txt
M  +2    -2    messageviewer/src/viewerplugins/viewerplugininterface.cpp
M  +1    -1    messageviewer/src/viewerplugins/viewerplugininterface.h
M  +2    -2    messageviewer/src/viewerplugins/viewerplugintoolmanager.cpp

http://commits.kde.org/messagelib/db7b7417f3cec5acec2f31d8cc7721437344792f
Comment 3 Murz 2016-03-28 13:56:43 UTC
Thanks for quick reply! About replacements - maybe will be better to reuse replacement tokens from Template editor (and maybe part of program code) in Message Composer?
%FULLSUBJECT
%FROMADDR
%FROMNAME
%TEXT
etc.
Comment 4 Murz 2016-03-28 14:10:45 UTC
Also Tempalte editor already have "Process with External Programs" functional, maybe you can reuse it too.
Comment 5 Laurent Montel 2016-03-28 20:17:49 UTC
When we have a script we need to parse argument
so "script.sh -b<body> -t<title>" etc.
We can't use directly %TEXT etc as we can't parse it.
Comment 6 Murz 2016-03-29 05:38:18 UTC
If you send params via command line - yes, better use like %t, but very often message body contains multiple line and long text, so pipe this via external program ("Process with External Programs" like in templates) will be better way, because we can setup custom template and parse it in program side, for example:
Command line: script.sh
Input template:
---
MESSAGE_TITLE: %FULLSUBJECT
MESSAGE_TEXT: %TEXT
CLIENT_NAME: %FROMNAME
---
What do you think about this?
Comment 7 Laurent Montel 2016-03-29 06:24:00 UTC
How you can create "Create ticket in CRM with mail message body and title" ? if you don't have arguments ?
Comment 8 Murz 2016-03-29 06:36:49 UTC
I plan to create custom cli script like crm_create_ticket.php with something:
<?php
  $input = file_get_contents("php://stdin");
  preg_match('/^CLIENT_NAME: (.*)$/', $input, $matches);
  $client_name=$matches[1];
  preg_match('/^MESSAGE_TITLE: (.*)$/', $input, $matches);
  $post['ticket_title']=$matches[1];
  preg_match('/^MESSAGE_TEXT: (.*)$\nCLIENT_NAME/', $input, $matches);
  $post['ticket_body']="Client name: $client_name \n Query: \n $matches[1];

    curl_setopt($curl, CURLOPT_URL, 'http://mycrm.com/create_ticket.php');
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
    $out = curl_exec($curl);
    echo $out;
    curl_close($curl);
?>
Or maybe bash equivalent of this process. 
So if KMail provide way to exec scripts and send message values to stdin of script, there will be wide way for customisation and automation of mail processing.
Comment 9 Murz 2016-03-29 06:51:01 UTC
I look at the KMail and seems that we already can do this via Filters functional!

In filters interface there are available Filter Actions "Pipe Throuth" and "Execute command" options.

I place myscript.sh in "Execute command" - it gets all message source to stdin!

Problem is only with parsing message subject and text, because they are BASE64 encoded, because we have raw message source text, not parsed via kmail.
Comment 10 Murz 2016-03-29 06:52:56 UTC
And we can add created filters to right-click menu of message, buttons on toolbar. So seems this feature request is already available, but will be good to improve it via templates, that will sent to stdin of "Execute command" options.
Comment 11 Laurent Montel 2016-03-29 06:54:07 UTC
(In reply to Murz from comment #9)
> I look at the KMail and seems that we already can do this via Filters
> functional!
> 
> In filters interface there are available Filter Actions "Pipe Throuth" and
> "Execute command" options.
> 
> I place myscript.sh in "Execute command" - it gets all message source to
> stdin!
> 
> Problem is only with parsing message subject and text, because they are
> BASE64 encoded, because we have raw message source text, not parsed via
> kmail.

yep filter allows it indeed.
Comment 12 Laurent Montel 2016-03-29 06:54:37 UTC
(In reply to Murz from comment #10)
> And we can add created filters to right-click menu of message, buttons on
> toolbar. So seems this feature request is already available, but will be
> good to improve it via templates, that will sent to stdin of "Execute
> command" options.

so it's another bug report it.
Comment 13 Laurent Montel 2016-03-29 07:08:10 UTC
But this feature is still useful as we can send some specific info from email to a external script.