*/
msg = CtdlFetchMessage(msgnum, 1);
if (msg != NULL) {
+ int rlen;
+ char *pCh;
+ StrBuf *Subject, *FlatSubject;
+
if (msg->cm_fields['V'] == NULL){
/* local message, no enVelope */
StrBuf *Buf;
/* Prepend "[List name]" to the subject */
if (msg->cm_fields['U'] == NULL) {
- msg->cm_fields['U'] = strdup("(no subject)");
+ 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);
+ tmp = Subject; Subject = FlatSubject; FlatSubject = tmp; /* so we can free the right one... */
+ StrBufRFC2047encode(&Subject, FlatSubject);
}
- snprintf(buf, sizeof buf, "[%s] %s", CC->room.QRname, msg->cm_fields['U']);
- free(msg->cm_fields['U']);
- msg->cm_fields['U'] = strdup(buf);
+
+ 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. */
/* Set the recipient of the list message to the
* email address of the room itself.
* receive network spool from the remote system
*/
void receive_spool(int *sock, char *remote_nodename) {
- long download_len = 0L;
- long bytes_received = 0L;
+ int download_len = 0L;
+ int bytes_received = 0L;
char buf[SIZ];
- static char pbuf[IGNET_PACKET_SIZE];
char tempfilename[PATH_MAX];
char permfilename[PATH_MAX];
- long plen;
+ int plen;
FILE *fp;
snprintf(tempfilename,
if (buf[0] != '2') {
return;
}
+
download_len = extract_long(&buf[4], 0);
+ if (download_len <= 0) {
+ return;
+ }
- if (download_len>0) {
- bytes_received = 0L;
- fp = fopen(tempfilename, "w");
- if (fp == NULL) {
- CtdlLogPrintf(CTDL_CRIT, "cannot open download file locally: %s\n",
- strerror(errno));
+ bytes_received = 0L;
+ fp = fopen(tempfilename, "w");
+ if (fp == NULL) {
+ CtdlLogPrintf(CTDL_CRIT, "Cannot create %s: %s\n", tempfilename, strerror(errno));
+ return;
+ }
+
+ CtdlLogPrintf(CTDL_DEBUG, "Expecting to transfer %d bytes\n", download_len);
+ while (bytes_received < download_len) {
+ /*
+ * If shutting down we can exit here and unlink the temp file.
+ * this shouldn't loose us any messages.
+ */
+ if (CtdlThreadCheckStop())
+ {
+ fclose(fp);
+ unlink(tempfilename);
return;
}
-
- CtdlLogPrintf(CTDL_DEBUG, "For this download we are expecting %d bytes\n", download_len);
- while (bytes_received < download_len) {
- /*
- * If shutting down we can exit here and unlink the temp file.
- * this shouldn't loose us any messages.
- */
- if (CtdlThreadCheckStop())
- {
- fclose(fp);
- unlink(tempfilename);
- return;
- }
- snprintf(buf, sizeof buf, "READ %ld|%ld",
- bytes_received,
- ((download_len - bytes_received > IGNET_PACKET_SIZE)
- ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
-
- if (sock_puts(sock, buf) < 0) {
- fclose(fp);
- unlink(tempfilename);
- return;
- }
- if (sock_getln(sock, buf, sizeof buf) < 0) {
+ snprintf(buf, sizeof buf, "READ %d|%d",
+ bytes_received,
+ ((download_len - bytes_received > IGNET_PACKET_SIZE)
+ ? IGNET_PACKET_SIZE : (download_len - bytes_received))
+ );
+
+ if (sock_puts(sock, buf) < 0) {
+ fclose(fp);
+ unlink(tempfilename);
+ return;
+ }
+ if (sock_getln(sock, buf, sizeof buf) < 0) {
+ fclose(fp);
+ unlink(tempfilename);
+ return;
+ }
+
+ if (buf[0] == '6') {
+ plen = extract_int(&buf[4], 0);
+ StrBuf *pbuf = NewStrBuf();
+ if (socket_read_blob(sock, pbuf, plen, CLIENT_TIMEOUT) != plen) {
+ CtdlLogPrintf(CTDL_INFO, "Short read from peer; aborting.\n");
fclose(fp);
unlink(tempfilename);
+ FreeStrBuf(&pbuf);
return;
}
-
- if (buf[0] == '6') {
- plen = extract_long(&buf[4], 0);
- if (sock_read(sock, pbuf, plen, 1) < 0) {
- fclose(fp);
- unlink(tempfilename);
- return;
- }
- fwrite((char *) pbuf, plen, 1, fp);
- bytes_received = bytes_received + plen;
- }
+ fwrite(ChrPtr(pbuf), plen, 1, fp);
+ bytes_received += plen;
+ FreeStrBuf(&pbuf);
}
-
- fclose(fp);
}
+
+ fclose(fp);
+
/* Last chance for shutdown exit */
if (CtdlThreadCheckStop())
{
unlink(tempfilename);
return;
}
- if (download_len > 0) {
- CtdlLogPrintf(CTDL_NOTICE, "Received %ld octets from <%s>\n", download_len, remote_nodename);
- }
+
CtdlLogPrintf(CTDL_DEBUG, "%s\n", buf);
-
- /* Now move the temp file to its permanent location.
+
+ /*
+ * Now move the temp file to its permanent location.
*/
if (link(tempfilename, permfilename) != 0) {
CtdlLogPrintf(CTDL_ALERT, "Could not link %s to %s: %s\n",
tempfilename, permfilename, strerror(errno)
);
}
+
unlink(tempfilename);
}
"An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
node, CC->cs_host, CC->cs_addr
);
- CtdlLogPrintf(CTDL_WARNING, err_buf);
+ CtdlLogPrintf(CTDL_WARNING, "%s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
CtdlAideMessage(err_buf, "IGNet Networking.");
return;
"A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
CC->cs_host, CC->cs_addr, node
);
- CtdlLogPrintf(CTDL_WARNING, err_buf);
+ CtdlLogPrintf(CTDL_WARNING, "%s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
CtdlAideMessage(err_buf, "IGNet Networking.");
return;