// This file contains functions which handle the mapping of Internet addresses
// to users on the Citadel system.
//
-// Copyright (c) 1987-2021 by the citadel.org team
+// Copyright (c) 1987-2022 by the citadel.org team
//
// This program is open source software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3.
// If the last item in a list of recipients was truncated to a partial address,
// remove it completely in order to avoid choking library functions.
-void sanitize_truncated_recipient(char *str)
-{
+void sanitize_truncated_recipient(char *str) {
if (!str) return;
if (num_tokens(str, ',') < 2) return;
}
-/*
- * Configure Internet email addresses for a user account, updating the Directory Index in the process
- */
-void CtdlSetEmailAddressesForUser(char *requested_user, char *new_emailaddrs)
-{
+// Configure Internet email addresses for a user account, updating the Directory Index in the process
+void CtdlSetEmailAddressesForUser(char *requested_user, char *new_emailaddrs) {
struct ctdluser usbuf;
int i;
char buf[SIZ];
- if (CtdlGetUserLock(&usbuf, requested_user) != 0) { // We are relying on the fact that the DirectoryIndex functions don't lock.
- return; // Silently fail here if we can't acquire a lock on the user record.
+ if (CtdlGetUserLock(&usbuf, requested_user) != 0) { // We can lock because the DirectoryIndex functions don't lock.
+ return; // Silently fail here if the specified user does not exist.
}
syslog(LOG_DEBUG, "internet_addressing: setting email addresses for <%s> to <%s>", usbuf.fullname, new_emailaddrs);
- /* Delete all of the existing directory index records for the user (easier this way) */
+ // Delete all of the existing directory index records for the user (easier this way)
for (i=0; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
CtdlDirectoryDelUser(buf, requested_user);
strcpy(usbuf.emailaddrs, new_emailaddrs); // make it official.
- /* Index all of the new email addresses (they've already been sanitized) */
+ // Index all of the new email addresses (they've already been sanitized)
for (i=0; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
CtdlDirectoryAddUser(buf, requested_user);
/*
* 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;
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
+ }
+
+ // If this room has the QR2_SMTP_PUBLIC flag set, anyone may email a post to this room, even non-subscribers.
+ if (room.QRflags2 & QR2_SMTP_PUBLIC) {
+ return(1);
+ }
+
+ 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);
+}