QOwnNotes/docs/scripting/examples/note-text-from-5pm-mail.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.5 KiB
QML
Raw Permalink Normal View History

import QtQml 2.0
/**
* This script parses the text that was copied from a task email of the webservice 5pm
2016-05-12 19:13:02 +02:00
* and creates a note text with a headline, the link to the task and the description
*/
QtObject {
/**
2016-05-12 19:13:02 +02:00
* This function is called when html or a media file is pasted to a note with `Ctrl + Shift + V`
*
* @param text text of the QMimeData object
* @param html html of the QMimeData object
* @returns the string that should be inserted instead of the text from the QMimeData object
*/
function insertingFromMimeDataHook(text, html) {
2016-06-07 07:08:47 +02:00
// script.log(text);
// script.log(html);
2016-05-12 19:47:05 +02:00
// http://www.regexpal.com is your friend
2016-05-13 07:47:49 +02:00
var re1 = /^Neue Aufgabe von [\w\s]+$\s\s^(.+)$/igm;
var result1 = re1.exec(text);
2016-06-07 07:08:47 +02:00
if (result1 === null) {
2016-06-07 07:21:40 +02:00
re1 = /^Nachricht aktualisiert von [\w\s]+$\s\s^Aufgabe: (.+)$/igm;
2016-06-07 07:08:47 +02:00
result1 = re1.exec(text);
}
if (result1 === null) {
2016-06-07 07:21:40 +02:00
re1 = /^Neue Nachricht erstellt von [\w\s]+$\s\s^Aufgabe: (.+)$/igm;
2016-06-07 07:08:47 +02:00
result1 = re1.exec(text);
}
var re2 = /^Direkter Zugriff hier: (http.+\d+)$/igm;
var result2 = re2.exec(text);
2016-05-12 19:13:02 +02:00
2016-05-12 19:34:51 +02:00
var re3 = /^Projekt: .+\nBeschreibung: ((.|\n)+)^Priorität: /igm;
2016-05-12 19:13:02 +02:00
var result3 = re3.exec(text);
2016-06-07 07:08:47 +02:00
if (result3 === null) {
re3 = /^Projekt: .+\n((.|\n)+)^Direkter Zugriff hier: /igm;
result3 = re3.exec(text);
}
// script.log(result1);
// script.log(result2);
// script.log(result3);
// return an empty string if we didn't find anything
if ((result1 === null) || (result2 === null)) {
2016-06-07 07:08:47 +02:00
script.log("no 5pm task was found");
return "";
}
2016-05-13 07:41:41 +02:00
var url = result2[1];
2016-05-13 07:41:41 +02:00
var re4 = /(\d+)$/igm;
var result4 = re4.exec(url);
var id = result4[1];
var headline = result1[1] + " (" + id + ")";
2016-05-12 19:13:02 +02:00
// add the headline of the task
var text = headline + "\n";
// add "=" characters so that the headline is really a headline
for (var i = 0; i < headline.length; i++) {
text += "=";
}
2016-05-12 19:13:02 +02:00
// add the url to the task
text += "\n\n- <" + url + ">";
2016-05-12 19:13:02 +02:00
// add the description of the task
if (result3 !== null) {
var description = result3[1];
text += "\n\n" + description
}
// return the text that should be pasted
return text;
}
}