]> diplodocus.org Git - nmh/commitdiff
Replaced -oauth service switch with -saslmech xoauth2
authorDavid Levine <david.levine@gonift.com>
Thu, 24 Mar 2016 00:25:32 +0000 (20:25 -0400)
committerDavid Levine <david.levine@gonift.com>
Thu, 24 Mar 2016 00:29:05 +0000 (20:29 -0400)
-authservice service, because OAUTH2 is a SASL mechanism.

16 files changed:
Makefile.am
man/inc.man
man/mhlogin.man
man/msgchk.man
man/send.man
sbr/oauth.c
test/oauth/common.sh
test/oauth/test-mhlogin
test/oauth/test-send
test/oauth/test-share
uip/inc.c
uip/mhlogin.c
uip/msgchk.c
uip/post.c
uip/send.c
uip/whatnowsbr.c

index 0d37d5e..91e4d93 100644 (file)
@@ -87,7 +87,7 @@ TESTS = test/ali/test-ali test/anno/test-anno \
        test/mhshow/test-subpart test/mhshow/test-msg-buffer-boundaries \
        test/mhstore/test-mhstore test/mkstemp/test-mkstemp \
        test/new/test-basic test/pick/test-pick test/pick/test-stderr \
-       test/oauth/test-mhlogin test/oauth/test-send \
+       test/oauth/test-mhlogin test/oauth/test-mhparam test/oauth/test-send \
        test/oauth/test-inc test/oauth/test-share \
        test/post/test-post-aliases test/post/test-post-basic \
        test/post/test-post-multiple test/post/test-post-bcc \
index f72b1f2..e866bfa 100644 (file)
@@ -1,4 +1,4 @@
-.TH INC %manext1% "November 25, 2014" "%nmhversion%"
+.TH INC %manext1% "March 23, 2016" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
@@ -37,7 +37,7 @@ inc \- incorporate new mail
 .RB [ \-sasl " | " \-nosasl ]
 .RB [ \-saslmech
 .IR mechanism ]
-.RB [ \-oauth
+.RB [ \-authservice
 .IR service ]
 .RB [ \-snoop ]
 .RB [ \-version ]
@@ -245,7 +245,7 @@ For debugging purposes, you may give the switch
 .BR \-snoop ,
 which will allow you to watch the POP transaction take place
 between you and the POP server.  If
-.B \-oauth
+.B \-saslmech xoauth2
 is used, the HTTP transaction is also shown.
 .PP
 If
@@ -272,18 +272,18 @@ switch.
 If
 .B nmh
 has been compiled with OAuth support, the
-.B \-oauth
+.B \-saslmech xoauth2
 switch will enable OAuth authentication.  The
 .B \-user
 switch must be used, and the
 .I user-name
-must be an email address the user has for that service.  Before using this,
-the user must authorize nmh by running
+must be an email address the user has for the service, which must
+be specified with the
+.B \-authservice
+.I service
+switch.  Before using this, the user must authorize nmh by running
 .B mhlogin
-and grant authorization to that account.  Only
-.B -oauth
-.I gmail
-is supported.  See the
+and grant authorization to that account.  See the
 .B mhlogin
 man page for more details.
 .PP
index 0651fdc..083c98a 100644 (file)
@@ -1,15 +1,17 @@
 .\"
 .\" %nmhwarning%
 .\"
-.TH SEND %manext1% "November 25, 2014" "%nmhversion%"
+.TH SEND %manext1% "March 23, 2016" "%nmhversion%"
 .SH NAME
 mhlogin \- login to external (OAuth) services
 .SH SYNOPSIS
 .HP 5
 .na
 .B mhlogin
-.RB \-oauth
-.IR service
+.RB [ \-saslmech
+.IR mechanism ]
+.RB [ \-authservice
+.IR service ]
 .RB [ \-snoop ]
 .RB [ \-version ]
 .RB [ \-help ]
@@ -18,7 +20,8 @@ mhlogin \- login to external (OAuth) services
 .B Mhlogin
 currently only supports OAuth for Gmail.  Run
 .B mhlogin
-.B -oauth
+.B \-saslmech xoauth2
+.B \-authservice
 .I gmail
 and load the printed URL in your browser.  Login to a Gmail account, grant
 authorization, and copy and paste the code into the
@@ -26,7 +29,7 @@ authorization, and copy and paste the code into the
 prompt.  Be sure to use the same account with the
 .B -user
 switch to
-.B send
+.BR send .
 .PP
 The
 .B \-snoop
@@ -35,11 +38,8 @@ switch can be used to view the HTTP transaction.
 All parameters configuring the service may be overridden by profile components,
 and even though only Gmail is supported out of the box, the user can define
 new services entirely in the profile.  Profile components are prefixed by
-.I
-oauth-
-.I
-service-
-for example
+.IR oauth-service- ,
+for example,
 .I oauth-gmail-credential-file
 which specifies where
 .B mhlogin
index 5b02c52..45ac872 100644 (file)
@@ -1,4 +1,4 @@
-.TH MSGCHK %manext1% "November 25, 2014" "%nmhversion%"
+.TH MSGCHK %manext1% "March 23, 2016" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
@@ -20,7 +20,7 @@ all/mail/nomail ]
 .RB [ \-sasl ]
 .RB [ \-saslmech
 .IR mechanism ]
