Mail to a mailing list room must be from a subscriber (or a logged in user) otherwise...
authorArt Cancro <ajc@citadel.org>
Mon, 29 Nov 2021 19:24:06 +0000 (14:24 -0500)
committerArt Cancro <ajc@citadel.org>
Mon, 29 Nov 2021 19:24:06 +0000 (14:24 -0500)
citadel/internet_addressing.c
citadel/internet_addressing.h
citadel/modules/smtp/serv_smtp.c

index 4292725868445f8148e7eec2fe1465c580f88251..6fb485b1abef5e28600f27a8c3eee813309a7cfa 100644 (file)
@@ -1655,8 +1655,7 @@ void CtdlSetEmailAddressesForUser(char *requested_user, char *new_emailaddrs)
 /*
  * Auto-generate an Internet email address for a user account
  */
-void AutoGenerateEmailAddressForUser(struct ctdluser *user)
-{
+void AutoGenerateEmailAddressForUser(struct ctdluser *user) {
        char synthetic_email_addr[1024];
        int i, j;
        int u = 0;
@@ -1688,3 +1687,33 @@ void AutoGenerateEmailAddressForUser(struct ctdluser *user)
        strncpy(CC->user.emailaddrs, synthetic_email_addr, sizeof(user->emailaddrs));
        syslog(LOG_DEBUG, "user_ops: auto-generated email address <%s> for <%s>", synthetic_email_addr, user->fullname);
 }
+
+
+// Determine whether the supplied email address is subscribed to the supplied room's mailing list service.
+int is_email_subscribed_to_list(char *email, char *room_name) {
+       struct ctdlroom room;
+       long roomnum;
+       char *roomnetconfig;
+       int found_it = 0;
+
+       if (CtdlGetRoom(&room, room_name)) {
+               return(0);                                      // room not found, so definitely not subscribed
+       }
+       roomnum = room.QRnumber;
+       roomnetconfig = LoadRoomNetConfigFile(roomnum);
+       if (roomnetconfig == NULL) {
+               return(0);
+       }
+
+       // We're going to do a very sloppy match here and simply search for the specified email address
+       // anywhere in the room's netconfig.  If you don't like this, fix it yourself.
+       if (bmstrcasestr(roomnetconfig, email)) {
+               found_it = 1;
+       }
+       else {
+               found_it = 0;
+       }
+
+       free(roomnetconfig);
+       return(found_it);
+}
index 4b12ee74da23c3972e824edb5de91f48b01265cf..443033561ee235be2bb8ffefcfebbdd0a5fc9101 100644 (file)
@@ -21,6 +21,7 @@ struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822);
 int CtdlIsMe(char *addr, int addr_buf_len);
 int CtdlHostAlias(char *fqdn);
 char *harvest_collected_addresses(struct CtdlMessage *msg);
+int is_email_subscribed_to_list(char *email, char *room_name);
 
 /* 
  * Values that can be returned by CtdlHostAlias()
index a74e2bb9fa7fc0fdf9927a937afd42d484ac520d..549a291658758fd6e23347171319ac3b29f14df8 100644 (file)
@@ -715,6 +715,16 @@ void smtp_rcpt(void) {
                return;
        }
 
+       if (
+               (valid->num_room > 0)                                           // If it's mail to a room (mailing list)...
+               && (SMTP->message_originated_locally == 0)                      // ...and also inbound Internet mail...
+               && (is_email_subscribed_to_list((char *)ChrPtr(SMTP->from), valid->recp_room) == 0)     // ...and not a subscriber
+       ) {
+               cprintf("551 <%s> - This mailing list only accepts messages from subscribers.\r\n", ChrPtr(SMTP->OneRcpt));
+               free_recipients(valid);
+               return;
+       }
+
        cprintf("250 RCPT ok <%s>\r\n", ChrPtr(SMTP->OneRcpt));
        if (StrLength(SMTP->recipients) > 0) {
                StrBufAppendBufPlain(SMTP->recipients, HKEY(","), 0);