* the POP3 server.
*/
void pop3_cleanup_function(void) {
- int i;
/* Don't do this stuff if this is not a POP3 session! */
if (CC->h_command_function != pop3_command_loop) return;
lprintf(CTDL_DEBUG, "Performing POP3 cleanup hook\n");
-
- if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
- if (POP3->msgs[i].temp != NULL) {
- fclose(POP3->msgs[i].temp);
- POP3->msgs[i].temp = NULL;
- }
- }
if (POP3->msgs != NULL) free(POP3->msgs);
-
- lprintf(CTDL_DEBUG, "Finished POP3 cleanup hook\n");
}
void pop3_add_message(long msgnum, void *userdata) {
FILE *fp;
lprintf(CTDL_DEBUG, "in pop3_add_message()\n");
+ struct MetaData smi;
++POP3->num_msgs;
if (POP3->num_msgs < 2) POP3->msgs = malloc(sizeof(struct pop3msg));
(POP3->num_msgs * sizeof(struct pop3msg)) ) ;
POP3->msgs[POP3->num_msgs-1].msgnum = msgnum;
POP3->msgs[POP3->num_msgs-1].deleted = 0;
- fp = tmpfile();
- POP3->msgs[POP3->num_msgs-1].temp = fp;
-
- CtdlRedirectOutput(fp, -1);
- CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
- CtdlRedirectOutput(NULL, -1);
- POP3->msgs[POP3->num_msgs-1].rfc822_length = ftell(fp);
+ /* We need to know the length of this message when it is printed in
+ * RFC822 format. Perhaps we have cached this length in the message's
+ * metadata record. If so, great; if not, measure it and then cache
+ * it for next time.
+ */
+ GetMetaData(&smi, POP3->num_msgs-1);
+ if (smi.meta_rfc822_length <= 0L) {
+ fp = tmpfile();
+ CtdlRedirectOutput(fp, -1);
+ CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
+ CtdlRedirectOutput(NULL, -1);
+ smi.meta_rfc822_length = ftell(fp);
+ fclose(fp);
+ PutMetaData(&smi);
+ }
+ POP3->msgs[POP3->num_msgs-1].rfc822_length = smi.meta_rfc822_length;
}
*/
void pop3_retr(char *argbuf) {
int which_one;
- int ch = 0;
- size_t bytes_remaining;
which_one = atoi(argbuf);
if ( (which_one < 1) || (which_one > POP3->num_msgs) ) {
}
cprintf("+OK Message %d:\r\n", which_one);
- bytes_remaining = POP3->msgs[which_one -1].rfc822_length;
- rewind(POP3->msgs[which_one - 1].temp);
- while (bytes_remaining-- > 0) {
- ch = getc(POP3->msgs[which_one - 1].temp);
- cprintf("%c", ch);
- }
- if (ch != 10) {
- lprintf(CTDL_WARNING, "Problem: message ends with 0x%2x, not 0x0a\n", ch);
- }
+ CtdlOutputMsg(POP3->msgs[which_one - 1].msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
cprintf(".\r\n");
}
char *ptr;
int in_body = 0;
int done = 0;
+ FILE *fp;
sscanf(argbuf, "%d %d", &which_one, &lines_requested);
if ( (which_one < 1) || (which_one > POP3->num_msgs) ) {
return;
}
+ fp = tmpfile();
+ if (fp == NULL) {
+ cprintf("-ERR Internal error: could not create temp file\r\n");
+ return;
+ }
+ CtdlRedirectOutput(fp, -1);
+ CtdlOutputMsg(POP3->msgs[which_one - 1].msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
+ CtdlRedirectOutput(NULL, -1);
+
cprintf("+OK Message %d:\r\n", which_one);
- rewind(POP3->msgs[which_one - 1].temp);
- while (ptr = fgets(buf, sizeof buf, POP3->msgs[which_one - 1].temp),
+ rewind(fp);
+ while (ptr = fgets(buf, sizeof buf, fp),
( (ptr!=NULL) && (done == 0))) {
if (in_body == 1)
if (lines_dumped >= lines_requested) done = 1;
if ((buf[0]==13)||(buf[0]==10)) in_body = 1;
}
if (buf[strlen(buf)-1] != 10) cprintf("\n");
+ fclose(fp);
cprintf(".\r\n");
}
/* Supplementary data for a message on disk
- * (These are kept separately from the message itself because they are
- * fields whose values may change at some point after the message is saved.)
+ * These are kept separate from the message itself for one of two reasons:
+ * 1. Either their values may change at some point after initial save, or
+ * 2. They are merely caches of data which exist somewhere else, for speed.
*/
struct MetaData {
- long meta_msgnum; /* Message number in *local* message base */
- int meta_refcount; /* Number of rooms which point to this msg */
- char meta_content_type[64];
- /* more stuff will be added to this record in the future */
+ long meta_msgnum; /* Message number in *local* message base */
+ int meta_refcount; /* Number of rooms pointing to this msg */
+ char meta_content_type[64]; /* Cached MIME content-type */
+ long meta_rfc822_length; /* Cache of RFC822-translated msg length */
};