-.RB [ \-oauth
+.RB [ \-authservice
 .IR service ]
 .RB [ \-snoop ]
 .RI [ users
@@ -100,7 +100,7 @@ For debugging purposes, there is also a switch
 which will
 allow you to watch the POP transaction take place between you and the
 POP server.  If
-.B \-oauth
+.B \-saslmech xoauth2
 is used, the HTTP transaction is also shown.
 .PP
 If
@@ -128,18 +128,18 @@ switch.
 If
 .B nmh
 has been compiled with OAuth support, the
-.B \-oauth
+.B \-saslmech xoauth2
 switch will enable OAuth authentication.  The
 .B \-user
 switch must be used, and the
 .I user-name
-must be an email address the user has for that service.  Before using this,
-the user must authorize nmh by running
+must be an email address the user has for the service, which must
+be specified with the
+.B \-authservice
+.I service
+switch.  Before using this, the user must authorize nmh by running
 .B mhlogin
-and grant authorization to that account.  Only
-.B -oauth
-.I gmail
-is supported.  See the
+and grant authorization to that account.  See the
 .B mhlogin
 man page for more details.
 .PP
index 281fe8d..2691c89 100644 (file)
@@ -1,7 +1,7 @@
 .\"
 .\" %nmhwarning%
 .\"
-.TH SEND %manext1% "November 25, 2014" "%nmhversion%"
+.TH SEND %manext1% "March 23, 2016" "%nmhversion%"
 .SH NAME
 send \- send a message
 .SH SYNOPSIS
@@ -25,8 +25,6 @@ send \- send a message
 .RB [ \-msgid " | " \-nomsgid ]
 .RB [ \-messageid
 .IR localname " | " random ]
-.RB [ \-oauth
-.IR service ]
 .RB [ \-push " | " \-nopush ]
 .RB [ \-split
 .IR seconds ]
@@ -46,6 +44,8 @@ send \- send a message
 .IR ssf ]
 .RB [ \-saslmech
 .IR mechanism ]
+.RB [ \-authservice
+.IR service ]
 .RB [ \-snoop ]
 .RB [ \-user
 .IR username ]
@@ -391,7 +391,7 @@ entry).  The
 switch can be used to view the SMTP transaction.  (Beware that the
 SMTP transaction may contain authentication information either in
 plaintext or easily decoded base64.)  If
-.B \-oauth
+.B \-saslmech xoauth2
 is used, the HTTP transaction is also shown.
 .PP
 If
@@ -431,18 +431,18 @@ underlying SASL mechanism.  A value of 0 disables encryption.
 If
 .B nmh
 has been compiled with OAuth support, the
-.B \-oauth
+.B \-saslmech xoauth2
 switch will enable OAuth authentication.  The
 .B \-user
 switch must be used, and the
 .I user-name
-must be an email address the user has for that service.  Before using this,
-the user must authorize nmh by running
+must be an email address the user has for the service, which must
+be specified with the
+.B \-authservice
+.I service
+switch.  Before using this, the user must authorize nmh by running
 .B mhlogin
-and grant authorization to that account.  Only
-.B -oauth
-.I gmail
-is supported.  See the
+and grant authorization to that account.  See the
 .B mhlogin
 man page for more details.
 .PP
