Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added "send via Thunderbird" button to eMailDialog #2602

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" alignment="1" pref="579" max="32767" attributes="0"/>
<Component id="jScrollPane2" alignment="1" max="32767" attributes="0"/>
<Component id="contentPanel" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -422,6 +422,20 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdSaveDraftActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cmdOpenTb">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons32/mail_forward.png"/>
iradraconis marked this conversation as resolved.
Show resolved Hide resolved
</Property>
<Property name="toolTipText" type="java.lang.String" value="Mit Thunderbird versenden"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdOpenTbActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JTextField" name="txtCc">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,11 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -1330,6 +1333,7 @@ private void initComponents() {
cmdAttach = new javax.swing.JButton();
jSeparator5 = new javax.swing.JToolBar.Separator();
cmdSaveDraft = new javax.swing.JButton();
cmdOpenTb = new javax.swing.JButton();
txtCc = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
txtTo = new javax.swing.JTextField();
Expand Down Expand Up @@ -1455,7 +1459,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(contentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel5Layout.setVerticalGroup(
Expand Down Expand Up @@ -1525,6 +1529,18 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
jToolBar1.add(cmdSaveDraft);

cmdOpenTb.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons32/mail_forward.png"))); // NOI18N
cmdOpenTb.setToolTipText("Mit Thunderbird versenden");
cmdOpenTb.setFocusable(false);
cmdOpenTb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
cmdOpenTb.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
cmdOpenTb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdOpenTbActionPerformed(evt);
}
});
jToolBar1.add(cmdOpenTb);

jLabel9.setText("BCC:");

cmbFrom.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
Expand Down Expand Up @@ -2604,6 +2620,170 @@ private void cmdTranscribeActionPerformed(java.awt.event.ActionEvent evt) {//GEN
}
}//GEN-LAST:event_cmdTranscribeActionPerformed

private void cmdOpenTbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOpenTbActionPerformed

// Pfad der Thunderbird-Executable abhängig vom Betriebssystem ermitteln
String thunderbirdPath = getThunderbirdExecutablePath();
if (thunderbirdPath == null) {
JOptionPane.showMessageDialog(this, "Thunderbird wurde nicht gefunden.");
return;
}

// Empfänger, CC, BCC und Betreff aus den Textfeldern holen
String to = this.txtTo.getText().trim();
String cc = this.txtCc.getText().trim();
String bcc = this.txtBcc.getText().trim();
String subject = this.txtSubject.getText().trim();

// Text des Editors holen
EditorImplementation ed = (EditorImplementation) this.contentPanel.getComponent(0);
String body = ed.getText().trim();

// Überprüfen, ob Anhänge in der attachments-Map vorhanden sind
List<String> attachmentList = new ArrayList<>();
if (!this.attachments.isEmpty()) {
for (String path : this.attachments.values()) {
attachmentList.add("file://" + path.replace("\\", "/"));
}
}

// Thunderbird-Aufruf zusammenstellen
List<String> command = new ArrayList<>();

// hier ggfs. Pfad vom Nutzer am Profil gespeichert
command.add(thunderbirdPath);
command.add("-compose");

StringBuilder composeCommand = new StringBuilder();

if (!to.isEmpty()) {
composeCommand.append("to='").append(to).append("'");
}

if (!cc.isEmpty()) {
composeCommand.append(",cc='").append(cc).append("'");
}

if (!bcc.isEmpty()) {
composeCommand.append(",bcc='").append(bcc).append("'");
}

if (!subject.isEmpty()) {
composeCommand.append(",subject='").append(subject).append("'");
}

// Wenn "body" vorhanden ist, escapen
// if (!body.isEmpty()) {
// composeCommand.append(",body='").append(escapeBody(body)).append("'");
// }

// Wenn "body" vorhanden ist
if (!body.isEmpty()) {
composeCommand.append(",body='").append(body).append("'");
}

