- if (sc->listrecps != NULL) {
- /* Fetch the message. We're going to need to modify it
- * in order to insert the [list name] in it, etc.
- */
- msg = CtdlFetchMessage(msgnum, 1);
- if (msg != NULL) {
- int rlen;
- char *pCh;
- StrBuf *Subject, *FlatSubject;
-
- if (msg->cm_fields['K'] != NULL)
- free(msg->cm_fields['K']);
- if (msg->cm_fields['V'] == NULL){
- /* local message, no enVelope */
- StrBuf *Buf;
- Buf = NewStrBuf();
- StrBufAppendBufPlain(Buf,
- msg->cm_fields['O']
- , -1, 0);
- StrBufAppendBufPlain(Buf, HKEY("@"), 0);
- StrBufAppendBufPlain(Buf, config.c_fqdn, -1, 0);
-
- msg->cm_fields['K'] = SmashStrBuf(&Buf);
- }
- else {
- msg->cm_fields['K'] =
- strdup (msg->cm_fields['V']);
- }
- /* Set the 'List-ID' header */
- if (msg->cm_fields['L'] != NULL) {
- free(msg->cm_fields['L']);
- }
- msg->cm_fields['L'] = malloc(1024);
- snprintf(msg->cm_fields['L'], 1024,
- "%s <%ld.list-id.%s>",
- CC->room.QRname,
- CC->room.QRnumber,
- config.c_fqdn
- );
-
- /* Prepend "[List name]" to the subject */
- if (msg->cm_fields['U'] == NULL) {
- Subject = NewStrBufPlain(HKEY("(no subject)"));
- }
- else {
- Subject = NewStrBufPlain(
- msg->cm_fields['U'], -1);
- }
- FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
- StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
-
- rlen = strlen(CC->room.QRname);
- pCh = strstr(ChrPtr(FlatSubject), CC->room.QRname);
- if ((pCh == NULL) ||
- (*(pCh + rlen) != ']') ||
- (pCh == ChrPtr(FlatSubject)) ||
- (*(pCh - 1) != '[')
- )
- {
- StrBuf *tmp;
- StrBufPlain(Subject, HKEY("["));
- StrBufAppendBufPlain(Subject,
- CC->room.QRname,
- rlen, 0);
- StrBufAppendBufPlain(Subject, HKEY("] "), 0);
- StrBufAppendBuf(Subject, FlatSubject, 0);
- /* so we can free the right one swap them */
- tmp = Subject;
- Subject = FlatSubject;
- FlatSubject = tmp;
- StrBufRFC2047encode(&Subject, FlatSubject);
- }
-
- if (msg->cm_fields['U'] != NULL)
- free (msg->cm_fields['U']);
- msg->cm_fields['U'] = SmashStrBuf(&Subject);
-
- FreeStrBuf(&FlatSubject);
-
- /* else we won't modify the buffer, since the
- * roomname is already here.
- */
-
- /* if there is no other recipient, Set the recipient
- * of the list message to the email address of the
- * room itself.
- */
- if ((msg->cm_fields['R'] == NULL) ||
- IsEmptyStr(msg->cm_fields['R']))
- {
- if (msg->cm_fields['R'] != NULL)
- free(msg->cm_fields['R']);
-
- msg->cm_fields['R'] = malloc(256);
- snprintf(msg->cm_fields['R'], 256,
- "room_%s@%s", CC->room.QRname,
- config.c_fqdn);
- for (i=0; msg->cm_fields['R'][i]; ++i) {
- if (isspace(msg->cm_fields['R'][i])) {
- msg->cm_fields['R'][i] = '_';
- }
- }
- }
-
- /* Handle delivery */
- network_deliver_list(msg, sc);
- CtdlFreeMessage(msg);
- }
- }