]> mj.ucw.cz Git - umpf.git/blobdiff - int.c
fix saving bodies
[umpf.git] / int.c
diff --git a/int.c b/int.c
index 521564030369833215e958c7370e3ba5f3e8dc6b..e1c906f058342ada6c8d264876d5f4fcc48bed35 100644 (file)
--- a/int.c
+++ b/int.c
@@ -7,6 +7,7 @@
 #include <fcntl.h>
 #include <stdarg.h>
 #include <sys/wait.h>
+#include <sysexits.h>
 
 #include "cond.tab.h"
 #include "umpf.h"
@@ -17,7 +18,7 @@
 
 #define INT_TO_STRING_LEN ((sizeof(int)*4*CHAR_BIT)/10 + 6)
 
-static void __attribute__ ((noreturn)) 
+void __attribute__ ((noreturn)) 
 bye(int code, char* msg, ...)
 {
         va_list args;
@@ -161,24 +162,58 @@ fold(const char* value, int taken)
        return ret;
 }
 
+static char*
+unfold(const char* u)
+{
+       char* new;
+       const char* pu = u; 
+       char* pn;
+
+       new = xmalloc(strlen(u)+1);
+       pn = new;
+
+#define IS_WHITE(c) ((c) == '\t' || (c)==' ' || c=='\n')
+
+       while (IS_WHITE(*pu))
+               pu++;
+
+       while (*pu != 0){
+               if (IS_WHITE(*pu)){
+                       while (IS_WHITE(*pu))
+                               pu++;
+                       if (*pu != 0)
+                               *pn++ = ' ';
+               } else
+                       *pn++ = *pu++;          
+       }
+       *pn = 0;
+
+       return new;
+}
+
 static void
 modify_headers(struct list* headers, struct list* hash)
 {
        struct hlist* p;
        int i;
        struct variable* pv;
+       char* u, * value;
        
 
        LIST_FOREACH(p, headers){
                pv = get_var_struct(p->name, hash);
                if (!pv)
                        continue;
-               if (pv->modified){
+               u = unfold(p->value);
+               value = get_var(pv->varcode);
+               if (strcmp(u, value)){
                        pv->modified = 0;
                        free_string(p->value);
-                       p->value = fold(get_var(pv->varcode),
+                       p->value = fold(value,
                                 strlen(p->name) + 2);
                }
+               free_string(u);
+               free_string(value);
        }
 
        // find new headers 
@@ -357,7 +392,7 @@ deliver(char* where, int copy, struct list* hash)
 
        if (!copy) {
                if (res)
-                       bye(-res, "%m");
+                       bye(EX_TEMPFAIL, "%m");
                else
                        bye(0, NULL);
        }
@@ -371,7 +406,6 @@ send_mail(char* where, int copy, struct list* hash)
        int res;
        struct email em = prepare_email(hash);
 
-       //write_email_to_fd(1, &em); 
        res = pipe(pd);
        if (res < 0)
                goto end;
@@ -393,7 +427,7 @@ end:
        destroy_email(em);
        if (!copy) {
                if (res)
-                       bye(-res, "%m");
+                       bye(EX_TEMPFAIL, "%m");
                else
                        bye(0, NULL);
        }
@@ -484,35 +518,6 @@ print_vars(struct list* hash)
        }
 }
 
-static char*
-unfold(const char* u)
-{
-       char* new;
-       const char* pu = u; 
-       char* pn;
-
-       new = xmalloc(strlen(u)+1);
-       pn = new;
-
-#define IS_WHITE(c) ((c) == '\t' || (c)==' ' || c=='\n')
-
-       while (IS_WHITE(*pu))
-               pu++;
-
-       while (*pu != 0){
-               if (IS_WHITE(*pu)){
-                       while (IS_WHITE(*pu))
-                               pu++;
-                       if (*pu != 0)
-                               *pn++ = ' ';
-               } else
-                       *pn++ = *pu++;          
-       }
-       *pn = 0;
-
-       return new;
-}
-
 void
 save_current_headers(struct list* hash)
 {
@@ -524,13 +529,10 @@ save_current_headers(struct list* hash)
                pv = get_var_struct(p->name, hash);
                if (!pv)
                        continue;
-               if (!get_var(pv->varcode))
-                       continue;
                u = unfold(p->value);
                set_var(pv->varcode, u);
-               set_var(pv->varcode, p->value);
+               free_string(u);
                pv->modified = 0;
                p->have_var = 1;
        }
-
 }