mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-24 14:57:26 +08:00
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:
parent
ee03abfd09
commit
1625e722a2
2 changed files with 62 additions and 31 deletions
|
@ -4,8 +4,8 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
{
|
||||
const
|
||||
NAME = 'Nextcloud',
|
||||
VERSION = '2.1',
|
||||
RELEASE = '2022-10-10',
|
||||
VERSION = '2.2',
|
||||
RELEASE = '2022-10-13',
|
||||
CATEGORY = 'Integrations',
|
||||
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
||||
REQUIRED = '2.18.6';
|
||||
|
@ -18,8 +18,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addHook('main.fabrica', 'MainFabrica');
|
||||
$this->addHook('filter.app-data', 'FilterAppData');
|
||||
|
||||
$this->addJs('js/message.js');
|
||||
$this->addHook('json.attachments', 'DoAttachmentsActions');
|
||||
$this->addJs('js/attachments.js');
|
||||
$this->addJsonHook('NextcloudSaveMsg', 'NextcloudSaveMsg');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,6 +56,39 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
*/
|
||||
|
||||
public function NextcloudSaveMsg() : array
|
||||
{
|
||||
$aValues = \RainLoop\Utils::DecodeKeyValuesQ($this->jsonParam('msgHash', ''));
|
||||
if (!empty($aValues['Folder']) && !empty($aValues['Uid'])) {
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
$oMailClient = $oActions->MailClient();
|
||||
if (!$oMailClient->IsLoggined()) {
|
||||
$oAccount = $oActions->getAccountFromToken();
|
||||
$oAccount->ImapConnectAndLoginHelper($oActions->Plugins(), $oMailClient, $oActions->Config());
|
||||
}
|
||||
|
||||
$sSaveFolder = $this->Config()->Get('plugin', 'save_folder', '') ?: 'Emails';
|
||||
$oFiles = \OCP\Files::getStorage('files');
|
||||
if ($oFiles && \method_exists($oFiles, 'file_put_contents')) {
|
||||
$oFiles->is_dir($sSaveFolder) || $oFiles->mkdir($sSaveFolder);
|
||||
}
|
||||
$sFilename = $sSaveFolder . '/' . ($this->jsonParam('filename', '') ?: \date('YmdHis')) . '.eml';
|
||||
|
||||
$oMailClient->MessageMimeStream(
|
||||
function ($rResource) use ($oFiles, $sFilename) {
|
||||
if (\is_resource($rResource)) {
|
||||
$oFiles->file_put_contents($sFilename, $rResource);
|
||||
}
|
||||
},
|
||||
(string) $aValues['Folder'],
|
||||
(int) $aValues['Uid'],
|
||||
isset($aValues['MimeIndex']) ? (string) $aValues['MimeIndex'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
return $this->jsonResponse(__FUNCTION__, true);
|
||||
}
|
||||
|
||||
public function DoAttachmentsActions(\SnappyMail\AttachmentsAction $data)
|
||||
{
|
||||
if (static::isLoggedIn() && 'nextcloud' === $data->action) {
|
||||
|
|
|
@ -30,45 +30,42 @@
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
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">Save Nextcloud</span>'
|
||||
+ '<span class="g-ui-link" data-bind="click: saveNextcloud" data-i18n="NEXTCLOUD/SAVE_ATTACHMENTS"></span>'
|
||||
+ '</span>'));
|
||||
}
|
||||
|
||||
|
||||
/** TODO: File browser to attach files in composer */
|
||||
/*
|
||||
let cfg = rl.settings.get('Nextcloud');
|
||||
fetch(cfg.WebDAV . '/files/' . cfg.UID, {
|
||||
method: 'PROPFIND',
|
||||
mode: 'same-origin',
|
||||
cache: 'no-cache',
|
||||
redirect: 'error',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
},
|
||||
body: '<?xml version="1.0"?>'
|
||||
+ '<d:propfind xmlns:d="DAV:">'
|
||||
+ '<d:prop><d:resourcetype/></d:prop>'
|
||||
+ '</d:propfind>'
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(text => {
|
||||
console.dir({response:text});
|
||||
parser = new DOMParser();
|
||||
xmlDoc = parser.parseFromString(text, "text/xml");
|
||||
})
|
||||
.catch(error => console.error(error));
|
||||
*/
|
||||
|
||||
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);
|
Loading…
Reference in a new issue