]> diplodocus.org Git - nmh/blobdiff - uip/sendsbr.c
fdcompare.c: Move interface to own file.
[nmh] / uip / sendsbr.c
index 0af6f63a3fe72c8b2e8026369e002a3c061930f7..ab4f73ce7c27ccecefb744a1c4852404c9ff1564 100644 (file)
@@ -5,16 +5,23 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/fmt_scan.h>
-#include <h/fmt_compile.h>
-#include <h/signals.h>
+#include "h/mh.h"
+#include "sbr/folder_read.h"
+#include "sbr/folder_free.h"
+#include "sbr/context_find.h"
+#include "sbr/brkstring.h"
+#include "sbr/pidstatus.h"
+#include "sbr/arglist.h"
+#include "sbr/error.h"
+#include "h/fmt_scan.h"
+#include "h/fmt_compile.h"
+#include "h/signals.h"
 #include <setjmp.h>
 #include <fcntl.h>
-#include <h/mime.h>
-#include <h/tws.h>
-#include <h/utils.h>
-#include <h/mts.h>
+#include "h/mime.h"
+#include "h/tws.h"
+#include "h/utils.h"
+#include "h/mts.h"
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -22,8 +29,9 @@
 #include <time.h>
 
 #ifdef OAUTH_SUPPORT
-#include <h/oauth.h>
+#include "h/oauth.h"
 #endif
+#include "h/done.h"
 #include "sbr/m_maildir.h"
 #include "sbr/m_mktemp.h"
 #include "sbr/message_id.h"
@@ -33,12 +41,12 @@ static int setup_oauth_params(char *[], int *, const char *, const char **);
 #endif /* OAUTH_SUPPORT */
 
 int debugsw = 0;               /* global */
-int forwsw  = 1;
+bool forwsw = true;
 int inplace = 1;
-int pushsw  = 0;
+bool pushsw;
 int splitsw = -1;
-int unique  = 0;
-int verbsw  = 0;
+bool unique;
+bool verbsw;
 
 char *altmsg   = NULL;         /*  .. */
 char *annotext = NULL;
@@ -100,7 +108,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
        execvp(buildprogram, buildvec);
        fprintf(stderr, "unable to exec ");
        perror(buildmimeproc);
-       _exit(-1);
+       _exit(1);
        break;
 
     default:
@@ -109,7 +117,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
        break;
     }
 
-    done=armed_done;
+    set_done(armed_done);
     switch (setjmp (env)) {
     case OK:
        /*
@@ -119,8 +127,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
        if (pushsw && unique) {
            char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
            if (cp == NULL) {
-               adios(NULL, "unable to create temporary file in %s",
-                     get_temp_dir());
+               die("unable to create temporary file");
            }
            if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
@@ -135,10 +142,10 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
 #ifdef OAUTH_SUPPORT
                const char *errmsg;
                if (setup_oauth_params(vec, nvecsp, auth_svc, &errmsg) != OK) {
-                        adios(NULL, "%s", errmsg);
+                        die("%s", errmsg);
                }
 #else
-                adios(NULL, "send built without OAUTH_SUPPORT, "
+                die("send built without OAUTH_SUPPORT, "
                       "so auth_svc %s is not supported", auth_svc);
 #endif /* OAUTH_SUPPORT */
        }
@@ -175,7 +182,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
        break;
     }
 
-    done=exit;
+    set_done(exit);
     if (distfile)
        (void) m_unlink (distfile);
 
@@ -276,17 +283,17 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
           case LENERR:
           case FMTERR:
-               adios (NULL, "message format error in component #%d", compnum);
+               die("message format error in component #%d", compnum);
 
           default:
-               adios (NULL, "getfld () returned %d", state);
+               die("getfld () returned %d", state);
        }
 
        break;
     }
     m_getfld_state_destroy (&gstate);
     if (cp == NULL)
-       adios (NULL, "headers missing from draft");
+       die("headers missing from draft");
 
     nparts = 1;
     pos = start;
@@ -329,8 +336,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
        char *cp = m_mktemp2(drft, invo_name, NULL, &out);
         if (cp == NULL) {
-           adios(NULL, "unable to create temporary file in %s",
-                 get_temp_dir());
+           die("unable to create temporary file");
         }
        strncpy(tmpdrf, cp, sizeof(tmpdrf));
 