// Wenn mehrere Anhänge vorhanden sind, diese als kommagetrennte Liste hinzufügen
if (!attachmentList.isEmpty()) {
composeCommand.append(",attachment='").append(String.join(",", attachmentList)).append("'");
}

// Füge den zusammengesetzten Compose-Befehl hinzu
command.add(composeCommand.toString());

// Den vollständigen Befehl in der Konsole ausgeben
System.out.println("Thunderbird Command: " + String.join(" ", command));
iradraconis marked this conversation as resolved.
Show resolved Hide resolved

// Thunderbird mit ProcessBuilder aufrufen
try {
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
iradraconis marked this conversation as resolved.
Show resolved Hide resolved
JOptionPane.showMessageDialog(this, "Fehler beim Öffnen von Thunderbird: " + e.getMessage());
}
}//GEN-LAST:event_cmdOpenTbActionPerformed

private String getThunderbirdExecutablePath() {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
iradraconis marked this conversation as resolved.
Show resolved Hide resolved
String path = getThunderbirdExecutablePathWindows();
if (path == null) {
path = getThunderbirdExecutablePathWindowsFallback();
}
return path;
} else if (os.contains("mac")) {
return getThunderbirdExecutablePathMac();
} else if (os.contains("nix") || os.contains("nux")) {
return getThunderbirdExecutablePathLinux();
}
return null; // Unbekanntes Betriebssystem
iradraconis marked this conversation as resolved.
Show resolved Hide resolved
}

private String getThunderbirdExecutablePathLinux() {
try {
ProcessBuilder processBuilder = new ProcessBuilder("which", "thunderbird");
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String path = reader.readLine();
if (path != null && !path.isEmpty()) {
return path; // Der gefundene Pfad von Thunderbird
} else {
throw new IOException("Thunderbird wurde nicht gefunden.");
}
} catch (IOException e) {
e.printStackTrace();
iradraconis marked this conversation as resolved.
Show resolved Hide resolved
return null; // Thunderbird wurde nicht gefunden
}
}


private String getThunderbirdExecutablePathWindows() {
try {
ProcessBuilder processBuilder = new ProcessBuilder("reg", "query",
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Clients\\Mail\\Mozilla Thunderbird\\InstallPath");
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.trim().startsWith("HKEY_LOCAL_MACHINE")) {
// Dies ist der Pfad zur Thunderbird-Installation
String path = line.split("\\s{4,}")[1].trim();
return path + "\\thunderbird.exe";
}
}
} catch (IOException e) {
e.printStackTrace();
iradraconis marked this conversation as resolved.
Show resolved Hide resolved
}
return null;
}


private String getThunderbirdExecutablePathWindowsFallback() {
String[] possiblePaths = {
"C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe",
"C:\\Program Files (x86)\\Mozilla Thunderbird\\thunderbird.exe"
};

for (String path : possiblePaths) {
File file = new File(path);
if (file.exists() && file.isFile()) {
return path; // Gefundene Thunderbird-Executable
}
}
return null; // Thunderbird wurde nicht gefunden
}


private String getThunderbirdExecutablePathMac() {
String defaultPath = "/Applications/Thunderbird.app/Contents/MacOS/thunderbird";
File file = new File(defaultPath);
if (file.exists() && file.isFile()) {
return defaultPath; // Gefundene Thunderbird-Executable
}
return null; // Thunderbird wurde nicht gefunden
}


private void startRecording() {
try {
AudioFormat audioFormat = AudioUtils.getAudioFormat();
Expand Down Expand Up @@ -2838,6 +3018,7 @@ public void windowClosing(java.awt.event.WindowEvent e) {
private javax.swing.JComboBox cmbTemplates;
private javax.swing.JButton cmdAssistant;
private javax.swing.JButton cmdAttach;
private javax.swing.JButton cmdOpenTb;
private javax.swing.JButton cmdRecipients;
private javax.swing.JButton cmdRecipientsBcc;
private javax.swing.JButton cmdRecipientsCc;
Expand Down
Loading