]> WPIA git - gigi.git/commitdiff
upd: make email sender address fixed.
authorFelix Dörre <felix@dogcraft.de>
Thu, 4 Aug 2016 23:20:50 +0000 (01:20 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 4 Aug 2016 23:20:50 +0000 (01:20 +0200)
Change-Id: I02f4f2707f989c7bf6c721baee04dcee6d280a37

src/org/cacert/gigi/api/FindAgent.java
src/org/cacert/gigi/email/EmailProvider.java
src/org/cacert/gigi/email/SendMail.java
src/org/cacert/gigi/output/template/MailTemplate.java
tests/org/cacert/gigi/email/TestSendmail.java
tests/org/cacert/gigi/testUtils/BusinessTest.java
tests/org/cacert/gigi/testUtils/TestEmailReceiver.java
util-testing/org/cacert/gigi/email/CommandlineEmailProvider.java
util-testing/org/cacert/gigi/email/DelegateMailProvider.java
util-testing/org/cacert/gigi/email/TestEmailProvider.java
util-testing/org/cacert/gigi/pages/Manager.java

index bca3a1276c73ca4cb40c5adc67250cf43b931327..e64326b303bcd2238d4790ec71a7b7b48e762230 100644 (file)
@@ -99,7 +99,7 @@ public class FindAgent extends APIPoint {
                 return;
 
             }
-            EmailProvider.getInstance().sendMail(to.getEmail(), "[Find Agent] " + subject, body, to.getEmail(), null, null, null, null, false);
+            EmailProvider.getInstance().sendMail(to.getEmail(), "[Find Agent] " + subject, body, null, null, null, null, false);
         }
     }
 }