@@ -363,7 +369,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
            if (!fgets (buffer, sizeof buffer, in)) {
                if (partno == nparts)
                    break;
-               adios (NULL, "premature eof");
+               die("premature eof");
            }
 
            if ((pos += (len = strlen (buffer))) > CPERMSG) {
@@ -467,7 +473,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
        execvp (program, vec);
        fprintf (stderr, "unable to exec ");
        perror (postproc);
-       _exit (-1);
+       _exit(1);
 
     default:
        /*
@@ -570,7 +576,7 @@ alert (char *file, int out)
            execvp (program, arglist);
            fprintf (stderr, "unable to exec ");
            perror (mailproc);
-           _exit (-1);
+           _exit(1);
 
        default:                /* no waiting... */
            break;
@@ -739,9 +745,9 @@ oops:
 }
 
 
-static
-void
-handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
+static void
+handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc)
+{
     const char *addr, *host;
     const char *message;
 
@@ -764,12 +770,12 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
             if (strcmp(*vp, "xoauth2") == 0) {
 #ifdef OAUTH_SUPPORT
                 if (setup_oauth_params(vec, vecp, auth_svc, &message) != OK) {
-                    adios(NULL, "%s", message);
+                    die("%s", message);
                 }
                 break;
 #else
                 NMH_UNUSED(auth_svc);
-                adios(NULL, "send built without OAUTH_SUPPORT, "
+                die("send built without OAUTH_SUPPORT, "
                       "so -saslmech xoauth2 is not supported");
 #endif /* OAUTH_SUPPORT */
             }
@@ -784,7 +790,8 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
  */
 static int
 setup_oauth_params(char *vec[], int *vecp, const char *auth_svc,
-                  const char **message) {
+                  const char **message)
+{
     const char *saslmech = NULL, *user = NULL;
     mh_oauth_service_info svc;
     char errbuf[256];
@@ -817,13 +824,13 @@ setup_oauth_params(char *vec[], int *vecp, const char *auth_svc,
         if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
            if (! mh_oauth_get_service_info(auth_svc, &svc, errbuf,
                                            sizeof(errbuf)))
-               adios(NULL, "Unable to retrieve oauth profile entries: %s",
+               die("Unable to retrieve oauth profile entries: %s",
                      errbuf);
 
            vec[(*vecp)++] = mh_xstrdup("-authservice");
            vec[(*vecp)++] = mh_xstrdup(auth_svc);
            vec[(*vecp)++] = mh_xstrdup("-oauthcredfile");
-           vec[(*vecp)++] = mh_xstrdup(mh_oauth_cred_fn(auth_svc));
+           vec[(*vecp)++] = mh_oauth_cred_fn(auth_svc);
            vec[(*vecp)++] = mh_xstrdup("-oauthclientid");
            vec[(*vecp)++] = getcpy(svc.client_id);
            vec[(*vecp)++] = mh_xstrdup("-oauthclientsecret");
@@ -847,9 +854,9 @@ setup_oauth_params(char *vec[], int *vecp, const char *auth_svc,
 /*
  * Extract user and domain from From: header line in draft.
  */
-static
-int
-get_from_header_info(const char *filename, const char **addr, const char **host, const char **message) {
+static int
+get_from_header_info(const char *filename, const char **addr, const char **host, const char **message)
+{
     struct stat st;
     FILE *in;
 
@@ -901,13 +908,13 @@ get_from_header_info(const char *filename, const char **addr, const char **host,
  * Get formatted information from header of a message.
  * Adapted from process_single_file() in uip/fmttest.c.
  */
-static
-const char *
-get_message_header_info(FILE *in, char *format) {
+static const char *
+get_message_header_info(FILE *in, char *format)
+{
     int dat[5];
     struct format *fmt;
     struct stat st;
-    int parsing_header;
+    bool parsing_header;
     m_getfld_state_t gstate;
     charstring_t buffer = charstring_create(0);
     char *retval;
@@ -923,7 +930,7 @@ get_message_header_info(FILE *in, char *format) {
      * Read in the message and process the header.
      */
     rewind (in);
-    parsing_header = 1;
+    parsing_header = true;
     gstate = m_getfld_state_init(in);
     do {
         char name[NAMESZ], rbuf[NMH_BUFSIZ];
@@ -950,7 +957,7 @@ get_message_header_info(FILE *in, char *format) {
             break;
         }
         default:
-            parsing_header = 0;
+            parsing_header = false;
         }
     } while (parsing_header);
     m_getfld_state_destroy(&gstate);
@@ -979,9 +986,9 @@ get_message_header_info(FILE *in, char *format) {
  * If no -server passed in from profile or commandline, could use smtp.<svc>.com for gmail,
  * but that might not generalize for other svcs.
  */
-static
-void
-merge_profile_entry(const char *addr, const char *host, char *vec[], int *vecp) {
+static void
+merge_profile_entry(const char *addr, const char *host, char *vec[], int *vecp)
+{
     char *addr_entry = concat("sendfrom-", addr, NULL);
     char *profile_entry = context_find(addr_entry);