#include <iconv.h>
#if 0
-/* This is the non-define version in case of s.b. needing to debug */
+/* This is the non-define version in case it is needed for debugging */
inline void FindNextEnd (char *bptr, char *end)
{
/* Find the next ?Q? */
char encoding[16];
char istr[1024];
iconv_t ic = (iconv_t)(-1) ;
- char *ibuf; /**< Buffer of characters to be converted */
- char *obuf; /**< Buffer for converted characters */
- size_t ibuflen; /**< Length of input buffer */
- size_t obuflen; /**< Length of output buffer */
- char *isav; /**< Saved pointer to input buffer */
- char *osav; /**< Saved pointer to output buffer */
+ char *ibuf; // Buffer of characters to be converted
+ char *obuf; // Buffer for converted characters
+ size_t ibuflen; // Length of input buffer
+ size_t obuflen; // Length of output buffer
+ char *isav; // Saved pointer to input buffer
+ char *osav; // Saved pointer to output buffer
int passes = 0;
int i, len, delta;
int illegal_non_rfc2047_encoding = 0;
for (i=0; i<len; ++i) {
if ((buf[i] < 32) || (buf[i] > 126)) {
illegal_non_rfc2047_encoding = 1;
- i = len; ///< take a shortcut, it won't be more than one.
+ i = len; // take a shortcut, it won't be more than one.
}
}
if (illegal_non_rfc2047_encoding) {
ibuf = malloc(1024);
isav = ibuf;
- if (!strcasecmp(encoding, "B")) { /**< base64 */
+ if (!strcasecmp(encoding, "B")) { // base64
ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
}
- else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
+ else if (!strcasecmp(encoding, "Q")) { // quoted-printable
size_t len;
unsigned long pos;
ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
}
else {
- strcpy(ibuf, istr); /**< unknown encoding */
+ strcpy(ibuf, istr); // unknown encoding
ibuflen = strlen(istr);
}
#endif
-
struct trynamebuf {
char buffer1[SIZ];
char buffer2[SIZ];
};
char *inetcfg = NULL;
-struct spamstrings_t *spamstrings = NULL;
-
/*
* Return nonzero if the supplied name is an alias for this host.
char host[256], type[256];
int found = 0;
- if (fqdn == NULL) return(hostalias_nomatch);
- if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
- if (!strcasecmp(fqdn, "localhost")) return(hostalias_localhost);
- if (!strcasecmp(fqdn, CtdlGetConfigStr("c_fqdn"))) return(hostalias_localhost);
- if (!strcasecmp(fqdn, CtdlGetConfigStr("c_nodename"))) return(hostalias_localhost);
- if (inetcfg == NULL) return(hostalias_nomatch);
+ if (fqdn == NULL) return(hostalias_nomatch);
+ if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
+ if (!strcasecmp(fqdn, "localhost")) return(hostalias_localhost);
+ if (!strcasecmp(fqdn, CtdlGetConfigStr("c_fqdn"))) return(hostalias_localhost);
+ if (!strcasecmp(fqdn, CtdlGetConfigStr("c_nodename"))) return(hostalias_localhost);
+ if (inetcfg == NULL) return(hostalias_nomatch);
config_lines = num_tokens(inetcfg, '\n');
for (i=0; i<config_lines; ++i) {
found = 0;
/* Process these in a specific order, in case there are multiple matches.
- * We want directory to override masq, for example.
+ * We want localhost to override masq, for example.
*/
if ( (!strcasecmp(type, "masqdomain")) && (!strcasecmp(fqdn, host))) {
found = hostalias_masq;
}
+
if ( (!strcasecmp(type, "localhost")) && (!strcasecmp(fqdn, host))) {
found = hostalias_localhost;
}
+
+ // "directory" used to be a distributed version of "localhost" but they're both the same now
if ( (!strcasecmp(type, "directory")) && (!strcasecmp(fqdn, host))) {
- found = hostalias_directory;
+ found = hostalias_localhost;
}
if (found) return(found);
}
-
return(hostalias_nomatch);
}
-
/*
* Determine whether a given Internet address belongs to the current user
*/
}
-
-
-
/*
* This function is self explanatory.
* (What can I say, I'm in a weird mood today...)
/*
* Aliasing for network mail.
- * (Error messages have been commented out, because this is a server.)
*/
int alias(char *name)
{ /* process alias and routing info for mail */
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
stripallbut(name, '<', '>');
- fp = fopen(file_mail_aliases, "r");
+ fp = fopen(file_mail_aliases, "r"); // when are we going to get rid of this?
if (fp == NULL) {
fp = fopen("/dev/null", "r");
}
}
fclose(fp);
- /* Hit the Global Address Book */
+ /* Hit the email address directory */
if (CtdlDirectoryLookup(aaa, name, sizeof aaa) == 0) {
strcpy(name, aaa);
}
}
-
/*
* Validate recipients, count delivery types and errors, and handle aliasing
* FIXME check for dupes!!!!!
*
* Caller needs to free the result using free_recipients()
*/
-recptypes *validate_recipients(const char *supplied_recipients,
- const char *RemoteIdentifier,
- int Flags) {
+recptypes *validate_recipients(const char *supplied_recipients, const char *RemoteIdentifier, int Flags)
+{
struct CitContext *CCC = CC;
recptypes *ret;
char *recipients = NULL;
break;
case MES_INTERNET:
/* Yes, you're reading this correctly: if the target
- * domain points back to the local system or an attached
- * Citadel directory, the address is invalid. That's
+ * domain points back to the local system,
+ * the address is invalid. That's
* because if the address were valid, we would have
* already translated it to a local address by now.
*/
EncodedMaxLen = nColons * (sizeof(headerStr) + 3) + SourceLen * 3;
Encoded = (char*) malloc (EncodedMaxLen);
- for (i = 0; i < nColons; i++)
+ for (i = 0; i < nColons; i++) {
source[AddrPtr[i]++] = '\0';
+ }
/* TODO: if libidn, this might get larger*/
user = malloc(SourceLen + 1);
node = malloc(SourceLen + 1);
}
-
/*
* Split an RFC822-style address into userid, host, and full name
*
}
-
/*
* convert_field() is a helper function for convert_internet_message().
* Given start/end positions for an rfc822 field, it converts it to a Citadel
}
-
struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822)
{
struct CtdlMessage *msg;
}
-
/*
* Look for a particular header field in an RFC822 message text. If the
* requested field is found, it is unfolded (if necessary) and returned to
}
-
/*****************************************************************************
* DIRECTORY MANAGEMENT FUNCTIONS *
*****************************************************************************/
}
-/* Return nonzero if the supplied address is in a domain we keep in
- * the directory
+/* Return nonzero if the supplied address is in one of "our" domains
*/
int IsDirectory(char *addr, int allow_masq_domains) {
char domain[256];
if ( (h == hostalias_masq) && allow_masq_domains)
return(1);
- if ( (h == hostalias_localhost) || (h == hostalias_directory) ) {
+ if (h == hostalias_localhost) {
return(1);
}
else {
}
-/*
- * Initialize the directory database (erasing anything already there)
- */
-void CtdlDirectoryInit(void) {
- cdb_trunc(CDB_DIRECTORY);
-}
-
-
/*
* Add an Internet e-mail address to the directory for a user
*/
int CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
char key[SIZ];
- if (IsDirectory(internet_addr, 0) == 0)
+ if (IsDirectory(internet_addr, 0) == 0) {
return 0;
+ }
syslog(LOG_DEBUG, "internet_addressing: create directory entry: %s --> %s", internet_addr, citadel_addr);
directory_key(key, internet_addr);
cdb_store(CDB_DIRECTORY, key, strlen(key), citadel_addr, strlen(citadel_addr)+1 );
utf8ify_rfc822_string(addr);
process_rfc822_addr(addr, user, node, name);
h = CtdlHostAlias(node);
- if ( (h != hostalias_localhost) && (h != hostalias_directory) ) {
+ if (h != hostalias_localhost) {
coll = realloc(coll, strlen(coll) + strlen(addr) + 4);
if (coll == NULL) return(NULL);
if (!IsEmptyStr(coll)) {
}
return(coll);
}
+
+
+/*
+ * Helper function for CtdlRebuildDirectoryIndex()
+ *
+ * Call this function as a ForEachUser backend in order to queue up
+ * user names, or call it with a null user to make it do the processing.
+ * This allows us to maintain the list as a static instead of passing
+ * pointers around.
+ */
+void CtdlRebuildDirectoryIndex_backend(struct ctdluser *usbuf, void *data) {
+
+ struct crdib {
+ char name[64];
+ char emails[512];
+ };
+
+ static struct crdib *e = NULL;
+ static int num_e = 0;
+ static int alloc_e = 0;
+
+ /* this is the calling mode where we add a user */
+
+ if (usbuf != NULL) {
+ if (num_e >= alloc_e) {
+ if (alloc_e == 0) {
+ alloc_e = 100;
+ e = malloc(sizeof(struct crdib) * alloc_e);
+ }
+ else {
+ alloc_e *= 2;
+ e = realloc(e, (sizeof(struct crdib) * alloc_e));
+ }
+ }
+ strcpy(e[num_e].name, usbuf->fullname);
+ strcpy(e[num_e].emails, usbuf->emailaddrs);
+ ++num_e;
+ return;
+ }
+
+ /* this is the calling mode where we do the processing */
+
+ int i, j;
+ for (i=0; i<num_e; ++i) {
+ if ( (!IsEmptyStr(e[i].name)) && (!IsEmptyStr(e[i].emails)) ) {
+ for (j=0; j<num_tokens(e[i].emails, '|'); ++j) {
+ char one_email[512];
+ extract_token(one_email, e[i].emails, j, '|', sizeof one_email);
+ CtdlDirectoryAddUser(one_email, e[i].name);
+ }
+ }
+ }
+ free(e);
+ num_e = 0;
+ alloc_e = 0;
+ return;
+}
+
+
+/*
+ * Initialize the directory database (erasing anything already there)
+ */
+void CtdlRebuildDirectoryIndex(void) {
+ syslog(LOG_INFO, "internet_addressing: rebuilding email address directory index");
+ cdb_trunc(CDB_DIRECTORY);
+ ForEachUser(CtdlRebuildDirectoryIndex_backend, NULL);
+ CtdlRebuildDirectoryIndex_backend(NULL, NULL);
+}