Download an email

An option is available in the reply drop-down called "Download Email", clicking this will prompt the user for the output directory
This commit is contained in:
Glenn 2022-08-23 16:51:21 +01:00
parent 1ce06f18ba
commit aba6709e30
4 changed files with 43 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -11,6 +11,8 @@ import {
Message,
} from 'mailspring-exports';
import { RetinaImg, ButtonDropdown, Menu } from 'mailspring-component-kit';
import { ipcRenderer, SaveDialogReturnValue } from 'electron';
import { dialog } from '@electron/remote';
interface MessageControlsProps {
thread: Thread;
@ -47,13 +49,24 @@ export default class MessageControls extends React.Component<MessageControlsProp
select: this._onShowOriginal,
};
const downloadEmail = {
name: localized('Download email'),
image: 'ic-dropdown-whitespace.png',
// TODO: Image isn't working - in this folders assets folder though
// image: 'mail-download-icon@2x.png',
select: this._onDownloadEmail,
};
if (!this.props.message.canReplyAll()) {
return [reply, forward, showOriginal];
return [reply, forward, showOriginal, downloadEmail];
}
const defaultReplyType = AppEnv.config.get('core.sending.defaultReplyType');
return defaultReplyType === 'reply-all'
? [replyAll, reply, forward, showOriginal]
: [reply, replyAll, forward, showOriginal];
return (defaultReplyType === 'reply-all' ? [replyAll, reply] : [reply, replyAll]).concat(
forward,
showOriginal,
downloadEmail
);
}
_dropdownMenu(items) {
@ -121,7 +134,10 @@ export default class MessageControls extends React.Component<MessageControlsProp
_onShowOriginal = async () => {
const { message } = this.props;
const filepath = require('path').join(require('@electron/remote').app.getPath('temp'), message.id);
const filepath = require('path').join(
require('@electron/remote').app.getPath('temp'),
message.id
);
const task = new GetMessageRFC2822Task({
messageId: message.id,
accountId: message.accountId,
@ -142,6 +158,27 @@ export default class MessageControls extends React.Component<MessageControlsProp
win.loadURL(`file://${filepath}`);
};
_onDownloadEmail = async () => {
const { message } = this.props;
const filepath = await dialog.showSaveDialog({
filters: [{ name: 'Email', extensions: ['.eml'] }],
defaultPath: `${message.subject} - ${new Date().toLocaleDateString(
'sv-SE'
)} - ${message.id.substring(0, 10)}.eml`,
});
if (!filepath.canceled && filepath.filePath) {
Actions.queueTask(
new GetMessageRFC2822Task({
messageId: message.id,
accountId: message.accountId,
filepath: filepath.filePath,
})
);
}
};
_onLogData = () => {
console.log(this.props.message);
(window as any).__message = this.props.message;

View file

@ -187,6 +187,7 @@
"Do you prefer a single panel layout (like Gmail) or a two panel layout?": "Do you prefer a single panel layout (like Gmail) or a two panel layout?",
"Dont show this again": "Dont show this again",
"Download All": "Download All",
"Download Email": "Download Email",
"Download Failed": "Download Failed",
"Download Now": "Download Now",
"Downloading Update": "Downloading Update",