* Implemented most of MAIL FROM:
[citadel.git] / citadel / serv_smtp.c
index 30a1daf1053560ac4da23c87a76521c7681e9a58..291f90064b12fc5883e08f1825ecd9fc091d1ef2 100644 (file)
@@ -36,6 +36,7 @@ struct citsmtp {
        struct usersupp vrfy_buffer;
        int vrfy_count;
        char vrfy_match[256];
+       char from[256];
 };
 
 enum {
@@ -88,6 +89,7 @@ void smtp_help(void) {
        cprintf("214-    EXPN\n");
        cprintf("214-    HELO\n");
        cprintf("214-    HELP\n");
+       cprintf("214-    MAIL\n");
        cprintf("214-    NOOP\n");
        cprintf("214-    QUIT\n");
        cprintf("214-    RSET\n");
@@ -247,11 +249,58 @@ void smtp_expn(char *argbuf) {
  */
 void smtp_rset(void) {
        memset(SMTP, 0, sizeof(struct citsmtp));
+       if (CC->logged_in) logout(CC);
        cprintf("250 Zap!\n");
 }
 
 
 
+/*
+ * Implements the "MAIL From:" command
+ */
+void smtp_mail(char *argbuf) {
+       char user[256];
+       char node[256];
+       int cvt;
+
+       if (strlen(SMTP->from) != 0) {
+               cprintf("503 Only one sender permitted\n");
+               return;
+       }
+
+       if (strncasecmp(argbuf, "From:", 5)) {
+               cprintf("501 Syntax error\n");
+               return;
+       }
+
+       strcpy(SMTP->from, &argbuf[5]);
+       striplt(SMTP->from);
+
+       if (strlen(SMTP->from) == 0) {
+               cprintf("501 Empty sender name is not permitted\n");
+               return;
+       }
+
+
+       /* If this SMTP connection is from a logged-in user, make sure that
+        * the user only sends email from his/her own address.
+        */
+       if (CC->logged_in) {
+               lprintf(9, "Me-checking <%s>\n", SMTP->from);
+               cvt = convert_internet_address(user, node, SMTP->from);
+               lprintf(9, "cvt=%d, citaddr=<%s@%s>\n", cvt, user, node);
+               if ( (cvt != 0) || (strcasecmp(user, CC->usersupp.fullname))) {
+                       cprintf("550 <%s> is not your address.\n", SMTP->from);
+                       strcpy(SMTP->from, "");
+                       return;
+               }
+       }
+
+       cprintf("250 Sender ok.  Groovy.\n");
+}
+
+
+
 /* 
  * Main command loop for SMTP sessions.
  */
@@ -296,6 +345,10 @@ void smtp_command_loop(void) {
                smtp_help();
        }
 
+       else if (!strncasecmp(cmdbuf, "MAIL", 4)) {
+               smtp_mail(&cmdbuf[5]);
+       }
+
        else if (!strncasecmp(cmdbuf, "NOOP", 4)) {
                cprintf("250 This command successfully did nothing.\n");
        }