- struct MD5Context md5context;
- u_char rawdigest[MD5_DIGEST_LEN];
- struct CtdlMessage *msg;
- int msglen = 0;
- StrBuf *Message;
- StrBuf *guid;
- AsyncIO *IO = &Cfg->IO;
-
- int n;
-
- /* Construct a GUID to use in the S_USETABLE table.
- * If one is not present in the item itself, make one up.
- */
- if (ri->guid != NULL) {
- StrBufSpaceToBlank(ri->guid);
- StrBufTrim(ri->guid);
- guid = NewStrBufPlain(HKEY("rss/"));
- StrBufAppendBuf(guid, ri->guid, 0);
- }
- else {
- MD5Init(&md5context);
- if (ri->title != NULL) {
- MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->title), StrLength(ri->title));
- }
- if (ri->link != NULL) {
- MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->link), StrLength(ri->link));
- }
- MD5Final(rawdigest, &md5context);
- guid = NewStrBufPlain(NULL, MD5_DIGEST_LEN * 2 + 12 /* _rss2ctdl*/);
- StrBufHexEscAppend(guid, NULL, rawdigest, MD5_DIGEST_LEN);
- StrBufAppendBufPlain(guid, HKEY("_rss2ctdl"), 0);
- }
-
- /* translate Item into message. */
- EVM_syslog(LOG_DEBUG, "RSS: translating item...\n");
- if (ri->description == NULL) ri->description = NewStrBufPlain(HKEY(""));
- StrBufSpaceToBlank(ri->description);
- msg = malloc(sizeof(struct CtdlMessage));
- memset(msg, 0, sizeof(struct CtdlMessage));
- msg->cm_magic = CTDLMESSAGE_MAGIC;
- msg->cm_anon_type = MES_NORMAL;
- msg->cm_format_type = FMT_RFC822;
-
- if (ri->guid != NULL) {
- msg->cm_fields['E'] = strdup(ChrPtr(ri->guid));
- }
-
- if (ri->author_or_creator != NULL) {
- char *From;
- StrBuf *Encoded = NULL;
- int FromAt;
-
- From = html_to_ascii(ChrPtr(ri->author_or_creator),
- StrLength(ri->author_or_creator),
- 512, 0);
- StrBufPlain(ri->author_or_creator, From, -1);
- StrBufTrim(ri->author_or_creator);
- free(From);
-
- FromAt = strchr(ChrPtr(ri->author_or_creator), '@') != NULL;
- if (!FromAt && StrLength (ri->author_email) > 0)
- {
- StrBufRFC2047encode(&Encoded, ri->author_or_creator);
- msg->cm_fields['A'] = SmashStrBuf(&Encoded);
- msg->cm_fields['P'] = SmashStrBuf(&ri->author_email);
- }
- else
- {
- if (FromAt)
- {
- msg->cm_fields['A'] = SmashStrBuf(&ri->author_or_creator);
- msg->cm_fields['P'] = strdup(msg->cm_fields['A']);
- }
- else
- {
- StrBufRFC2047encode(&Encoded, ri->author_or_creator);
- msg->cm_fields['A'] = SmashStrBuf(&Encoded);
- msg->cm_fields['P'] = strdup("rss@localhost");