to a memory buffer. This will replace the other two.
* serv_pop3.c: began migration to the new redirect mode.
$Log$
+ Revision 641.10 2005/03/01 22:03:35 ajc
+ * Began implementation of a third RedirectOutput mode -- one which writes
+ to a memory buffer. This will replace the other two.
+ * serv_pop3.c: began migration to the new redirect mode.
+
Revision 641.9 2005/03/01 04:24:52 ajc
* When saving an RFC822 message, use a less expensive algorithm to
search for the Content Type
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
* Back end for pop3_grab_mailbox()
*/
void pop3_add_message(long msgnum, void *userdata) {
- FILE *fp;
struct MetaData smi;
++POP3->num_msgs;
*/
GetMetaData(&smi, POP3->num_msgs-1);
if (smi.meta_rfc822_length <= 0L) {
- fp = tmpfile();
- CtdlRedirectOutput(fp, -1);
+ CC->redirect_buffer = malloc(SIZ);
+ CC->redirect_len = 0;
+ CC->redirect_alloc = SIZ;
CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
- CtdlRedirectOutput(NULL, -1);
- smi.meta_rfc822_length = ftell(fp);
- fclose(fp);
+ smi.meta_rfc822_length = CC->redirect_len;
+ free(CC->redirect_buffer);
+ CC->redirect_buffer = NULL;
+ CC->redirect_len = 0;
+ CC->redirect_alloc = 0;
PutMetaData(&smi);
}
POP3->msgs[POP3->num_msgs-1].rfc822_length = smi.meta_rfc822_length;
/* Redirect this session's output to somewhere else? */
FILE *redirect_fp;
int redirect_sock;
+ char *redirect_buffer; /* the buffer */
+ size_t redirect_len; /* length of data in buffer */
+ size_t redirect_alloc; /* length of allocated buffer */
#ifdef HAVE_OPENSSL
SSL *ssl;
int redirect_ssl;
int old_buffer_len = 0;
#endif
+ if (CC->redirect_buffer != NULL) {
+ if (CC->redirect_len + nbytes >= CC->redirect_alloc) {
+ CC->redirect_alloc = CC->redirect_alloc * 2;
+ CC->redirect_buffer = realloc(CC->redirect_buffer,
+ CC->redirect_alloc);
+ }
+ memcpy(&CC->redirect_buffer[CC->redirect_len], buf, nbytes);
+ CC->redirect_len += nbytes;
+ return;
+ }
+
if (CC->redirect_fp != NULL) {
fwrite(buf, (size_t)nbytes, (size_t)1, CC->redirect_fp);
return;