index 6c284d8..b795eb8 100644 (file)
@@ -184,7 +184,7 @@ mh_oauth_do_xoauth(const char *user, const char *svc, FILE *log)
     fp = lkfopendata(fn, "r+", &failed_to_lock);
     if (fp == NULL) {
         if (errno == ENOENT) {
-            adios(NULL, "no credentials -- run mhlogin -oauth %s", svc);
+            adios(NULL, "no credentials -- run mhlogin -saslmech xoauth2 -authservice %s", svc);
         }
         adios(fn, "failed to open");
     }
@@ -199,12 +199,10 @@ mh_oauth_do_xoauth(const char *user, const char *svc, FILE *log)
     if (!mh_oauth_access_token_valid(time(NULL), cred)) {
         if (!mh_oauth_refresh(cred)) {
             if (mh_oauth_get_err_code(ctx) == MH_OAUTH_NO_REFRESH) {
-                adios(NULL, "no valid credentials -- run mhlogin -oauth %s",
-                      svc);
+                adios(NULL, "no valid credentials -- run mhlogin -saslmech xoauth2 -authservice %s", svc);
             }
             if (mh_oauth_get_err_code(ctx) == MH_OAUTH_BAD_GRANT) {
-                adios(NULL, "credentials rejected -- run mhlogin -oath %s",
-                      svc);
+                adios(NULL, "credentials rejected -- run mhlogin -saslmech xoauth2 -authservice %s", svc);
             }
             advise(NULL, "error refreshing OAuth2 token");
             adios(NULL, mh_oauth_get_err_string(ctx));
@@ -329,7 +327,7 @@ update_svc_field(char **field, const char *base_name, const char *svc)
 static boolean
 update_svc(struct service_info *svc, const char *svc_name, mh_oauth_ctx *ctx)
 {
-#define update(name)                                                     \
+#define update(name)                                                    \
     update_svc_field(&svc->name, #name, svc_name);                       \
     if (svc->name == NULL) {                                             \
         set_err_details(ctx, MH_OAUTH_BAD_PROFILE, #name " is missing"); \
index e0fdb2a..3f3dc59 100644 (file)
@@ -131,7 +131,7 @@ expect_creds() {
 }
 
 test_inc() {
-    run_test "inc -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@example.com -width 80" "$@"
+    run_test "inc -host 127.0.0.1 -port ${pop_port} -saslmech xoauth2 -authservice test -user nobody@example.com -width 80" "$@"
 }
 
 test_inc_success() {
@@ -142,7 +142,7 @@ test_inc_success() {
 }
 
 test_send_no_servers() {
-    run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -oauth test -user nobody@example.com" "$@"
+    run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice test -user nobody@example.com" "$@"
 }
 
 test_send_only_fakesmtp() {
index b7287a4..c6c0261 100755 (executable)
@@ -18,7 +18,7 @@ expect_no_creds() {
 
 test_mhlogin() {
     start_fakehttp
-    run_test 'eval echo code | mhlogin -oauth test' \
+    run_test 'eval echo code | mhlogin -saslmech xoauth2 -authservice test' \
 "Load the following URL in your browser and authorize nmh to access test:
 
 http://127.0.0.1:${http_port}/oauth/auth?response_type=code&client_id=test-id&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=test-scope
index 1c5ae4b..363debc 100755 (executable)
@@ -35,7 +35,7 @@ expire: 2000000000
 EOF
 
 start_fakesmtp
-run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -oauth test -user nobody@example.com"
+run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice test -user nobody@example.com"
 
 # TEST
 echo 'expired access token, refresh works, smtp server accepts message'
@@ -163,21 +163,21 @@ setup_draft
 # TEST
 echo 'no service definition'
 
-run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -oauth bogus -user nobody@example.com" 'send: incomplete OAuth2 service definition: scope is missing'
+run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice bogus -user nobody@example.com" 'send: incomplete OAuth2 service definition: scope is missing'
 
 # TEST
 echo 'no creds file -- should tell user to mhlogin'
 
 rm -f "${MHTMPDIR}/oauth-test"
 
-test_send_no_servers 'send: no credentials -- run mhlogin -oauth test'
+test_send_no_servers 'send: no credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 echo 'empty creds file -- should tell user to mhlogin'
 
 fake_creds < /dev/null
 
-test_send_no_servers 'send: no valid credentials -- run mhlogin -oauth test'
+test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 echo 'garbage creds file'
@@ -234,7 +234,7 @@ access: test-access
 expire: 1414303986
 EOF
 
-test_send_no_servers 'send: no valid credentials -- run mhlogin -oauth test'
+test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 echo 'access token has no expiration, no refresh token -- tell user to mhlogin'
@@ -243,7 +243,7 @@ fake_creds <<EOF
 access: test-access
 EOF
 
-test_send_no_servers 'send: no valid credentials -- run mhlogin -oauth test'
+test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 echo 'refresh finds no http server'
@@ -259,7 +259,7 @@ send: error making HTTP request to OAuth2 authorization endpoint: [details]
 EOF
 
 run_prog send -draft -server 127.0.0.1 -port ${smtp_port} \
-  -oauth test -user nobody@example.com > "${testname}.send-output" 2>&1 || true
+  -saslmech xoauth2 -authservice test -user nobody@example.com > "${testname}.send-output" 2>&1 || true
 # Clear out an error message we get from libcurl on some systems (seen at least
 # 3 different versions of this error message, on FreeBSD 10.1, Ubuntu 12.04, and
 # Ubuntu 14.04).
@@ -309,7 +309,7 @@ Content-Type: application/json
 }
 EOF
 
-test_send_only_fakehttp 'send: credentials rejected -- run mhlogin -oath test'
+test_send_only_fakehttp 'send: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 echo 'refresh gets response too big'
index 6353ec5..cf5fca3 100755 (executable)
@@ -34,7 +34,7 @@ expire:
 EOF
 
 start_fakehttp
-run_test 'eval echo code | mhlogin -oauth test' \
+run_test 'eval echo code | mhlogin -saslmech xoauth2 -authservice test' \
 "Load the following URL in your browser and authorize nmh to access test:
 
 http://127.0.0.1:${http_port}/oauth/auth?response_type=code&client_id=test-id&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=test-scope
@@ -42,7 +42,7 @@ http://127.0.0.1:${http_port}/oauth/auth?response_type=code&client_id=test-id&re
 Enter the authorization code: "
 
 start_pop_xoauth
-run_test "msgchk -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
+run_test "msgchk -host 127.0.0.1 -port ${pop_port} -saslmech xoauth2 -authservice test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
 
 start_pop_xoauth
 test_inc_success
@@ -74,7 +74,7 @@ start_pop_xoauth
 test_inc_success
 
 start_pop_xoauth
-run_test "msgchk -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
+run_test "msgchk -host 127.0.0.1 -port ${pop_port} -saslmech oauth2 -authservice test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
 
 setup_draft
 test_send_only_fakesmtp
@@ -100,7 +100,7 @@ EOF
 
 start_fakehttp
 start_pop_xoauth
-run_test "msgchk -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
+run_test "msgchk -host 127.0.0.1 -port ${pop_port} -saslmech xoauth2 -authservice test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
 
 start_pop_xoauth
 test_inc_success
@@ -131,7 +131,7 @@ setup_draft
 test_send
 
 start_pop_xoauth
-run_test "msgchk -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
+run_test "msgchk -host 127.0.0.1 -port ${pop_port} -saslmech xoauth2 -authservice test -user nobody@example.com" 'nobody@example.com has 1 message (178 bytes) on 127.0.0.1'
 
 start_pop_xoauth
 test_inc_success
index 5f5c509..a47b336 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -58,7 +58,6 @@
     X("form formatfile", 0, FORMSW) \
     X("format string", 5, FMTSW) \
     X("host hostname", 0, HOSTSW) \
-    X("oauth service", 0, OAUTHSW) \
     X("user username", 0, USERSW) \
     X("pack file", 0, PACKSW) \
     X("nopack", 0, NPACKSW) \
@@ -74,6 +73,7 @@
     X("sasl", SASLminc(-4), SASLSW) \
     X("nosasl", SASLminc(-6), NOSASLSW) \
     X("saslmech", SASLminc(-8), SASLMECHSW) \
+    X("authservice", SASLminc(-11), AUTHSERVICESW) \
     X("proxy command", 0, PROXYSW) \
 
 #define X(sw, minchars, id) id,
@@ -191,14 +191,13 @@ main (int argc, char **argv)
     char *cp, *maildir = NULL, *folder = NULL;
     char *format = NULL, *form = NULL;
     char *host = NULL, *port = NULL, *user = NULL, *proxy = NULL;
-    char *audfile = NULL, *from = NULL, *saslmech = NULL;
+    char *audfile = NULL, *from = NULL, *saslmech = NULL, *auth_svc = NULL;
     char buf[BUFSIZ], **argp, *nfs, **arguments;
     struct msgs *mp = NULL;
     struct stat st, s1;
     FILE *aud = NULL;
     char b[PATH_MAX + 1];
     char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */
-    const char *oauth_svc = NULL;
 
     int nmsgs, nbytes;
     char *MAILHOST_env_variable;
@@ -326,16 +325,6 @@ main (int argc, char **argv)
                    adios (NULL, "missing argument to %s", argp[-2]);
                continue;
 
-            case OAUTHSW:
-#ifdef OAUTH_SUPPORT
-                if (!(cp = *argp++) || *cp == '-')
-                    adios (NULL, "missing argument to %s", argp[-2]);
-                oauth_svc = cp;
-#else
-                adios (NULL, "not built with OAuth support");
-#endif
-                continue;
-
            case USERSW:
                if (!(user = *argp++) || *user == '-')
                    adios (NULL, "missing argument to %s", argp[-2]);
@@ -364,6 +353,16 @@ main (int argc, char **argv)
                if (!(saslmech = *argp++) || *saslmech == '-')
                    adios (NULL, "missing argument to %s", argp[-2]);
                continue;
+
+           case AUTHSERVICESW:
+#ifdef OAUTH_SUPPORT
+                if (!(auth_svc = *argp++) || *auth_svc == '-')
+                    adios (NULL, "missing argument to %s", argp[-2]);
+#else
+                adios (NULL, "not built with OAuth support");
+#endif
+                continue;
+
            case PROXYSW:
                if (!(proxy = *argp++) || *proxy == '-')
                    adios (NULL, "missing argument to %s", argp[-2]);
@@ -406,11 +405,14 @@ main (int argc, char **argv)
     if (inc_type == INC_POP) {
        struct nmh_creds creds = { 0, 0, 0 };
 
-       if (oauth_svc == NULL) {
+       if (auth_svc == NULL) {
+           if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
+               adios (NULL, "must specify -authservice with -saslmech xoauth2");
+           }
            nmh_get_credentials (host, user, sasl, &creds);
        } else {
            if (user == NULL) {
-               adios (NULL, "must specify -user with -oauth");
+               adios (NULL, "must specify -user with -saslmech xoauth2");
            }
            creds.user = user;
        }
@@ -419,7 +421,7 @@ main (int argc, char **argv)
         * initialize POP connection
         */
        if (pop_init (host, port, creds.user, creds.password, proxy, snoop,
-                     sasl, saslmech, oauth_svc) == NOTOK)
+                     sasl, saslmech, auth_svc) == NOTOK)
            adios (NULL, "%s", response);
 
        /* Check if there are any messages */
index 4fa10e1..a08305c 100644 (file)
@@ -13,7 +13,8 @@
 #include <h/oauth.h>
 
 #define MHLOGIN_SWITCHES \
-    X("oauth", 1, OAUTHSW) \
+    X("saslmech", 1, SASLMECHSW) \
+    X("authservice", -11, AUTHSERVICESW) \
     X("snoop", 1, SNOOPSW) \
     X("help", 1, HELPSW) \
     X("version", 1, VERSIONSW) \
@@ -52,7 +53,7 @@ do_login(const char *svc, int snoop)
     const char *url;
 
     if (svc == NULL) {
-        adios(NULL, "only support -oauth gmail");
+        adios(NULL, "missing -authservice switch");
     }
 
     if (!mh_oauth_new(&ctx, svc)) {
@@ -110,7 +111,7 @@ int
 main(int argc, char **argv)
 {
     char *cp, **argp, **arguments;
-    char *svc = NULL;
+    char *saslmech = NULL, *svc = NULL;
     int snoop = 0;
 
     if (nmh_init(argv[0], 1)) { return 1; }
@@ -129,7 +130,7 @@ main(int argc, char **argv)
                adios (NULL, "-%s unknown", cp);
 
            case HELPSW:
-               snprintf(help, sizeof(help), "%s -oauth gmail [switches]",
+               snprintf(help, sizeof(help), "%s [switches]",
                          invo_name);
                print_help (help, switches, 1);
                done (0);
@@ -137,10 +138,14 @@ main(int argc, char **argv)
                print_version(invo_name);
                done (0);
 
-            case OAUTHSW:
-                   if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                    svc = cp;
+           case SASLMECHSW:
+               if (!(saslmech = *argp++) || *saslmech == '-')
+                   adios (NULL, "missing argument to %s", argp[-2]);
+               continue;
+
+           case AUTHSERVICESW:
+                if (!(svc = *argp++) || *svc == '-')
+                    adios (NULL, "missing argument to %s", argp[-2]);
                 continue;
 
             case SNOOPSW:
index ef9d32b..d1b1cb7 100644 (file)
@@ -33,7 +33,7 @@
     X("snoop", -5, SNOOPSW) \
     X("sasl", SASLminc(-4), SASLSW) \
     X("saslmech", SASLminc(-5), SASLMECHSW) \
-    X("oauth service", 0, OAUTHSW) \
+    X("authservice", SASLminc(-11), AUTHSERVICESW) \
     X("proxy command", 0, PROXYSW) \
 
 #define X(sw, minchars, id) id,
@@ -82,10 +82,9 @@ main (int argc, char **argv)
     int status = 0, sasl = 0;
     int snoop = 0, vecp = 0;
     char *cp, *host = NULL, *port = NULL, *user = NULL, *proxy = NULL;
-    char buf[BUFSIZ], *saslmech = NULL; 
+    char buf[BUFSIZ], *saslmech = NULL, *auth_svc = NULL;
     char **argp, **arguments, *vec[MAXVEC];
     struct passwd *pw;
-    const char *oauth_svc = NULL;
 
     if (nmh_init(argv[0], 1)) { return 1; }
 
@@ -140,16 +139,6 @@ main (int argc, char **argv)
                        adios (NULL, "missing argument to %s", argp[-2]);
                continue;
 
-            case OAUTHSW:
-#ifdef OAUTH_SUPPORT
-                if (!(cp = *argp++) || *cp == '-')
-                    adios (NULL, "missing argument to %s", argp[-2]);
-                oauth_svc = cp;
-#else
-                adios (NULL, "not built with OAuth support");
-#endif
-                continue;
-
                case USERSW: 
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
@@ -172,6 +161,15 @@ main (int argc, char **argv)
                        adios (NULL, "missing argument to %s", argp[-2]);
                    continue;
 
+               case AUTHSERVICESW:
+#ifdef OAUTH_SUPPORT
+                   if (!(auth_svc = *argp++) || *auth_svc == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+#else
+                   adios (NULL, "not built with OAuth support");
+#endif
+                   continue;
+
                case PROXYSW:
                    if (!(proxy = *argp++) || *proxy == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
@@ -204,11 +202,11 @@ main (int argc, char **argv)
     if (host) {
        if (vecp == 0) {
            status = remotemail (host, port, user, proxy, notifysw, 1,
-                                snoop, sasl, saslmech, oauth_svc);
+                                snoop, sasl, saslmech, auth_svc);
        } else {
            for (vecp = 0; vec[vecp]; vecp++)
                status += remotemail (host, port, vec[vecp], proxy, notifysw, 0,
-                                     snoop, sasl, saslmech, oauth_svc);
+                                     snoop, sasl, saslmech, auth_svc);
        }
     } else {
        if (user == NULL) user = getusername ();
@@ -333,23 +331,26 @@ extern char response[];
 static int
 remotemail (char *host, char *port, char *user, char *proxy, int notifysw,
            int personal, int snoop, int sasl, char *saslmech,
-           const char *oauth_svc)
+           const char *auth_svc)
 {
     int nmsgs, nbytes, status;
     struct nmh_creds creds = { 0, 0, 0 };
 
-    if (oauth_svc == NULL) {
+    if (auth_svc == NULL) {
+       if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
+           adios (NULL, "must specify -authservice with -saslmech xoauth2");
+       }
        nmh_get_credentials (host, user, sasl, &creds);
     } else {
        if (user == NULL) {
-           adios (NULL, "must specify -user with -oauth");
+           adios (NULL, "must specify -user with -saslmech xoauth2");
        }
        creds.user = user;
     }
 
     /* open the POP connection */
     if (pop_init (host, port, creds.user, creds.password, proxy, snoop, sasl,
-                 saslmech, oauth_svc) == NOTOK
+                 saslmech, auth_svc) == NOTOK
            || pop_stat (&nmsgs, &nbytes) == NOTOK     /* check for messages  */
            || pop_quit () == NOTOK) {                 /* quit POP connection */
        advise (NULL, "%s", response);
index 4391608..836a817 100644 (file)
@@ -80,7 +80,7 @@
     X("nosasl", SASLminc(-6), NOSASLSW) \
     X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
     X("saslmech", SASLminc(-5), SASLMECHSW) \
-    X("oauth", -5, OAUTHSW) \
+    X("authservice", SASLminc(-11), AUTHSERVICESW) \
     X("user", SASLminc(-4), USERSW) \
     X("port server submission port name/number", 4, PORTSW) \
     X("tls", TLSminc(-3), TLSSW) \
@@ -442,10 +442,13 @@ main (int argc, char **argv)
                        adios (NULL, "missing argument to %s", argp[-2]);
                    continue;
 
-               case OAUTHSW:
-                   if (!(cp = *argp++) || *cp == '-')
+               case AUTHSERVICESW:
+#ifdef OAUTH_SUPPORT
+                   if (!(xoauth_client_res = *argp++) || *xoauth_client_res == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
-                    xoauth_client_res = cp;
+#else
+                   adios (NULL, "not built with OAuth support");
+#endif
                    continue;
 
                case USERSW:
index 491efbb..a9d4842 100644 (file)
@@ -65,7 +65,7 @@
     X("nosasl", SASLminc(-6), NOSASLSW) \
     X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
     X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
-    X("oauth service", 0, OAUTHSW) \
+    X("authservice", SASLminc(-11), AUTHSERVICESW) \
     X("user username", SASLminc(-4), USERSW) \
     X("attach", -6, ATTACHSW) \
     X("noattach", -8, NOATTACHSW) \
@@ -121,10 +121,11 @@ main (int argc, char **argv)
     char *cp, *dfolder = NULL, *maildir = NULL;
     char buf[BUFSIZ], **ap, **argp, **arguments, *program;
     char *msgs[MAXARGS], **vec;
-    const char *user = NULL, *oauth_svc = NULL;
+    const char *user = NULL, *saslmech = NULL;
     struct msgs *mp;
     struct stat st;
     int snoop = 0;
+    char *auth_svc = NULL;
 
     if (nmh_init(argv[0], 1)) { return 1; }
 
@@ -259,18 +260,6 @@ main (int argc, char **argv)
                    vec[vecp++] = --cp;
                    continue;
 
-                case OAUTHSW:
-#ifdef OAUTH_SUPPORT
-                   if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                    oauth_svc = cp;
-#else
-                    NMH_UNUSED (user);
-                    NMH_UNUSED (oauth_svc);
-                    adios (NULL, "not built with OAuth support");
-#endif
-                   continue;
-
                case USERSW:
                    vec[vecp++] = --cp;
                    if (!(cp = *argp++) || *cp == '-')
@@ -279,12 +268,25 @@ main (int argc, char **argv)
                     user = cp;
                    continue;
 
+               case SASLMECHSW:
+                   if (!(saslmech = *argp++) || *saslmech == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   continue;
+
+               case AUTHSERVICESW:
+#ifdef OAUTH_SUPPORT
+                   if (!(auth_svc = *argp++) || *auth_svc == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+#else
+                   adios (NULL, "not built with OAuth support");
+#endif
+                   continue;
+
                case ALIASW: 
                case FILTSW: 
                case WIDTHSW: 
                case CLIESW: 
                case SERVSW: 
-               case SASLMECHSW:
                case SASLMXSSFSW:
                case PORTSW:
                case MTSSM:
@@ -449,15 +451,26 @@ go_to_it:
     }
 
 #ifdef OAUTH_SUPPORT
-    if (oauth_svc != NULL) {
+    if (auth_svc == NULL) {
+        if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
+            adios (NULL, "must specify -authservice with -saslmech xoauth2");
+        }
+    } else {
         if (user == NULL) {
-            adios (NULL, "must specify -user with -oauth");
+            adios (NULL, "must specify -user with -saslmech xoauth2");
         }
 
-        vec[vecp++] = "-oauth";
-        vec[vecp++] = mh_oauth_do_xoauth (user, oauth_svc,
-                                         snoop ? stderr : NULL);
+        vec[vecp++] = "-authservice";
+        if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
+            vec[vecp++] = mh_oauth_do_xoauth (user, auth_svc, snoop ? stderr : NULL);
+        } else {
+            vec[vecp++] = auth_svc;
+        }
     }
+#else
+    NMH_UNUSED(auth_svc);
+    NMH_UNUSED(user);
+    NMH_UNUSED(saslmech);
 #endif /* OAUTH_SUPPORT */
 
     if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
index 223d3f0..b9518e8 100644 (file)
@@ -949,7 +949,7 @@ buildfile (char **argp, char *file)
     X("nosasl", SASLminc(-6), NOSASLSW) \
     X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
     X("saslmech", SASLminc(-5), SASLMECHSW) \
-    X("oauth service", 5, OAUTHSW) \
+    X("authservice", SASLminc(-11), AUTHSERVICESW) \
     X("user username", SASLminc(-4), USERSW) \
     X("attach fieldname", 6, SNDATTACHSW) \
     X("noattach", 0, SNDNOATTACHSW) \
@@ -990,7 +990,8 @@ sendit (char *sp, char **arg, char *file, int pushed)
     int        vecp, n = 1;
     char *cp, buf[BUFSIZ], **argp, *program;
     char **arguments, *savearg[MAXARGS], **vec;
-    const char *user = NULL, *oauth_svc = NULL;
+    const char *user = NULL, *saslmech = NULL;
+    char *auth_svc = NULL;
     int snoop = 0;
     struct stat st;
 
@@ -1145,13 +1146,26 @@ sendit (char *sp, char **arg, char *file, int pushed)
                    vec[vecp++] = --cp;
                    continue;
 
+               case AUTHSERVICESW:
+#ifdef OAUTH_SUPPORT
+                   if (!(auth_svc = *argp++) || *auth_svc == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+#else
+                    NMH_UNUSED (user);
+                    NMH_UNUSED (auth_svc);
+                   adios (NULL, "not built with OAuth support");
+#endif
+                   continue;
+
+               case SASLMECHSW:
+                    saslmech = *argp;
+                   /* fall thru */
                case ALIASW:
                case FILTSW:
                case WIDTHSW:
                case CLIESW:
                case SERVSW:
                case SASLMXSSFSW:
-               case SASLMECHSW:
                case USERSW:
                case PORTSW:
                case MTSSM:
@@ -1166,18 +1180,6 @@ sendit (char *sp, char **arg, char *file, int pushed)
                     user = cp;
                    continue;
 
-                case OAUTHSW:
-#ifdef OAUTH_SUPPORT
-                   if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                    oauth_svc = cp;
-#else
-                    NMH_UNUSED (user);
-                    NMH_UNUSED (oauth_svc);
-                    adios (NULL, "not built with OAuth support");
-#endif
-                   continue;
-
                case SDRFSW:
                case SDRMSW:
                    if (!(cp = *argp++) || *cp == '-') {
@@ -1245,15 +1247,24 @@ sendit (char *sp, char **arg, char *file, int pushed)
     }
 
 #ifdef OAUTH_SUPPORT
-    if (oauth_svc != NULL) {
+    if (auth_svc == NULL) {
+        if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
+            adios (NULL, "must specify -authservice with -saslmech xoauth2");
+        }
+    } else {
         if (user == NULL) {
-            adios (NULL, "must specify -user with -oauth");
+            adios (NULL, "must specify -user with -saslmech xoauth2");
         }
 
-        vec[vecp++] = "-oauth";
-        vec[vecp++] = mh_oauth_do_xoauth (user, oauth_svc,
-                                         snoop ? stderr : NULL);
+        vec[vecp++] = "-authservice";
+        if (saslmech  &&  ! strcasecmp(saslmech, "xoauth2")) {
+            vec[vecp++] = mh_oauth_do_xoauth (user, auth_svc, snoop ? stderr : NULL);
+        } else {
+            vec[vecp++] = auth_svc;
+        }
     }
+#else
+    NMH_UNUSED(saslmech);
 #endif /* OAUTH_SUPPORT */
 
     if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {