Functional Overview
This Button attaches the selected items to a new Thunderbird mail. Either directly as single files or together in one zip file.
- If nothing is selected the button is disabled.
- When no modifier key is pressed the selected files are attached directly to a new email.
- If also folders are selected a dialog box will inform the user that folders will be ignored. The user can proceed ("OK") or abort ("Cancel") the script.
- If only folders were selected a dialog box will inform the user that folders cannot be attached to a mail and the script will end.
- When the "shift" key is pressed while clicking on the button the selected files and folders are archived to a zip-file which is attached to a new mail. A dialog box will be displayed where the user can define the name or abort the script.
- The zip file is created in a temporary folder in the windows-temp folder. This temporary folder is deleted automatically later by Opus (function "GetTempDirPath").
- When the "ctrl" key is pressed while clicking on the button the selected files and folders are archived to a zip-file which is copied to the clipboard. A dialog box will be displayed where the user can define the name or abort the script.
- The zip file is created in a temporary folder in the windows-temp folder. This temporary folder is deleted automatically later by Opus (function "GetTempDirPath").
- If you install the Thunderbird Add-on mentioned in the chapter "How to install" you can add this zip file (and/ or other single files) to an already opened "new mail"-window.
Included language overlays
- English
- German
How to Install
-
Simply drag and drop the dcf file onto an appropriate toolbar. See also How to use buttons and scripts from this forum
-
To be able to attach the zip-file created with the modifier "ctrl" you need the Thunderbird add-on "Attach from clipboard" / "Anhang aus Zwischenablage".
How to Use
- If you want to add files directly to a new mail:
- Select the desired files and click on the button. A new thunderbid mail will be opened with the selected files attached.
- If you want to add files and/or folders as zip-file to a new mail:
- Select the desired files (and folders) and press the "shift"-key while clicking on the button. A new thunderbid mail will be opened with the zip file attached.
- If you want to add some files and/or folders as zip-file to an already existing "new mail"-window:
- Select the desired files (and folders) and press the "ctrl"-key while clicking on the button.
- Switch to the existing "new mail"-windows and press "ctrl+alt+v". The new zip file is now attached to the mail.
- If you want to add a single file directly to an already existing "new mail"-window:
- Select the desired file and press "ctrl+c". Do not use the "Attach to Mail"-button.
- Switch to the existing "new mail"-windows and press "ctrl+alt+v". The copied file is now attached to the mail.
- It is a limitation of the Windows OS that you can only attach one file at once with this method.
Credits
Thanks to @Leo and @lxp for their help for some parts of the code. Also thanks to the community for other code snippets shared in this forum which helped me. ![]()
Further Development
Please share any problems or ideas that could improve this Button.
Button code
Script:
@disablenosel
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
var Dlg = DOpus.Dlg;
var fsu = DOpus.FSUtil;
var lang = DOpus.language;
cmd.deselect = false;
DOpus.ClearOutput();
DOpus.Output("ATTACH TO MAIL STARTS");
if (clickData.func.qualifiers === "none") {
if (tab.selected_files.count > 0 && tab.selected_dirs.count === 0) {
DOpus.Output("Only files have been selected and are now attached to a new mail");
cmd.ClearFiles();
cmd.AddFiles(tab.selected_files)
cmd.RunCommand('thunderbird -compose "attachment=\'{allfilepath|sep=,}\'"');
} else if (tab.selected_files.count > 0 && tab.selected_dirs.count > 0) {
DOpus.Output("Also folders have been selected, but only the selected files are now attached to a new mail");
Dlg.window = tab;
Dlg.icon = "warning";
Dlg.top = true;
Dlg.title = DOpus.Strings.Get("titleWarn");
Dlg.message = DOpus.Strings.Get("warningFolder1");
if (lang === "English") {
Dlg.buttons = "OK|Cancel";
} else if (lang === "Deutsch") {
Dlg.buttons = "OK|Abbrechen";
}
var retVal = Dlg.Show;
if (retVal === 0) {
DOpus.Output("Pressed button: Cancel");
DOpus.Output("ATTACH TO MAIL ENDS");
return;
} else if (retVal === 1) {
cmd.ClearFiles();
cmd.AddFiles(tab.selected_files)
cmd.RunCommand('thunderbird -compose "attachment=\'{allfilepath|sep=,}\'"');
}
} else {
DOpus.Output("Only folders have been selected. The script will terminate.");
Dlg.window = tab;
Dlg.icon = "warning";
Dlg.top = true;
Dlg.title = DOpus.Strings.Get("titleWarn");
Dlg.message = DOpus.Strings.Get("warningFolder2");
Dlg.buttons = "OK";
Dlg.Show;
}
} else if (clickData.func.qualifiers === "shift" || clickData.func.qualifiers === "ctrl") {
DOpus.Output("All selected files and folders are now archived to a zip file");
Dlg.window = tab;
Dlg.icon = "question";
Dlg.top = true;
Dlg.title = DOpus.Strings.Get("title");
Dlg.message = DOpus.Strings.Get("question");
Dlg.max = 50;
if (lang === "English") {
Dlg.buttons = "OK|Cancel";
} else if (lang === "Deutsch") {
Dlg.buttons = "OK|Abbrechen";
}
var retVal = Dlg.Show;
var arcname = Dlg.input;
if (retVal === 0) {
DOpus.Output("Pressed button: Cancel");
DOpus.Output("ATTACH TO MAIL ENDS");
return;
} else if (retVal === 1 && clickData.func.qualifiers === "shift") {
DOpus.Output("Pressed button: OK / Name of archive: " + arcname);
var tmpPath = fsu.GetTempDirPath(1);
cmd.RunCommand('Copy ARCHIVE="' + tab.selected + '" TO="' + tmpPath + '" CREATEFOLDER="' + arcname + '"');
DOpus.Output("Temppath: " + tmpPath);
cmd.RunCommand('thunderbird -compose "attachment=' + tmpPath + '\\' + arcname + '.zip"');
} else if (retVal === 1 && clickData.func.qualifiers === "ctrl") {
DOpus.Output("pressed button: OK / Name of archive: " + arcname);
var tmpPath = fsu.GetTempDirPath(1);
cmd.RunCommand('Copy ARCHIVE="' + tab.selected + '" TO="' + tmpPath + '" CREATEFOLDER="' + arcname + '"');
DOpus.Output("Temppath: " + tmpPath);
cmd.RunCommand('Clipboard COPY FILE="' + tmpPath + '\\' + arcname + '.zip"');
}
} else {
DOpus.Output("The key pressed is not supported as modifier.");
Dlg.window = tab;
Dlg.icon = "warning";
Dlg.top = true;
Dlg.title = DOpus.Strings.Get("titleWarn");
Dlg.message = DOpus.Strings.Get("warningQual");
Dlg.buttons = "OK";
Dlg.Show;
}
DOpus.Output("ATTACH TO MAIL ENDS");
}
Ressources:
<resources>
<resource type="strings">
<strings lang="deutsch">
<string id="title">Archivname</string>
<string id="titleWarn">Warnung</string>
<string id="question">Wie soll das Archiv benannt werden?</string>
<string id="warningFolder1">Es wurden auch Ordner selektiert. Diese werden übersprungen.</string>
<string id="warningFolder2">Ordner kƶnnen nicht einer E-Mail angehƤngt werden.</string>
<string id="warningQual">Die gedrückte Taste wird als Modifikator nicht unterstützt.</string>
</strings>
<strings lang="english">
<string id="title">Archive name</string>
<string id="titleWarn">Warning</string>
<string id="question">How should the archive be named?</string>
<string id="warningFolder1">Folders were selected as well. These will be skipped.</string>
<string id="warningFolder2">Folders cannot be attached to an email.</string>
<string id="warningQual">The key pressed is not supported as modifier.</string>
</strings>
</resource>
</resources>
Button Download
Warning : Only tested with DOpus v12.26
V1.0.314
Mail.dcf (8.6 KB)
V1.0.315
Mail.dcf (9.3 KB)
- added the possibility to abort the script if the dialog box informs the user that folders will be ignored.