Added option to save email in Nextcloud for #96 and @Mer0me

https://help.nextcloud.com/t/best-way-to-archive-mails-into-nextcloud-folders/144252
This commit is contained in:
the-djmaze 2022-10-13 14:07:04 +02:00
parent ee03abfd09
commit 1625e722a2
2 changed files with 62 additions and 31 deletions

View file

@ -0,0 +1,71 @@
(rl => {
addEventListener('rl-view-model.create', e => {
if ('MailMessageView' === e.detail.viewModelTemplateID) {
let view = e.detail;
view.saveNextcloudError = ko.observable(false).extend({ falseTimeout: 7000 });
view.saveNextcloudLoading = ko.observable(false);
view.saveNextcloud = () => {
const
hashes = (view.message()?.attachments || [])
.map(item => item?.checked() /*&& !item?.isLinked()*/ ? item.download : '')
.filter(v => v);
if (hashes.length) {
view.saveNextcloudLoading(true);
rl.fetchJSON('./?/Json/&q[]=/0/', {}, {
Action: 'AttachmentsActions',
Do: 'nextcloud',
Hashes: hashes
})
.then(result => {
view.saveNextcloudLoading(false);
if (result?.Result) {
// success
} else {
view.saveNextcloudError(true);
}
})
.catch(() => {
view.saveNextcloudLoading(false);
view.saveNextcloudError(true);
});
}
};
view.nextcloudSaveMsg = () => {
let msg = view.message();
rl.pluginRemoteRequest(
(iError, data) => {
console.dir({
iError:iError,
data:data
});
},
'NextcloudSaveMsg',
{
'msgHash': msg.requestHash,
'filename': msg.subject()
}
);
};
}
});
let template = document.getElementById('MailMessageView');
const attachmentsControls = template.content.querySelector('.attachmentsControls');
if (attachmentsControls) {
attachmentsControls.append(Element.fromHTML('<span>'
+ '<i class="fontastic iconcolor-red" data-bind="visible: saveNextcloudError">✖</i>'
+ '<i class="fontastic" data-bind="visible: !saveNextcloudError(), css: {\'icon-spinner\': saveNextcloudLoading()}">💾</i>'
+ '<span class="g-ui-link" data-bind="click: saveNextcloud" data-i18n="NEXTCLOUD/SAVE_ATTACHMENTS"></span>'
+ '</span>'));
}
const msgMenu = template.content.querySelector('#more-view-dropdown-id + menu');
if (msgMenu) {
msgMenu.append(Element.fromHTML('<li role="presentation">'
+ '<a href="#" tabindex="-1" data-icon="📥" data-bind="click: nextcloudSaveMsg" data-i18n="NEXTCLOUD/SAVE_EML"></a>'
+ '</li>'));
}
})(window.rl);