X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Femail%2FSendmail.java;h=601130500e96719c1fe913db1b61f7240a5dd94d;hb=446d3aa82c177eb844f6f19c8f85d4a6e631efe7;hp=67c0fb5b2eb00a6d802afe25989b2044ee2f0db2;hpb=943d8e7ed0ea5a9d56e7e694a3cbd849c52bad16;p=gigi.git diff --git a/src/org/cacert/gigi/email/Sendmail.java b/src/org/cacert/gigi/email/Sendmail.java index 67c0fb5b..60113050 100644 --- a/src/org/cacert/gigi/email/Sendmail.java +++ b/src/org/cacert/gigi/email/Sendmail.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; +import java.security.GeneralSecurityException; import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Date; @@ -12,6 +13,8 @@ import java.util.Locale; import java.util.Properties; import java.util.regex.Pattern; +import org.cacert.gigi.util.ServerConstants; + public class Sendmail extends EmailProvider { protected Sendmail(Properties props) {} @@ -23,7 +26,7 @@ public class Sendmail extends EmailProvider { String[] bits = from.split(","); - Socket smtp = new Socket("dogcraft.de", 25); + Socket smtp = new Socket("localhost", 25); PrintWriter out = new PrintWriter(smtp.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream())); readResponse(in); @@ -56,7 +59,7 @@ public class Sendmail extends EmailProvider { } else { out.print("Reply-To: " + from + "\r\n"); } - out.print("From: " + from + "\r\n"); + out.print("From: support@" + ServerConstants.getWwwHostName().replaceAll("^www.", "") + "\r\n"); out.print("To: " + to + "\r\n"); if (NON_ASCII.matcher(subject).matches()) { @@ -64,24 +67,24 @@ public class Sendmail extends EmailProvider { } 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"); + StringBuffer headers = new StringBuffer(); + headers.append("Content-Type: text/plain; charset=\"utf-8\"\r\n"); + headers.append("Content-Transfer-Encoding: base64\r\n"); // out.print(chunk_split(base64_encode(recode("html..utf-8", // $message)))."\r\n.\r\n"); - message = message + "\r\n"; + headers.append("\r\n"); + headers.append(Base64.getEncoder().encodeToString(message.getBytes("UTF-8")).replaceAll("(.{64})(?=.)", "$1\r\n")); + headers.append("\r\n"); - String sendM = message.replace("\r", "").replace("\n.\n", "\n").replace("\n.\n", "\n").replace("\n", "\r\n") + ".\r\n"; - out.print(sendM); - out.flush(); + try { + sendSigned(headers.toString(), out); + out.print("\r\n.\r\n"); + out.flush(); + } catch (GeneralSecurityException e) { + e.printStackTrace(); + smtp.close(); + return; + } readResponse(in); out.print("QUIT\n"); out.flush(); @@ -92,6 +95,7 @@ public class Sendmail extends EmailProvider { private static void readResponse(BufferedReader in) throws IOException { String line; while ((line = in.readLine()) != null && line.matches("\\d+-")) { + System.out.println(line); } }