From b53642b6cb69546ec1b68fc941b1f79cf16dc51e Mon Sep 17 00:00:00 2001 From: Maximilian Steinert <71747937+iradraconis@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:48:14 +0200 Subject: [PATCH 1/4] added "send via Thunderbird" button to eMailDialog --- .../jlawyer/client/mail/SendEmailDialog.form | 16 +- .../jlawyer/client/mail/SendEmailDialog.java | 183 +++++++++++++++++- 2 files changed, 197 insertions(+), 2 deletions(-) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form index 768be26c9..bf82baf76 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form @@ -283,7 +283,7 @@ - + @@ -422,6 +422,20 @@ + + + + + + + + + + + + + + diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java index 058eeec6b..39d3e6e1e 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java @@ -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; @@ -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(); @@ -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( @@ -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" })); @@ -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 attachmentList = new ArrayList<>(); + if (!this.attachments.isEmpty()) { + for (String path : this.attachments.values()) { + attachmentList.add("file://" + path.replace("\\", "/")); + } + } + + // Thunderbird-Aufruf zusammenstellen + List 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)); + + // Thunderbird mit ProcessBuilder aufrufen + try { + ProcessBuilder processBuilder = new ProcessBuilder(command); + processBuilder.start(); + } catch (IOException e) { + e.printStackTrace(); + 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")) { + 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 + } + + 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(); + 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(); + } + 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(); @@ -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; From d97d904fb261eb5ebd02d87697bc045f3d3cb33b Mon Sep 17 00:00:00 2001 From: Maximilian Steinert <71747937+iradraconis@users.noreply.github.com> Date: Mon, 7 Oct 2024 06:18:31 +0200 Subject: [PATCH 2/4] added log messages added and changed button icon use SystemUtils method to determine OS --- .../jlawyer/client/mail/SendEmailDialog.form | 2 +- .../jlawyer/client/mail/SendEmailDialog.java | 27 +++++++++--------- .../src/icons32/openInThunderbird.png | Bin 0 -> 971 bytes 3 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 j-lawyer-client/src/icons32/openInThunderbird.png diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form index bf82baf76..7861aa26c 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.form @@ -425,7 +425,7 @@ - + diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java index 39d3e6e1e..ccf3d235d 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java @@ -697,6 +697,7 @@ import com.jdimension.jlawyer.client.utils.FrameUtils; import com.jdimension.jlawyer.client.utils.SelectAttachmentDialog; import com.jdimension.jlawyer.client.utils.StringUtils; +import com.jdimension.jlawyer.client.utils.SystemUtils; import com.jdimension.jlawyer.client.utils.ThreadUtils; import com.jdimension.jlawyer.email.EmailTemplate; import com.jdimension.jlawyer.persistence.AddressBean; @@ -1529,7 +1530,7 @@ 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.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons32/openInThunderbird.png"))); // NOI18N cmdOpenTb.setToolTipText("Mit Thunderbird versenden"); cmdOpenTb.setFocusable(false); cmdOpenTb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); @@ -2697,25 +2698,25 @@ private void cmdOpenTbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR try { ProcessBuilder processBuilder = new ProcessBuilder(command); processBuilder.start(); - } catch (IOException e) { - e.printStackTrace(); - JOptionPane.showMessageDialog(this, "Fehler beim Öffnen von Thunderbird: " + e.getMessage()); + } catch (Throwable t) { + log.error("Error opening Thunderbird", t); + JOptionPane.showMessageDialog(this, "Fehler beim Öffnen von Thunderbird: " + t); } }//GEN-LAST:event_cmdOpenTbActionPerformed private String getThunderbirdExecutablePath() { - String os = System.getProperty("os.name").toLowerCase(); - if (os.contains("win")) { + if (SystemUtils.isWindows()) { String path = getThunderbirdExecutablePathWindows(); if (path == null) { path = getThunderbirdExecutablePathWindowsFallback(); } return path; - } else if (os.contains("mac")) { + } else if (SystemUtils.isMacOs()) { return getThunderbirdExecutablePathMac(); - } else if (os.contains("nix") || os.contains("nux")) { + } else if (SystemUtils.isLinux()) { return getThunderbirdExecutablePathLinux(); } + log.error("Error finding Thunderbird Installation: unknown OS"); return null; // Unbekanntes Betriebssystem } @@ -2730,9 +2731,9 @@ private String getThunderbirdExecutablePathLinux() { } else { throw new IOException("Thunderbird wurde nicht gefunden."); } - } catch (IOException e) { - e.printStackTrace(); - return null; // Thunderbird wurde nicht gefunden + } catch (Throwable t) { + log.error("Error finding Thunderbird installation", t); + return null; } } @@ -2751,8 +2752,8 @@ private String getThunderbirdExecutablePathWindows() { return path + "\\thunderbird.exe"; } } - } catch (IOException e) { - e.printStackTrace(); + } catch (Throwable t) { + log.error("Error finding Thunderbird installation", t); } return null; } diff --git a/j-lawyer-client/src/icons32/openInThunderbird.png b/j-lawyer-client/src/icons32/openInThunderbird.png new file mode 100644 index 0000000000000000000000000000000000000000..4dac11c277e328785f5ddc26ca2528dd1e2a2710 GIT binary patch literal 971 zcmV;+12p`JP)Uk%WTh!tx%@6kj4xA zPA~6$^ZkD_^JW2jzMrlvbVzl0LX-`2XO!SiEagmAk}>Pn0cwW$s4=hOgEJ4?`&r}9$a_y z4vAXmR$x55p{tRu%!{|wmE;QMkx@^B1=GL}^TWa;X7$+>{I_>ao*W}8@CS~4TYrr% zJGz+Z&{QBKAXkNmV^~|u-QuybV=-KhwiEyaPo+f#B+<$HF}ZIj006Sl->prz4$u`R zQg}nxE9Y9a`&k`bb~M)3TA2qtI|=}RQGVf)=wz20Z$g&Xq;yg0W+FUptxa2=&%UlJ z0YI!U_(e-sol2B0S$ABPdgwATn|@gvZ{+fZu7{2TF`OcoZ9YY=+It$8`zkyUa6E?6 znAJO}jI(Oz0)C+9owecmNq(TG;jf`A7&yiR2r-T`SrDHkTYIdCm>a$T001$xmD9g% z1CII5v{x7N#_m>+ufTYSkmw~o`%3DW&L?V{wmc76O#Q&x2JP#3U|51|&5;u6!WAh1 z0K$mTXltp+XWuv90VJ5+^>-^^hm760OA?)&&a~VsWIAiEVp6$3nY5>XOx$`1!zBa& z0Nbm3W~nLK4xDY+)4pzRff)SHzFy2HK#3~?{2X(}?l*MR=~W-WU0M&cyc(QpthWQtk`zGR2sMGg4YC`;XbuB3&Z-h$)b@- z64lZq001g2`=XeHcLaKMkHqHrfsaqkn#-Apu`;eCJl=%=0x|R#`v0^HzAzz3sda4(n!pUiV+J35ZMF5kiJzI(u=;grwS(XQDQ!U tN>}0k1w2r-oZ66A3xw3qef2Cek>4hWaIclyqWS;;002ovPDHLkV1m^1zmNa` literal 0 HcmV?d00001 From 569c03316c700403a3b981eb94fb8d6916e7db4f Mon Sep 17 00:00:00 2001 From: Maximilian Steinert <71747937+iradraconis@users.noreply.github.com> Date: Mon, 7 Oct 2024 07:04:05 +0200 Subject: [PATCH 3/4] removed System.out.println --- .../com/jdimension/jlawyer/client/mail/SendEmailDialog.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java index ccf3d235d..8269e073a 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java @@ -2691,9 +2691,6 @@ private void cmdOpenTbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR // 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)); - // Thunderbird mit ProcessBuilder aufrufen try { ProcessBuilder processBuilder = new ProcessBuilder(command); From 3f98074c9eb0ff5f4e79d058f97d64b1cd22eae4 Mon Sep 17 00:00:00 2001 From: Maximilian Steinert <71747937+iradraconis@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:50:36 +0200 Subject: [PATCH 4/4] added warning if there is no recepient selected --- .../com/jdimension/jlawyer/client/mail/SendEmailDialog.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java index 8269e073a..c79a1d0dd 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/SendEmailDialog.java @@ -2659,6 +2659,9 @@ private void cmdOpenTbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR if (!to.isEmpty()) { composeCommand.append("to='").append(to).append("'"); + } else { + JOptionPane.showMessageDialog(this, "Empfänger ist erforderlich."); + return; } if (!cc.isEmpty()) {