]> code.citadel.org Git - citadel.git/blobdiff - citadel/citmail.c
* citserver.c, msgbase.c, user_ops.c: hide the owner-prefix of mail
[citadel.git] / citadel / citmail.c
index 720b4ed95b20ba26618de5c64c7993f21552f852..9581ca1996d7e091ae58354224b09b49e2b7967b 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * citmail.c v4.0
+ * citmail.c v4.1
+ * $Id$
  *
  * This program may be used as a local mail delivery agent, which will allow
  * all Citadel users to receive Internet e-mail.  To enable this functionality,
 #include <pwd.h>
 #include <errno.h>
 #include <syslog.h>
+#include <limits.h>
 #include "citadel.h"
+#include "config.h"
+#include "internetmail.h"
 
 #define LOCAL 0
 #define REMOTE 1
 char *monthdesc[] = {  "Jan","Feb","Mar","Apr","May","Jun",
                        "Jul","Aug","Sep","Oct","Nov","Dec" };
 
-
-
-void LoadInternetConfig();
-void get_config();
-int IsHostLocal();
-struct config config;
-
 char ALIASES[128];
 char CIT86NET[128];
 char SENDMAIL[128];
@@ -56,10 +53,10 @@ char OUTGOING_FQDN[128];
 int RUN_NETPROC = 1;
 
 
-long conv_date(sdbuf)
-char sdbuf[]; {
+long conv_date(char *sdbuf)
+{
        int a,b,cpos,tend,tval;
-       long now;
+       time_t now;
        struct tm *tmbuf;
        char dbuf[128];
 
@@ -127,37 +124,36 @@ char sdbuf[]; {
        }
 
 
-#ifdef NO_STRERROR
+#ifndef HAVE_STRERROR
 /*
  * replacement strerror() for systems that don't have it
  */
-char *strerror(e)
-int e; {
+char *strerror(int e)
+{
        static char buf[32];
 
-       sprintf(buf,"errno = %d",e);
+       snprintf(buf,sizeof buf,"errno = %d",e);
        return(buf);
        }
 #endif
 
-int haschar(st,ch)
-char st[];
-int ch; {
+int haschar(char *st, int ch)
+{
        int a,b;
        b=0;
        for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
        return(b);
        }
 
-void strip_trailing_whitespace(buf)
-char buf[]; {
+void strip_trailing_whitespace(char *buf)
+{
        while(isspace(buf[strlen(buf)-1]))
                buf[strlen(buf)-1]=0;
        }
 
 /* strip leading and trailing spaces */
-void striplt(buf)
-char buf[]; {
+void striplt(char *buf)
+{
        while ( (strlen(buf)>0) && (buf[0]==32) ) strcpy(buf,&buf[1]);
        while (buf[strlen(buf)-1] == 32) buf[strlen(buf)-1] = 0;
        }
@@ -196,11 +192,8 @@ void host_alias(char host[]) {
 /*
  * Split an RFC822-style address into userid, host, and full name
  */
-void process_rfc822_addr(rfc822,user,node,name)
-char rfc822[];
-char user[];
-char node[];
-char name[];  {
+void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
+{
        int a;
 
        /* extract full name - first, it's From minus <userid> */
@@ -343,7 +336,7 @@ void loopcopy(FILE *to, FILE *from) {
  */
 void do_citmail(char recp[], int dtype) {
 
-       long now;
+       time_t now;
        FILE *temp;
        int a;
        char buf[128];
@@ -368,25 +361,24 @@ void do_citmail(char recp[], int dtype) {
 
                /* chop the system name out, so we're left with a user */
                while (haschar(recp,'!')) strcpy(recp,&recp[1]);
+               }
 
-               /* now convert underscores to spaces */
-               for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=' ';
-
-               /* Are we delivering to a room instead of a user? */
-               if (!strncasecmp(recp, "room ", 5)) {
-                       strcpy(targetroom, &recp[5]);
-                       strcpy(recp, "");
-                       }
-               else {
-                       strcpy(targetroom, "");
-                       }
+       /* Convert underscores to spaces */
+       for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=' ';
 
+       /* Are we delivering to a room instead of a user? */
+       if (!strncasecmp(recp, "room ", 5)) {
+               strcpy(targetroom, &recp[5]);
+               strcpy(recp, "");
+               }
+       else {
+               strcpy(targetroom, MAILROOM);
                }
 
        time(&now);
-       sprintf(from, "postmaster@%s", config.c_nodename);
+       snprintf(from, sizeof from, "postmaster@%s", config.c_nodename);
 
-       sprintf(buf, "./network/spoolin/citmail.%d", getpid());
+       snprintf(buf, sizeof buf, "./network/spoolin/citmail.%d", getpid());
        temp = fopen(buf,"w");
 
        putc(255,temp); putc(MES_NORMAL,temp); putc(1,temp);
@@ -412,7 +404,7 @@ void do_citmail(char recp[], int dtype) {
                fprintf(temp, "O%s%c", targetroom, 0);
                }
        else {
-               fprintf(temp, "OMail%c", 0);
+               fprintf(temp, "O%s%c", MAILROOM, 0);
                }
 
        fprintf(temp,"N%s%c", nodebuf, 0);
@@ -435,12 +427,12 @@ void do_citmail(char recp[], int dtype) {
        }
 
 
-void do_uudecode(target)
-char *target;  {
+void do_uudecode(char *target)
+{
        static char buf[1024];
        FILE *fp;
        
-       sprintf(buf,"cd %s; uudecode",target);
+       snprintf(buf,sizeof buf,"cd %s; uudecode",target);
 
        fp=popen(buf,"w");
        if (fp==NULL) return;
@@ -451,8 +443,8 @@ char *target;  {
 
        }
 
-int alias(name)
-char *name; {
+int alias(char *name)
+{
        FILE *fp;
        int a;
        char abuf[256];
@@ -517,9 +509,8 @@ void deliver(char recp[], int is_test, int deliver_to_ignet) {
 
 
 
-void main(argc,argv)
-int argc;
-char *argv[]; {
+int main(int argc, char **argv)
+{
        int is_test = 0;
        int deliver_to_ignet = 0;
        int smtp = 0;
@@ -618,7 +609,7 @@ char *argv[]; {
                
                                                        /* Otherwise, we're dealing with Citadel mail. */
                                                        else {
-                                                               sprintf(recp, "%s!%s", node, user);
+                                                               snprintf(recp, sizeof recp, "%s!%s", node, user);
                                                                deliver_to_ignet = 1;
                                                                printf("250 IGnet recipient.\n");
                                                                }
@@ -674,14 +665,14 @@ char *argv[]; {
                        * back to an external mail transport agent such as sendmail.
                        */
                        if (haschar(node, '.')) {
-                               sprintf(buf, SENDMAIL, recp);
+                               snprintf(buf, sizeof buf, SENDMAIL, recp);
                                system(buf);
                                exit(0);
                                }
        
                        /* Otherwise, we're dealing with Citadel mail. */
                        else {
-                               sprintf(recp, "%s!%s", node, user);
+                               snprintf(recp, sizeof recp, "%s!%s", node, user);
                                deliver_to_ignet = 1;
                                }