+void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char *RoomName);
+
+void aggregate_recipients(StrBuf **recps, RoomNetCfg Which, OneRoomNetCfg *OneRNCfg, long nSegments)
+{
+ int i;
+ size_t recps_len = 0;
+ RoomNetCfgLine *nptr;
+ struct CitContext *CCC = CC;
+
+ *recps = NULL;
+ /*
+ * Figure out how big a buffer we need to allocate
+ */
+ for (nptr = OneRNCfg->NetConfigs[Which]; nptr != NULL; nptr = nptr->next) {
+ recps_len = recps_len + StrLength(nptr->Value[0]) + 2;
+ }
+
+ /* Nothing todo... */
+ if (recps_len == 0)
+ return;
+
+ *recps = NewStrBufPlain(NULL, recps_len);
+
+ if (*recps == NULL) {
+ QN_syslog(LOG_EMERG,
+ "Cannot allocate %ld bytes for recps...\n",
+ (long)recps_len);
+ abort();
+ }
+
+ /* Each recipient */
+ for (nptr = OneRNCfg->NetConfigs[Which]; nptr != NULL; nptr = nptr->next) {
+ if (nptr != OneRNCfg->NetConfigs[Which]) {
+ for (i = 0; i < nSegments; i++)
+ StrBufAppendBufPlain(*recps, HKEY(","), i);
+ }
+ StrBufAppendBuf(*recps, nptr->Value[0], 0);
+ }
+}
+
+static void ListCalculateSubject(struct CtdlMessage *msg)
+{
+ struct CitContext *CCC = CC;
+ StrBuf *Subject, *FlatSubject;
+ int rlen;
+ char *pCh;
+
+ 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(CCC->room.QRname);
+ pCh = strstr(ChrPtr(FlatSubject), CCC->room.QRname);
+ if ((pCh == NULL) ||
+ (*(pCh + rlen) != ']') ||
+ (pCh == ChrPtr(FlatSubject)) ||
+ (*(pCh - 1) != '[')
+ )
+ {
+ StrBuf *tmp;
+ StrBufPlain(Subject, HKEY("["));
+ StrBufAppendBufPlain(Subject,
+ CCC->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);
+}