]> diplodocus.org Git - nmh/blobdiff - uip/mhlogin.c
Add basic support for the STLS command in POP
[nmh] / uip / mhlogin.c
index e02ef4655638f075349c2533050657fe70a9893a..5e6d1615c29b058d5bbf9bc297d9a9e882d46f23 100644 (file)
@@ -9,10 +9,17 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <h/mh.h>
+#include "h/mh.h"
+#include "sbr/getarguments.h"
+#include "sbr/concat.h"
+#include "sbr/smatch.h"
+#include "sbr/ambigsw.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/error.h"
 #include "h/done.h"
-#include <h/utils.h>
-#include <h/oauth.h>
+#include "h/utils.h"
+#include "h/oauth.h"
 #include "sbr/lock_file.h"
 
 #define MHLOGIN_SWITCHES \
@@ -57,15 +64,15 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     const char *url;
 
     if (svc == NULL) {
-        adios(NULL, "missing -authservice switch");
+        die("missing -authservice switch");
     }
 
     if (user == NULL) {
-        adios(NULL, "missing -user switch");
+        die("missing -user switch");
     }
 
     if (!mh_oauth_new(&ctx, svc)) {
-        adios(NULL, "%s", mh_oauth_get_err_string(ctx));
+        die("%s", mh_oauth_get_err_string(ctx));
     }
 
     if (snoop) {
@@ -75,7 +82,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     fn = mh_oauth_cred_fn(svc);
 
     if ((url = mh_oauth_get_authorize_url(ctx)) == NULL) {
-      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
+      die("%s", mh_oauth_get_err_string(ctx));
     }
 
     if (browser) {
@@ -98,7 +105,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
                " to access %s:\n\n%s\n\n",
                mh_oauth_svc_display_name(ctx), url);
     }
-    printf("Enter the authorization code: ");
+    fputs("Enter the authorization code: ", stdout);
     fflush(stdout);
     code = geta();
 
@@ -111,7 +118,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     }
     if (cred == NULL) {
       inform("error exchanging code for OAuth2 token");
-      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
+      die("%s", mh_oauth_get_err_string(ctx));
     }
 
     cred_file = lkfopendata(fn, "r+", &failed_to_lock);
@@ -122,7 +129,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
       adios(fn, "oops");
     }
     if (!mh_oauth_cred_save(cred_file, cred, user)) {
-      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
+      die("%s", mh_oauth_get_err_string(ctx));
     }
     if (lkfclosedata(cred_file, fn) != 0) {
       adios (fn, "oops");
@@ -143,7 +150,7 @@ main(int argc, char **argv)
     const char *user = NULL, *saslmech = NULL, *svc = NULL, *browser = NULL;
     int snoop = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], true, true)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -156,7 +163,7 @@ main(int argc, char **argv)
                ambigsw (cp, switches);
                done (1);
            case UNKWNSW:
-               adios (NULL, "-%s unknown", cp);
+               die("-%s unknown", cp);
 
            case HELPSW:
                snprintf(help, sizeof(help), "%s [switches]",
@@ -169,22 +176,22 @@ main(int argc, char **argv)
 
            case USERSW:
                if (!(user = *argp++) || *user == '-')
-                   adios (NULL, "missing argument to %s", argp[-2]);
+                   die("missing argument to %s", argp[-2]);
                continue;
 
            case SASLMECHSW:
                if (!(saslmech = *argp++) || *saslmech == '-')
-                   adios (NULL, "missing argument to %s", argp[-2]);
+                   die("missing argument to %s", argp[-2]);
                continue;
 
            case AUTHSERVICESW:
                 if (!(svc = *argp++) || *svc == '-')
-                    adios (NULL, "missing argument to %s", argp[-2]);
+                    die("missing argument to %s", argp[-2]);
                 continue;
 
            case BROWSERSW:
                 if (!(browser = *argp++) || *browser == '-')
-                    adios (NULL, "missing argument to %s", argp[-2]);
+                    die("missing argument to %s", argp[-2]);
                 continue;
 
             case SNOOPSW:
@@ -192,12 +199,12 @@ main(int argc, char **argv)
                 continue;
            }
        }
-        adios(NULL, "extraneous arguments");
+        die("extraneous arguments");
     }
 
     if (saslmech  &&  strcasecmp(saslmech, "xoauth2")) {
         /* xoauth is assumed */
-        adios(NULL, "only -saslmech xoauth2 is supported");
+        die("only -saslmech xoauth2 is supported");
     }
     free(arguments);
 
@@ -207,7 +214,7 @@ main(int argc, char **argv)
     NMH_UNUSED(svc);
     NMH_UNUSED(browser);
     NMH_UNUSED(snoop);
-    adios(NULL, "not built with OAuth support");
+    die("not built with OAuth support");
     return 1;
 #endif
 }