autorespond の日本語対応

qmailadmin から利用できる, autorespond.
実は日本語に対応できていないので,少々強引な方法で,対応させるpatchを書く.

--- autorespond-2.0.5/autorespond.c.jp  2004-11-02 10:42:22.477178136 -0500
+++ autorespond-2.0.5/autorespond.c     2004-11-02 10:42:29.404125080 -0500
@@ -84,7 +84,7 @@
 #define DEFAULT_FROM   "$"     /* default "from" for the autorespond */

 #define WITH_OMESSAGE  1
-
+#define NKF            "/usr/bin/nkf -j"  /* path to the filter */

 #define HR_BUFFER_SIZE 1024

@@ -201,7 +201,7 @@
 int pie[2];                            /*envelope pipe*/
 FILE *mfp;
 char msg_buffer[256];
-
+char cmd[1024];
        /*open a pipe to qmail-queue*/
        if(pipe(pim)==-1 || pipe(pie)==-1) {
                return -1;
@@ -262,15 +262,17 @@
          message-id could be computed a little better*/
        fprintf(fdm,"Date: %u %s %u %02u:%02u:%02u -0000\nMessage-ID: <%lu.%u.bl
ah>\n"
                ,dt->tm_mday,montab[dt->tm_mon],dt->tm_year+1900,dt->tm_hour,dt-
>tm_min,dt->tm_sec,msgwhen,getpid() );
-
-       mfp = fopen( msg, "rb" );
+       /* add content-type */
+       fprintf(fdm,"Content-Type: text/plain; charset=\"ISO-2022-JP\"\n");

+       snprintf(cmd, sizeof(cmd), "%s %s", NKF, msg);
+       mfp = popen( cmd, "r" );
        while ( fgets( msg_buffer, sizeof(msg_buffer), mfp ) != NULL )
        {
                fprintf(fdm,"%s",msg_buffer);
        }

-       fclose(mfp);
+       pclose(mfp);

        fclose(fdm);

要は,

  • nkf で定型文章を jis に変換.
  • 送出するメールのヘッダに,文字コードがJISであることを示すContent-Type: text/plain; charset="ISO-2022-JP"をつける.

subjectとかfromの日本語は,RFCにしたがってencodeしてあげないといけないのだけど,その辺は無視.ちゃんと対応するためには,perl なり php でautorespondもどきを実装したほうが早そうなんだけど…そこまで作業できません.