]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/email/Sendmail.java
Format code according do BenBE's formatter.
[gigi.git] / src / org / cacert / gigi / email / Sendmail.java
index f47d2bc3cbefdba25a40a95f20c5557f4b7e5c1e..67c0fb5b2eb00a6d802afe25989b2044ee2f0db2 100644 (file)
@@ -13,89 +13,87 @@ import java.util.Properties;
 import java.util.regex.Pattern;
 
 public class Sendmail extends EmailProvider {
-       protected Sendmail(Properties props) {
-       }
 
-       private static final Pattern NON_ASCII = Pattern.compile("[^a-zA-Z0-9 .-\\[\\]!_@]");
+    protected Sendmail(Properties props) {}
 
-       @Override
-       public void sendmail(String to, String subject, String message, String from, String replyto, String toname,
-               String fromname, String errorsto, boolean extra) throws IOException {
+    private static final Pattern NON_ASCII = Pattern.compile("[^a-zA-Z0-9 .-\\[\\]!_@]");
 
-               String[] bits = from.split(",");
+    @Override
+    public void sendmail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
 
-               Socket smtp = new Socket("dogcraft.de", 25);
-               PrintWriter out = new PrintWriter(smtp.getOutputStream());
-               BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream()));
-               readResponse(in);
-               out.print("HELO www.cacert.org\r\n");
-               out.flush();
-               readResponse(in);
-               out.print("MAIL FROM:<returns@cacert.org>\r\n");
-               out.flush();
-               readResponse(in);
-               bits = to.split(",");
-               for (String user : bits) {
-                       out.print("RCPT TO:<" + user.trim() + ">\r\n");
-                       out.flush();
-                       readResponse(in);
-               }
-               out.print("DATA\r\n");
-               out.flush();
-               readResponse(in);
-               out.print("X-Mailer: CAcert.org Website\r\n");
-               // if (array_key_exists("REMOTE_ADDR", $_SERVER)) {
-               // out.print("X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
-               // }
-               // TODO
-               SimpleDateFormat emailDate = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss ZZZZ (z)", Locale.ENGLISH);
-               out.print("Date: " + emailDate.format(new Date(System.currentTimeMillis())) + "\r\n");
-               out.print("Sender: " + errorsto + "\r\n");
-               out.print("Errors-To: " + errorsto + "\r\n");
-               if (replyto != null) {
-                       out.print("Reply-To: " + replyto + "\r\n");
-               } else {
-                       out.print("Reply-To: " + from + "\r\n");
-               }
-               out.print("From: " + from + "\r\n");
-               out.print("To: " + to + "\r\n");
-               if (NON_ASCII.matcher(subject).matches()) {
+        String[] bits = from.split(",");
 
-                       out.print("Subject: =?utf-8?B?" + Base64.getEncoder().encodeToString(subject.getBytes()) + "?=\r\n");
-               } else {
-                       out.print("Subject: " + subject + "\r\n");
-               }
-               out.print("Mime-Version: 1.0\r\n");
-               if (!extra) {
-                       out.print("Content-Type: text/plain; charset=\"utf-8\"\r\n");
-                       out.print("Content-Transfer-Encoding: 8bit\r\n");
-               } else {
-                       out.print("Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
-                       out.print("Content-Transfer-Encoding: quoted-printable\r\n");
-                       out.print("Content-Disposition: inline\r\n");
-               }
-               // out.print("Content-Transfer-Encoding: BASE64\r\n");
-               out.print("\r\n");
-               // out.print(chunk_split(base64_encode(recode("html..utf-8",
-               // $message)))."\r\n.\r\n");
-               message = message + "\r\n";
+        Socket smtp = new Socket("dogcraft.de", 25);
+        PrintWriter out = new PrintWriter(smtp.getOutputStream());
+        BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream()));
+        readResponse(in);
+        out.print("HELO www.cacert.org\r\n");
+        out.flush();
+        readResponse(in);
+        out.print("MAIL FROM:<returns@cacert.org>\r\n");
+        out.flush();
+        readResponse(in);
+        bits = to.split(",");
+        for (String user : bits) {
+            out.print("RCPT TO:<" + user.trim() + ">\r\n");
+            out.flush();
+            readResponse(in);
+        }
+        out.print("DATA\r\n");
+        out.flush();
+        readResponse(in);
+        out.print("X-Mailer: CAcert.org Website\r\n");
+        // if (array_key_exists("REMOTE_ADDR", $_SERVER)) {
+        // out.print("X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
+        // }
+        // TODO
+        SimpleDateFormat emailDate = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss ZZZZ (z)", Locale.ENGLISH);
+        out.print("Date: " + emailDate.format(new Date(System.currentTimeMillis())) + "\r\n");
+        out.print("Sender: " + errorsto + "\r\n");
+        out.print("Errors-To: " + errorsto + "\r\n");
+        if (replyto != null) {
+            out.print("Reply-To: " + replyto + "\r\n");
+        } else {
+            out.print("Reply-To: " + from + "\r\n");
+        }
+        out.print("From: " + from + "\r\n");
+        out.print("To: " + to + "\r\n");
+        if (NON_ASCII.matcher(subject).matches()) {
 
-               String sendM = message.replace("\r", "").replace("\n.\n", "\n").replace("\n.\n", "\n").replace("\n", "\r\n")
-                       + ".\r\n";
-               out.print(sendM);
-               out.flush();
-               readResponse(in);
-               out.print("QUIT\n");
-               out.flush();
-               readResponse(in);
-               smtp.close();
-       }
+            out.print("Subject: =?utf-8?B?" + Base64.getEncoder().encodeToString(subject.getBytes()) + "?=\r\n");
+        } else {
+            out.print("Subject: " + subject + "\r\n");
+        }
+        out.print("Mime-Version: 1.0\r\n");
+        if ( !extra) {
+            out.print("Content-Type: text/plain; charset=\"utf-8\"\r\n");
+            out.print("Content-Transfer-Encoding: 8bit\r\n");
+        } else {
+            out.print("Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
+            out.print("Content-Transfer-Encoding: quoted-printable\r\n");
+            out.print("Content-Disposition: inline\r\n");
+        }
+        // out.print("Content-Transfer-Encoding: BASE64\r\n");
+        out.print("\r\n");
+        // out.print(chunk_split(base64_encode(recode("html..utf-8",
+        // $message)))."\r\n.\r\n");
+        message = message + "\r\n";
 
-       private static void readResponse(BufferedReader in) throws IOException {
-               String line;
-               while ((line = in.readLine()) != null && line.matches("\\d+-")) {
-               }
+        String sendM = message.replace("\r", "").replace("\n.\n", "\n").replace("\n.\n", "\n").replace("\n", "\r\n") + ".\r\n";
+        out.print(sendM);
+        out.flush();
+        readResponse(in);
+        out.print("QUIT\n");
+        out.flush();
+        readResponse(in);
+        smtp.close();
+    }
 
-       }
+    private static void readResponse(BufferedReader in) throws IOException {
+        String line;
+        while ((line = in.readLine()) != null && line.matches("\\d+-")) {
+        }
+
+    }
 
 }