From 86c7e47726c33df45cb066962b4614daa39befb4 Mon Sep 17 00:00:00 2001
From: Ituki Kirihara <ituki@fc.to>
Date: Sun, 17 May 2015 13:05:26 +0900
Subject: [PATCH] =?utf8?q?qmail=E3=81=8B=E3=82=89lmtp=E8=BB=A2=E9=80=81?=
 =?utf8?q?=E5=87=BA=E6=9D=A5=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99?=
 =?utf8?q?=E3=82=8B=E3=83=91=E3=83=83=E3=83=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

手抜き注意

Signed-off-by: Ituki Kirihara <ituki@fc.to>
---
 qmail-remote-lmtp.patch | 102 ++++++++++++++++++++++++++++++++++++++++++++++++
 readme.txt              |  20 ++++++++++
 2 files changed, 122 insertions(+)
 create mode 100644 qmail-remote-lmtp.patch
 create mode 100644 readme.txt

diff --git a/qmail-remote-lmtp.patch b/qmail-remote-lmtp.patch
new file mode 100644
index 0000000..4d4c988
--- /dev/null
+++ b/qmail-remote-lmtp.patch
@@ -0,0 +1,102 @@
+--- qmail-remote.c.org	Mon Jun 15 19:53:16 1998
++++ qmail-remote.c	Tue Apr 14 08:48:29 2015
+@@ -29,6 +29,11 @@
+ #include "timeoutread.h"
+ #include "timeoutwrite.h"
+ 
++#include <string.h>
++#include <fcntl.h>
++#include <sys/socket.h>
++#include <sys/un.h>
++
+ #define HUGESMTPTEXT 5000
+ 
+ #define PORT_SMTP 25 /* silly rabbit, /etc/services is for users */
+@@ -44,6 +49,8 @@
+ stralloc host = {0};
+ stralloc sender = {0};
+ 
++int lmtpmode = 0;
++
+ saa reciplist = {0};
+ 
+ struct ip_address partner;
+@@ -86,6 +93,12 @@
+ it isn't in my control/locals file, so I don't treat it as local. (#5.4.6)\n");
+ zerodie(); }
+ 
++void temp_no_lmtp_so_long() { out("ZLMTP file can't open\n"); zerodie(); }
++void temp_no_lmtp_socketopen() { out("ZLMTP socket can't open\n"); zerodie(); }
++void temp_no_lmtp_open() { out("ZLMTP file can't open\n"); zerodie(); }
++void temp_no_lmtp_non_support_multircpt() { out("Zcurrent LMTP don't support multi rcpt...\n"); zerodie(); }
++
++
+ void outhost()
+ {
+   char x[IPFMT];
+@@ -224,7 +237,11 @@
+  
+   if (smtpcode() != 220) quit("ZConnected to "," but greeting failed");
+  
+-  substdio_puts(&smtpto,"HELO ");
++  if (lmtpmode){
++    substdio_puts(&smtpto,"LHLO ");
++  }else{
++    substdio_puts(&smtpto,"HELO ");
++  }
+   substdio_put(&smtpto,helohost.s,helohost.len);
+   substdio_puts(&smtpto,"\r\n");
+   substdio_flush(&smtpto);
+@@ -239,6 +256,9 @@
+   if (code >= 400) quit("ZConnected to "," but sender was rejected");
+  
+   flagbother = 0;
++  if (lmtpmode && reciplist.len != 1){
++    temp_no_lmtp_non_support_multircpt();
++  }
+   for (i = 0;i < reciplist.len;++i) {
+     substdio_puts(&smtpto,"RCPT TO:<");
+     substdio_put(&smtpto,reciplist.sa[i].s,reciplist.sa[i].len);
+@@ -338,6 +358,7 @@
+   int flagallaliases;
+   int flagalias;
+   char *relayhost;
++  struct sockaddr_un address;
+  
+   sig_pipeignore();
+   if (argc < 4) perm_usage();
+@@ -357,7 +378,11 @@
+   if (relayhost) {
+     i = str_chr(relayhost,':');
+     if (relayhost[i]) {
+-      scan_ulong(relayhost + i + 1,&port);
++      if (strcmp(relayhost + i + 1,"lmtp") == 0){
++        lmtpmode = 1;
++      }else{
++        scan_ulong(relayhost + i + 1,&port);
++      }
+       relayhost[i] = 0;
+     }
+     if (!stralloc_copys(&host,relayhost)) temp_nomem();
+@@ -380,7 +405,20 @@
+     ++recips;
+   }
+ 
+- 
++  if (lmtpmode){
++    stralloc_0(&host);
++    if (host.len >= sizeof(address.sun_path) -1) temp_no_lmtp_so_long();
++    smtpfd = socket(AF_UNIX,SOCK_STREAM,0);
++    if (smtpfd == -1) temp_no_lmtp_socketopen();
++    address.sun_family = AF_UNIX;
++    strcpy(address.sun_path, host.s);
++    if (connect(smtpfd,(struct sockaddr *)&address,sizeof(address)) == -1) temp_no_lmtp_open();
++    smtp(); /* does not return */
++    close(smtpfd);
++    temp_noconn();
++    /* end program */
++  }
++
+   random = now() + (getpid() << 16);
+   switch (relayhost ? dns_ip(&ip,&host) : dns_mxip(&ip,&host,random)) {
+     case DNS_MEM: temp_nomem();
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..7e9f678
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,20 @@
+smtproutesに以下の拡張を施す
+
+domain:relay:port
+↓
+domain:relay:port or "lmtp"
+
+domain:relay:lmtp と記述することで、relay(ローカルパス)にLMTPでメールがリレーされる。
+
+変更ファイル qmail-remote.c
+
+relayにはlmtp(dovecot)のパスを書く
+パーミッションはgroup= qmail mode = 0600 user=qmailr\
+例えば
+
+test.proj.jp:/var/spool/dovecot-lmtp-qmail:lmtp
+
+と書いておけば、test.proj.jpはdovecotのlmtpを経由して送信される
+
+
+
-- 
2.4.0