index ed61aeca2f6cf3ddab0c35f43c7a1e25ebb04031..ea6679cd1a98e0c878173c13c35d770999eea427 100644 (file)
@@ -25,7 +25,7 @@ import org.cacert.gigi.util.DNSUtil;
 
 public abstract class EmailProvider {
 
-    public abstract void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException;
+    public abstract void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException;
 
     private static EmailProvider instance;
 
index 43c07e8ae593f2841d46051d834f6cb4ef0d88d2..d7343fbe9a4f6348962625a84032dcd0040f146b 100644 (file)
@@ -31,19 +31,17 @@ public class SendMail extends EmailProvider {
     private static final Pattern NON_ASCII = Pattern.compile("[^a-zA-Z0-9 .-\\[\\]!_@]");
 
     @Override
-    public void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
-
-        String[] bits = from.split(",");
-
+    public void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+        String from = "support@" + ServerConstants.getWwwHostName().replaceAll("^www.", "");
         try (Socket smtp = new Socket(targetHost, targetPort); PrintWriter out = new PrintWriter(new OutputStreamWriter(smtp.getOutputStream(), "UTF-8")); BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream(), "UTF-8"));) {
             readSMTPResponse(in, 220);
             out.print("HELO www.cacert.org\r\n");
             out.flush();
             readSMTPResponse(in, 250);
-            out.print("MAIL FROM:<returns@cacert.org>\r\n");
+            out.print("MAIL FROM: <" + from + ">\r\n");
             out.flush();
             readSMTPResponse(in, 250);
-            bits = to.split(",");
+            String[] bits = to.split(",");
             for (String user : bits) {
                 out.print("RCPT TO:<" + user.trim() + ">\r\n");
                 out.flush();
@@ -68,7 +66,7 @@ public class SendMail extends EmailProvider {
             } else {
                 out.print("Reply-To: " + from + "\r\n");
             }
-            out.print("From: support@" + ServerConstants.getWwwHostName().replaceAll("^www.", "") + "\r\n");
+            out.print("From: " + from + "\r\n");
             out.print("To: " + to + "\r\n");
             if (NON_ASCII.matcher(subject).matches()) {
 
index 7f1a87d019cb2ba3ea01f2845cabe53a4f5ca85e..45f8594a594bdc762f5c157b6578aa7e6836bb7b 100644 (file)
@@ -65,7 +65,7 @@ public class MailTemplate extends Template {
         String body = runTemplate(this, l, vars);
         String subject = runTemplate(subjectBlock, l, vars);
 
-        SendMail.getInstance().sendMail(to, SUBJECT_TAG + subject, body, "support@cacert.org", null, null, null, null, false);
+        SendMail.getInstance().sendMail(to, SUBJECT_TAG + subject, body, null, null, null, null, false);
     }
 
     private static String runTemplate(Outputable toRun, Language l, Map<String, Object> vars) {
index 5ddd75080fe318da796e0bec0fa706352ac18d78..aa0e8a351164633c7ad629dec2eea8baf4d086de 100644 (file)
@@ -55,7 +55,7 @@ public class TestSendmail extends ConfiguredTest {
 
         String subj = "subj-" + createUniqueName();
         String msg = "msg-" + createUniqueName();
-        EmailProvider.getInstance().sendMail(succmail, subj, msg, "system@cacert.org", "system@cacert.org", "Testtarget", "Testsender", null, false);
+        EmailProvider.getInstance().sendMail(succmail, subj, msg, "system@cacert.org", "Testtarget", "Testsender", null, false);
 
         try (Socket s = SSLSocketFactory.getDefault().createSocket(imap, 993);//
                 PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream(), "UTF-8"), true);//
index 8de7a5868df942ca775e7496390d5647f32798aa..b78b37263eddccb3299688963f1c972b6c8c412b 100644 (file)
@@ -39,8 +39,8 @@ public abstract class BusinessTest extends ConfiguredTest {
         }
 
         @Override
-        public void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
-            TestMail tm = new TestEmailReceiver.TestMail(to, subject, message, fromname, replyto) {
+        public void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+            TestMail tm = new TestEmailReceiver.TestMail(to, subject, message, replyto) {
 
                 @Override
                 public void verify() throws IOException {
index 27b166f9667c35109839d9a4fccd404f117831fb..155539c798b1ed0c0e18ba7807e26b8df7610b89 100644 (file)
@@ -34,15 +34,12 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
 
         String message;
 
-        String from;
-
         String replyto;
 
-        public TestMail(String to, String subject, String message, String from, String replyto) {
+        public TestMail(String to, String subject, String message, String replyto) {
             this.to = to;
             this.subject = subject;
             this.message = message;
-            this.from = from;
             this.replyto = replyto;
         }
 
@@ -58,10 +55,6 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
             return message;
         }
 
-        public String getFrom() {
-            return from;
-        }
-
         public String getReplyto() {
             return replyto;
         }
@@ -174,9 +167,8 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
                     String to = dis.readUTF();
                     String subject = dis.readUTF();
                     String message = dis.readUTF();
-                    String from = dis.readUTF();
                     String replyto = dis.readUTF();
-                    mails.add(new TestMail(to, subject, message, from, replyto));
+                    mails.add(new TestMail(to, subject, message, replyto));
                 } else if (type.equals("challengeAddrBox")) {
                     String email = dis.readUTF();
                     dos.writeUTF(quickEmailCheck(email));
@@ -273,8 +265,8 @@ public final class TestEmailReceiver extends EmailProvider implements Runnable,
     }
 
     @Override
-    public void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
-        mails.add(new TestMail(to, subject, message, from, replyto));
+    public void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+        mails.add(new TestMail(to, subject, message, replyto));
     }
 
 }
index e23f47588fa553014b262659517b33b32ce8015f..263b4c49b6f3af34d71b16aa77eaa8ae907cb921 100644 (file)
@@ -8,12 +8,11 @@ public class CommandlineEmailProvider extends EmailProvider {
     public CommandlineEmailProvider(Properties p) {}
 
     @Override
-    public void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+    public void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
         synchronized (System.out) {
             System.out.println("== MAIL ==");
             System.out.println("To: " + to);
             System.out.println("Subject: " + subject);
-            System.out.println("From: " + from);
             System.out.println("Errors-To: " + errorsto);
             System.out.println("Extra: " + extra);
             System.out.println(message);
index c0143ebe0a855e79109f099c544e1d3ee1aeba81..109aae8dc17f7d1bba931a9cb9d34d23d3d92dd1 100644 (file)
@@ -25,9 +25,9 @@ public abstract class DelegateMailProvider extends EmailProvider {
     }
 
     @Override
-    public void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+    public void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
         if (target != null) {
-            target.sendMail(to, subject, message, from, replyto, toname, fromname, errorsto, extra);
+            target.sendMail(to, subject, message, replyto, toname, fromname, errorsto, extra);
         }
     }
 
index 91c0440504e7c46c259dbc5da1807045b32e3415..eb5eb820d795c8e21e10030404a0ce9d8def203c 100644 (file)
@@ -33,10 +33,10 @@ public class TestEmailProvider extends DelegateMailProvider {
     }
 
     @Override
-    public synchronized void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+    public synchronized void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
         while (true) {
             if ( !ensureLocalConnection() && getTarget() != null) {
-                super.sendMail(to, subject, message, from, replyto, toname, fromname, errorsto, extra);
+                super.sendMail(to, subject, message, replyto, toname, fromname, errorsto, extra);
                 return;
             }
             try {
@@ -47,7 +47,6 @@ public class TestEmailProvider extends DelegateMailProvider {
                 write(to);
                 write(subject);
                 write(message);
-                write(from);
                 write(replyto);
                 out.flush();
                 return;
index 8600785bc4a9da3033342c566f6a93e59ae231d6..0cf8e12d6055f342d0f81582cdad8922b4470ebb 100644 (file)
@@ -164,7 +164,7 @@ public class Manager extends Page {
         }
 
         @Override
-        public synchronized void sendMail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+        public synchronized void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
             HashMap<String, LinkedList<String>> mails = Manager.getInstance().emails;
             LinkedList<String> hismails = mails.get(to);
             if (hismails == null) {
@@ -173,7 +173,7 @@ public class Manager extends Page {
             hismails.addFirst(subject + "\n" + message);
             for (int i = 0; i < toForward.length; i++) {
                 if (toForward[i].matcher(to).matches()) {
-                    super.sendMail(to, subject, message, from, replyto, toname, fromname, errorsto, extra);
+                    super.sendMail(to, subject, message, replyto, toname, fromname, errorsto, extra);
                     return;
                 }
             }