+/*
+ * This handler detects whether the user is attempting to save a new
+ * vCard as part of his/her personal configuration, and handles the replace
+ * function accordingly (copy the vCard from the config room to the global
+ * address book).
+ */
+int vcard_upload_aftersave(struct CtdlMessage *msg) {
+ char *ptr;
+ int linelen;
+ long msgid;
+ struct quickroom qrbuf;
+
+ /* If this isn't the configuration room, or if this isn't a MIME
+ * message, don't bother.
+ */
+ if (strcasecmp(msg->cm_fields['O'], CONFIGROOM)) return(0);
+ if (msg->cm_format_type != 4) return(0);
+
+ ptr = msg->cm_fields['M'];
+ while (ptr != NULL) {
+
+ linelen = strcspn(ptr, "\n");
+ if (linelen == 0) return(0); /* end of headers */
+
+ if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
+ /* Bingo! The user is uploading a new vCard, so
+ * delete the old one.
+ */
+
+ msgid = atol(msg->cm_fields['I']);
+ if (msgid < 0L) return(0);
+
+ if (getroom(&qrbuf, ADDRESS_BOOK_ROOM) != 0) return(0);
+ AddMessageToRoom(&qrbuf, msgid);
+ AdjRefCount(msgid, +1);
+
+ return(0);
+ }
+
+ ptr = strchr((char *)ptr, '\n');
+ if (ptr != NULL) ++ptr;
+ }
+
+ return(0);
+}
+
+
+