+/*
+ * Backend function for smtp_webcit_preferences_hack().
+ * Look at a message and determine if it's the preferences file.
+ */
+void smtp_webcit_preferences_hack_backend(long msgnum, void *userdata) {
+ struct CtdlMessage *msg;
+ char **webcit_conf = (char **) userdata;
+
+ if (*webcit_conf) {
+ return; // already got it
+ }
+
+ msg = CtdlFetchMessage(msgnum, 1);
+ if (msg == NULL) {
+ return;
+ }
+
+ if ( !CM_IsEmpty(msg, eMsgSubject) &&
+ (!strcasecmp(msg->cm_fields[eMsgSubject], "__ WebCit Preferences __")))
+ {
+ /* This is it! Change ownership of the message text so it doesn't get freed. */
+ *webcit_conf = (char *)msg->cm_fields[eMesageText];
+ msg->cm_fields[eMesageText] = NULL;
+ }
+ CM_Free(msg);
+}
+
+
+/*
+ * The configuration item for the user's preferred display name for outgoing email is, unfortunately,
+ * stored in the account's WebCit configuration. We have to fetch it now.
+ */
+void smtp_webcit_preferences_hack(void) {
+ char config_roomname[ROOMNAMELEN];
+ char *webcit_conf = NULL;
+ citsmtp *sSMTP = SMTP;
+
+ snprintf(config_roomname, sizeof config_roomname, "%010ld.%s", CC->user.usernum, USERCONFIGROOM);
+ if (CtdlGetRoom(&CC->room, config_roomname) != 0) {
+ return;
+ }
+
+ /*
+ * Find the WebCit configuration message
+ */
+
+ CtdlForEachMessage(MSGS_ALL, 1, NULL, NULL, NULL, smtp_webcit_preferences_hack_backend, (void *)&webcit_conf);
+
+ if (!webcit_conf) {
+ return;
+ }
+
+ /* Parse the webcit configuration and attempt to do something useful with it */
+ char *str = webcit_conf;
+ char *saveptr = str;
+ char *this_line = NULL;
+ while (this_line = strtok_r(str, "\n", &saveptr), this_line != NULL) {
+ str = NULL;
+ if (!strncasecmp(this_line, "defaultfrom|", 12)) {
+ sSMTP->preferred_sender_email = NewStrBufPlain(&this_line[12], -1);
+ }
+ if (!strncasecmp(this_line, "defaultname|", 12)) {
+ sSMTP->preferred_sender_name = NewStrBufPlain(&this_line[12], -1);
+ }
+ if ((!strncasecmp(this_line, "defaultname|", 12)) && (sSMTP->preferred_sender_name == NULL)) {
+ sSMTP->preferred_sender_name = NewStrBufPlain(&this_line[12], -1);
+ }
+
+ }
+ free(webcit_conf);
+}
+
+