#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
+#include <stdarg.h>
#include "cond.tab.h"
#include "umpf.h"
#define INT_TO_STRING_LEN ((sizeof(int)*4*CHAR_BIT)/10 + 6)
+static void __attribute__ ((noreturn))
+bye(int code, char* msg, ...)
+{
+ va_list args;
+
+ if (current_body->tmpfile)
+ unlink(current_body->tmpfile);
+
+ if (msg) {
+ va_start(args, msg);
+ vfprintf(stderr, msg, args);
+ fputc('\n', stderr);
+ va_end(args);
+ }
+ exit(code);
+}
+
static void
clear_var(int var)
{
modify_headers(current_headers, hash);
em.headers = copy_headers(current_headers);
- em.body_len = current_body->body_len;
- em.body = xmalloc(em.body_len);
- memcpy(em.body, current_body->body, em.body_len);
+ em.body_len = current_body->body_len;
+ em.fd = current_body->fd;
+ if (current_body->body) {
+ em.body = xmalloc(em.body_len);
+ memcpy(em.body, current_body->body, em.body_len);
+ em.tmpfile = NULL;
+ } else {
+ em.tmpfile = xstrdup(current_body->tmpfile);
+ em.body = NULL;
+ }
return em;
}
+static void
+destroy_email(struct email em)
+{
+ if (em.body)
+ free(em.body);
+ if(em.tmpfile)
+ free(em.tmpfile);
+}
+
static void
do_string_ternary_op(struct code* p)
{
res = deliver_local_email(where, &em);
- if (!copy)
- exit(-res);
+ destroy_email(em);
+
+ if (!copy) {
+ if (res)
+ bye(-res, "%m");
+ else
+ bye(0, NULL);
+ }
}
void
case OPC_CALL_EXT:
break;
case OPC_DISCARD:
- exit(0);
+ bye(0, NULL);
break;
}}
deliver(default_mailbox, 0, hash);