]> diplodocus.org Git - nmh/commitdiff
Added -browser switch to mhlogin(1).
authorDavid Levine <david.levine@gonift.com>
Fri, 25 Mar 2016 01:25:19 +0000 (21:25 -0400)
committerDavid Levine <david.levine@gonift.com>
Fri, 25 Mar 2016 01:27:21 +0000 (21:27 -0400)
man/mhlogin.man
uip/mhlogin.c

index 083c98aeaf9cb4faf7d4334c25eb969a0f62b65f..32a61ec08768f5ca9b6c18878e374b171d20db31 100644 (file)
@@ -1,7 +1,7 @@
 .\"
 .\" %nmhwarning%
 .\"
-.TH SEND %manext1% "March 23, 2016" "%nmhversion%"
+.TH SEND %manext1% "March 24, 2016" "%nmhversion%"
 .SH NAME
 mhlogin \- login to external (OAuth) services
 .SH SYNOPSIS
@@ -12,6 +12,8 @@ mhlogin \- login to external (OAuth) services
 .IR mechanism ]
 .RB [ \-authservice
 .IR service ]
+.RB [ \-browser
+.IR command ]
 .RB [ \-snoop ]
 .RB [ \-version ]
 .RB [ \-help ]
@@ -32,6 +34,16 @@ switch to
 .BR send .
 .PP
 The
+.B \-browser
+switch causes
+.B mhlogin
+to load the URL directly into a new browser session.  The command argument
+must include the browser invocation name, and can include any browser arguments
+in the
+.B \-browser
+argument string, e.g., 'google-chrome --new-window'.
+.PP
+The
 .B \-snoop
 switch can be used to view the HTTP transaction.
 .PP
@@ -61,3 +73,7 @@ should read them.
 .fi
 .SH "SEE ALSO"
 .IR send (1)
+.SH DEFAULTS
+.nf
+.RB ` \-saslmech "' xoauth2"
+.fi
index e6b791b621a1db274e26e9244ceabf27e62a068d..0c209d9a5e2301af721d89a75927062f79ea0c34 100644 (file)
@@ -15,6 +15,7 @@
 #define MHLOGIN_SWITCHES \
     X("saslmech", 0, SASLMECHSW) \
     X("authservice", 0, AUTHSERVICESW) \
+    X("browser", 0, BROWSERSW) \
     X("snoop", 0, SNOOPSW) \
     X("help", 0, HELPSW) \
     X("version", 0, VERSIONSW) \
@@ -43,7 +44,7 @@ geta (void)
 }
 
 static int
-do_login(const char *svc, int snoop)
+do_login(const char *svc, const char *browser, int snoop)
 {
     char *fn, *code;
     mh_oauth_ctx *ctx;
@@ -70,11 +71,27 @@ do_login(const char *svc, int snoop)
       adios(NULL, mh_oauth_get_err_string(ctx));
     }
 
-    printf("Load the following URL in your browser and authorize nmh"
-           " to access %s:\n"
-           "\n%s\n\n"
-           "Enter the authorization code: ",
-           mh_oauth_svc_display_name(ctx), url);
+    if (browser) {
+        char *command = concat(browser, " '", url, "'", NULL);
+        int status = OK;
+
+        printf("Follow the prompts in your browser to authorize nmh"
+               " to access %s.\n",
+               mh_oauth_svc_display_name(ctx));
+        sleep(1);
+
+        status = system(command);
+        free(command);
+
+        if (status != OK) {
+            adios ((char *) browser, "SYSTEM");
+        }
+    } else {
+        printf("Load the following URL in your browser and authorize nmh"
+               " to access %s:\n\n%s\n\n",
+               mh_oauth_svc_display_name(ctx), url);
+    }
+    printf("Enter the authorization code: ");
     fflush(stdout);
     code = geta();
 
@@ -111,7 +128,7 @@ int
 main(int argc, char **argv)
 {
     char *cp, **argp, **arguments;
-    char *saslmech = NULL, *svc = NULL;
+    const char *saslmech = NULL, *svc = NULL, *browser = NULL;
     int snoop = 0;
 
     if (nmh_init(argv[0], 1)) { return 1; }
@@ -148,6 +165,11 @@ main(int argc, char **argv)
                     adios (NULL, "missing argument to %s", argp[-2]);
                 continue;
 
+           case BROWSERSW:
+                if (!(browser = *argp++) || *browser == '-')
+                    adios (NULL, "missing argument to %s", argp[-2]);
+                continue;
+
             case SNOOPSW:
                 snoop++;
                 continue;
@@ -156,10 +178,16 @@ main(int argc, char **argv)
         adios(NULL, "extraneous arguments");
     }
 
+    if (saslmech  &&  strcasecmp(saslmech, "xoauth2")) {
+        /* xoauth is assumed */
+        adios(NULL, "only -saslmech xoauth2 is supported");
+    }
+
 #ifdef OAUTH_SUPPORT
-    return do_login(svc, snoop);
+    return do_login(svc, browser, snoop);
 #else
     NMH_UNUSED(svc);
+    NMH_UNUSED(browser);
     NMH_UNUSED(snoop);
     adios(NULL, "not built with OAuth support");
     return 1;