merge with latest 2.2_release submit/tizen_2.2/20130814.085838 submit/tizen_2.2/20130814.101615
authorMin-Soo Kim <minnsoo.kim@samsung.com>
Fri, 2 Aug 2013 10:14:41 +0000 (19:14 +0900)
committerMin-Soo Kim <minnsoo.kim@samsung.com>
Fri, 2 Aug 2013 10:14:41 +0000 (19:14 +0900)
20 files changed:
Makefile.am
configure.ac
imap-2007e/c-client/Makefile
imap-2007e/c-client/auth_pla.c
imap-2007e/c-client/auth_xoauth2.c [new file with mode: 0755]
imap-2007e/c-client/auths.c
imap-2007e/c-client/imap4r1.c
imap-2007e/c-client/linkage.c
imap-2007e/c-client/linkage.h
imap-2007e/c-client/lnx_mail.c
imap-2007e/c-client/mail.c
imap-2007e/c-client/mail.h
imap-2007e/c-client/osdep.c
imap-2007e/c-client/osdepssl.c
imap-2007e/c-client/rfc822.c
imap-2007e/c-client/smtp.c
imap-2007e/c-client/ssl_unix.c
libuw-imap-toolkit.manifest
packaging/uw-imap-toolkit.spec
uw-imap-toolkit.pc.in

index 8b241f6..f035fba 100755 (executable)
@@ -31,6 +31,7 @@ libuw_imap_toolkit_la_CPPFLAGS= -I. \
                            -D__FEATURE_HEADER_OPTIMIZATION__ \
                            -D__FEATURE_SEND_OPTMIZATION__ \
                            -D__FEATURE_XLIST_SUPPORT__ \
+                           -D__FEATURE_SUPPORT_IMAP_ID__ \
                            -DCREATEPROTO=unixproto -DEMPTYPROTO=unixproto \
                            -DMAILSPOOL=\"/var/spool/mail\" \
                            -DANONYMOUSHOME=\"/var/spool/mail/anonymous\" \
@@ -64,7 +65,7 @@ pcfiles = uw-imap-toolkit.pc
 all: 
 all-local: $(pcfiles)
 
-SUFFIXES: .pc
+%.pc: %.pc
        cp $< $@
 
 pkgconfigdir = $(libdir)/pkgconfig
index e1f6b2e..30f1dc2 100755 (executable)
@@ -8,7 +8,6 @@ AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADER([config.h])
 
 # Checks for programs.
-ifdef([AM_PROG_AR], [AM_PROG_AR])
 AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_INSTALL
index 090c8f2..3c043c0 100755 (executable)
@@ -903,7 +903,7 @@ osdep.o:mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
        gethstid.c getspnam.c \
        gr_wait.c gr_wait4.c gr_waitp.c \
        kerb_mit.c \
-       auth_ext.c auth_gss.c auth_log.c auth_md5.c auth_pla.c \
+       auth_ext.c auth_gss.c auth_log.c auth_md5.c auth_pla.c auth_xoauth2.c\
        pmatch.c scandir.c setpgrp.c strerror.c truncate.c write.c \
        memmove.c memmove2.c memset.c \
        tz_bsd.c tz_nul.c tz_sv4.c \
index 4813c4c..f775dfd 100755 (executable)
@@ -65,11 +65,6 @@ long auth_plain_client (authchallenge_t challenger,authrespond_t responder,
                                /* get initial (empty) challenge */
   if (challenge = (*challenger) (stream,&clen)) {
     fs_give ((void **) &challenge);
-    if (clen) {                        /* abort if challenge non-empty */
-      mm_log ("auth_plain_client : Server bug: non-empty initial PLAIN challenge 1",WARN);
-      (*responder) (stream,NIL,0);
-      ret = LONGT;             /* will get a BAD response back */
-    }
     pwd[0] = NIL;              /* prompt user if empty challenge */
     mm_login (mb,user,pwd,*trial);
 
@@ -78,6 +73,21 @@ long auth_plain_client (authchallenge_t challenger,authrespond_t responder,
       *trial = 0;              /* cancel subsequent attempts */
       ret = LONGT;             /* will get a BAD response back */
     }
+
+    else if ((*responder) (stream,user,strlen (user)) &&
+            (challenge = (*challenger) (stream,&clen))) {
+      fs_give ((void **) &challenge);
+                               /* send password */
+      if ((*responder) (stream,pwd,strlen (pwd))) {
+       if (challenge = (*challenger) (stream,&clen))
+         fs_give ((void **) &challenge);
+       else {
+         ++*trial;             /* can try again if necessary */
+         ret = LONGT;          /* check the authentication */
+       }
+      }
+    }
+
     else {
       unsigned long rlen = 
        strlen (mb->authuser) + strlen (user) + strlen (pwd) + 2;
@@ -111,15 +121,9 @@ long auth_plain_client (authchallenge_t challenger,authrespond_t responder,
       fs_give ((void **) &response);
     }
   }
-  else // [ Written by Kyuho Jo for AOL 2010/02/16
+  else
   {
        mm_log ("Enter section for handling emtpy challenge",WARN);
-    if (clen) 
-       {                       /* abort if challenge non-empty */
-      mm_log ("auth_plain_client : Server bug: non-empty initial PLAIN challenge 2",WARN);
-      (*responder) (stream,NIL,0);
-      ret = LONGT;             /* will get a BAD response back */
-    }
     pwd[0] = NIL;              /* prompt user if empty challenge */
 
        mm_login (mb,user,pwd,*trial);
@@ -155,7 +159,7 @@ long auth_plain_client (authchallenge_t challenger,authrespond_t responder,
              fs_give ((void **) &challenge);
            else 
            {
-             mm_log ("Second emtpy challege  ",WARN);
+             mm_log ("Second empty challege  ",WARN);
              ++*trial;         /* can try again if necessary */
              ret = LONGT;              /* check the authentication */
            }
@@ -164,7 +168,7 @@ long auth_plain_client (authchallenge_t challenger,authrespond_t responder,
       fs_give ((void **) &response);
     }
        
-  }    // ] Written by Kyuho Jo for AOL 2010/02/16
+  }
 
   memset (pwd,0,MAILTMPLEN);   /* erase password */
   if (!ret) *trial = 65535;    /* don't retry if bad protocol */
diff --git a/imap-2007e/c-client/auth_xoauth2.c b/imap-2007e/c-client/auth_xoauth2.c
new file mode 100755 (executable)
index 0000000..048cc9a
--- /dev/null
@@ -0,0 +1,111 @@
+/* ========================================================================
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 
+ * ========================================================================
+ */
+
+/*
+ * Program:    XOAUTH2 authenticator
+ *
+ * Author:     Kyuho Jo (kyuho.jo@samsung.com)
+ *
+ * Date:       18 May 2013
+ */
+\f
+long auth_xoauth2_client (authchallenge_t challenger,authrespond_t responder,
+                       char *service,NETMBX *mb,void *stream,
+                       unsigned long *trial,char *user);
+char *auth_xoauth2_server (authresponse_t responder,int argc,char *argv[]);
+
+AUTHENTICATOR auth_xoauth2 = {
+  AU_AUTHUSER | AU_HIDE,       /* allow authuser, hidden */
+  "XOAUTH2",                   /* authenticator name */
+  NIL,                         /* always valid */
+  auth_xoauth2_client,         /* client method */
+  auth_xoauth2_server,         /* server method */
+  NIL                          /* next authenticator */
+};
+\f
+/* Client authenticator
+ * Accepts: challenger function
+ *         responder function
+ *         SASL service name
+ *         parsed network mailbox structure
+ *         stream argument for functions
+ *         pointer to current trial count
+ *         returned user name
+ * Returns: T if success, NIL otherwise, number of trials incremented if retry
+ */
+
+#define MAX_RESPONSE_LENGTH 1024
+#define CHAR_SOH            0x01
+
+long auth_xoauth2_client (authchallenge_t challenger,authrespond_t responder,
+                       char *service,NETMBX *mb,void *stream,
+                       unsigned long *trial,char *user)
+{
+       char *u, token[MAILTMPLEN] = { 0, };
+       void *challenge;
+       unsigned long clen;
+       long ret = NIL;
+
+       if (challenge = (*challenger) (stream,&clen)) {
+               fs_give ((void **) &challenge);
+               if (clen) { /* abort if challenge non-empty */
+                       mm_log ("auth_xoauth2_client : non-empty initial XOAUTH2 challenge",WARN);
+                       (*responder) (stream,NIL,0);
+                       ret = LONGT; /* will get a BAD response back */
+               }
+               token[0] = NIL;         /* prompt user if empty challenge */
+               mm_login (mb, user, token, *trial);
+
+               if (!token[0]) {                /* empty challenge or user requested abort */
+                       (*responder) (stream, NIL, 0);
+                       *trial = 0;             /* cancel subsequent attempts */
+                       ret = LONGT;            /* will get a BAD response back */
+               }
+               else {
+                       unsigned long formed_response_length = 0;
+                       char formed_response[MAX_RESPONSE_LENGTH] = { 0, };
+
+                       snprintf(formed_response, MAX_RESPONSE_LENGTH, "user=%s%cauth=Bearer %s%c%c", user, CHAR_SOH, token, CHAR_SOH, CHAR_SOH);
+
+                       mm_log(formed_response, TCPDEBUG);
+
+                       if ((*responder) (stream,formed_response,strlen(formed_response))) {
+                               if (challenge = (*challenger) (stream,&clen)) {
+                                       /* print challenge with error code */
+                                       mm_log(challenge, ERROR);
+                                       /* and send CR */
+                                       (*responder) (stream, "", 0);
+                                       fs_give ((void **) &challenge);
+                                       ret = LONGT;
+                               }
+                               else {
+                                       ++*trial;
+                                       ret = LONGT;
+                               }
+                       }
+               }
+               memset(token,0,MAILTMPLEN);
+       }
+       return ret;
+}
+\f
+/* Server authenticator
+ * Accepts: responder function
+ *         argument count
+ *         argument vector
+ * Returns: authenticated user name or NIL
+ */
+char *auth_xoauth2_server (authresponse_t responder,int argc,char *argv[])
+{
+       char *ret = NIL;
+       return NIL;
+}
index 3e0e254..5836882 100755 (executable)
@@ -2,3 +2,4 @@
 #include "auth_md5.c"
 #include "auth_pla.c"
 #include "auth_log.c"
+#include "auth_xoauth2.c"
index d9ebdc4..ef5a003 100755 (executable)
@@ -39,6 +39,7 @@
 #include "c-client.h"
 #include "imap4r1.h"
 \f
+
 /* Parameters */
 
 #define IMAPLOOKAHEAD 20       /* envelope lookahead */
@@ -165,6 +166,9 @@ long imap_status (MAILSTREAM *stream,char *mbx,long flags);
 MAILSTREAM *imap_open (MAILSTREAM *stream);
 IMAPPARSEDREPLY *imap_rimap (MAILSTREAM *stream,char *service,NETMBX *mb,
                             char *usr,char *tmp);
+#ifdef __FEATURE_SUPPORT_IMAP_ID__
+long imap_id (MAILSTREAM *stream);
+#endif /* __FEATURE_SUPPORT_IMAP_ID__ */
 long imap_anon (MAILSTREAM *stream,char *tmp);
 long imap_auth (MAILSTREAM *stream,NETMBX *mb,char *tmp,char *usr);
 long imap_login (MAILSTREAM *stream,NETMBX *mb,char *pwd,char *usr);
@@ -916,10 +920,20 @@ MAILSTREAM *imap_open (MAILSTREAM *stream)
                   net_host (LOCAL->netstream),NETMAXHOST-1);
          mb.host[NETMAXHOST-1] = '\0';
        }
+
+
+#ifdef __FEATURE_SUPPORT_IMAP_ID__
+       /* Process for IMAP ID */
+       if (LOCAL->cap.id) {
+               mm_log ("This server requires IMAP ID", WARN);
+               imap_id(stream);
+       }
+#endif /* __FEATURE_SUPPORT_IMAP_ID__ */
+
                                /* need new capabilities after login */
        LOCAL->gotcapability = NIL;
        if (!(stream->anonymous ? imap_anon (stream,tmp) :
-             (LOCAL->cap.auth ? imap_auth (stream,&mb,tmp,usr) :
+             ((LOCAL->cap.auth && (mb.auth_method > AUTH_METHOD_NONE))? imap_auth (stream,&mb,tmp,usr) :
               imap_login (stream,&mb,tmp,usr)))) {
                                /* failed, is there a referral? */
          if (ir && LOCAL->referral &&
@@ -1062,6 +1076,41 @@ IMAPPARSEDREPLY *imap_rimap (MAILSTREAM *stream,char *service,NETMBX *mb,
   }
   return NIL;
 }
+
+#ifdef __FEATURE_SUPPORT_IMAP_ID__
+long imap_id (MAILSTREAM *stream)
+{
+       IMAPPARSEDREPLY *reply;
+       int ret = NIL;
+       char *imap_id_tag_string = NULL;
+       IMAPARG *args[2];
+       IMAPARG id_tag;
+
+       if(stream == NULL)
+               return ret;
+
+       mm_imap_id (&imap_id_tag_string);
+
+       if(imap_id_tag_string != NULL) {
+               if(stream->debug)
+                       mm_dlog(imap_id_tag_string);
+
+               id_tag.type = ASTRING;
+               id_tag.text = (void *) imap_id_tag_string;
+               args[0] = &id_tag; args[1] = NIL;
+               /* send "ID tag" */
+               if (imap_OK (stream,reply = imap_send (stream,"ID",args)))
+                       ret = LONGT;            /* success */
+               else {
+                       mm_log ("ID failed",ERROR);
+               }
+               free(imap_id_tag_string);
+       }
+
+       return ret;
+}
+#endif /* __FEATURE_SUPPORT_IMAP_ID__ */
+
 \f
 /* IMAP log in as anonymous
  * Accepts: stream to authenticate
@@ -1218,6 +1267,10 @@ long imap_login (MAILSTREAM *stream,NETMBX *mb,char *pwd,char *usr)
          ret = LONGT;          /* success */
        else {
          mm_log (reply->text,WARN);
+         if (reply->text && strstr(reply->text, "AUTHENTICATIONFAILED")) {
+                 mm_log ("Can not authenticate",ERROR);
+                 break;
+         }
          if (!LOCAL->referral && (trial == imap_maxlogintrials))
            mm_log ("Too many login failures",ERROR);
        }
@@ -4321,6 +4374,11 @@ void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply)
     else t = reply->text;
     mm_list (stream,NIL,t,NIL);
   }
+#ifdef __FEATURE_SUPPORT_IMAP_ID__
+  else if (!strcmp (reply->key,"ID")) {
+    imap_parse_id (stream,reply->text);
+  }
+#endif /* __FEATURE_SUPPORT_IMAP_ID__ */
   else {
     sprintf (LOCAL->tmp,"Unexpected untagged message: %.80s",
             (char *) reply->key);
@@ -4387,7 +4445,7 @@ void imap_parse_response (MAILSTREAM *stream,char *text,long errflg,long ntfy)
       }
 \f
       else if (!compare_cstring (t,"CAPABILITY"))
-       imap_parse_capabilities (stream,s);
+         imap_parse_capabilities (stream,s);
       else if ((j = LEVELUIDPLUS (stream) && LOCAL->appendmailbox) &&
               !compare_cstring (t,"COPYUID") &&
               (cu = (copyuid_t) mail_parameters (NIL,GET_COPYUID,NIL)) &&
@@ -5219,22 +5277,24 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
        stream->unhealthy = T;
        body->subtype = cpystr (rfc822_default_subtype (body->type));
       }
-      if (**txtptr == ' ')     /* multipart parameters */
+      if (**txtptr == ' ' && *((*txtptr)+ 1) != ')') { /* multipart parameters */
        body->parameter = imap_parse_body_parameter (stream,txtptr,reply);
-      if (**txtptr == ' ') {   /* disposition */
+      }
+      if (**txtptr == ' ' && *((*txtptr)+ 1) != ')') { /* disposition */
        imap_parse_disposition (stream,body,txtptr,reply);
        if (LOCAL->cap.extlevel < BODYEXTDSP) LOCAL->cap.extlevel = BODYEXTDSP;
       }
-      if (**txtptr == ' ') {   /* language */
+      if (**txtptr == ' ' && *((*txtptr)+ 1) != ')') { /* language */
        body->language = imap_parse_language (stream,txtptr,reply);
        if (LOCAL->cap.extlevel < BODYEXTLANG)
          LOCAL->cap.extlevel = BODYEXTLANG;
       }
-      if (**txtptr == ' ') {   /* location */
+      if (**txtptr == ' ' && *((*txtptr)+ 1) != ')') { /* location */
        body->location = imap_parse_string (stream,txtptr,reply,NIL,NIL,LONGT);
        if (LOCAL->cap.extlevel < BODYEXTLOC) LOCAL->cap.extlevel = BODYEXTLOC;
       }
-      while (**txtptr == ' ') imap_parse_extension (stream,txtptr,reply);
+      while (**txtptr == ' ' && *((*txtptr)+ 1) != ')') imap_parse_extension (stream,txtptr,reply);
+      while ((c = **txtptr) == ' ') ++*(txtptr);
       if (**txtptr != ')') {   /* validate ending */
        sprintf (LOCAL->tmp,"Junk at end of multipart body: %.80s",
                 (char *) *txtptr);
@@ -5313,20 +5373,20 @@ void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,
        break;
       }
 \f
-      if (**txtptr == ' ') {   /* extension data - md5 */
+      if (**txtptr == ' ' && *(*txtptr + 1) != ')') {  /* extension data - md5 */
        body->md5 = imap_parse_string (stream,txtptr,reply,NIL,NIL,LONGT);
        if (LOCAL->cap.extlevel < BODYEXTMD5) LOCAL->cap.extlevel = BODYEXTMD5;
       }
-      if (**txtptr == ' ') {   /* disposition */
+      if (**txtptr == ' ' && *(*txtptr + 1) != ')') {  /* disposition */
        imap_parse_disposition (stream,body,txtptr,reply);
        if (LOCAL->cap.extlevel < BODYEXTDSP) LOCAL->cap.extlevel = BODYEXTDSP;
       }
-      if (**txtptr == ' ') {   /* language */
+      if (**txtptr == ' ' && *(*txtptr + 1) != ')') {  /* language */
        body->language = imap_parse_language (stream,txtptr,reply);
        if (LOCAL->cap.extlevel < BODYEXTLANG)
          LOCAL->cap.extlevel = BODYEXTLANG;
       }
-      if (**txtptr == ' ') {   /* location */
+      if (**txtptr == ' ' && *(*txtptr + 1) != ')') {  /* location */
        body->location = imap_parse_string (stream,txtptr,reply,NIL,NIL,LONGT);
        if (LOCAL->cap.extlevel < BODYEXTLOC) LOCAL->cap.extlevel = BODYEXTLOC;
       }
@@ -5643,6 +5703,16 @@ void imap_parse_capabilities (MAILSTREAM *stream,char *t)
       (i = mail_lookup_auth_name ("LOGIN",NIL)) && (--i < MAXAUTHENTICATORS))
     LOCAL->cap.auth &= ~(1 << i);
 }
+
+/* IMAP parse id
+ * Accepts: MAIL stream
+ *         reply
+ */
+
+void imap_parse_id (MAILSTREAM *stream,char *t)
+{
+  /* If ID information from host is needed, add parser here */
+}
 \f
 /* IMAP load cache
  * Accepts: MAIL stream
index 66fb599..9de09a7 100755 (executable)
@@ -17,6 +17,7 @@
   auth_link (&auth_md5);               /* link in the md5 authenticator */
   auth_link (&auth_pla);               /* link in the pla authenticator */
   auth_link (&auth_log);               /* link in the log authenticator */
+  auth_link (&auth_xoauth2);   /* link in the xoauth2 authenticator */
   mail_versioncheck (CCLIENTVERSION);
   ssl_onceonlyinit ();
   mail_parameters (NIL,SET_DISABLEPLAINTEXT,(void *) 2);
index e7ed506..7fe61dd 100755 (executable)
@@ -17,3 +17,4 @@ extern AUTHENTICATOR auth_ext;
 extern AUTHENTICATOR auth_md5;
 extern AUTHENTICATOR auth_pla;
 extern AUTHENTICATOR auth_log;
+extern AUTHENTICATOR auth_xoauth2;
index 6ed835b..eb5f9cf 100755 (executable)
@@ -154,31 +154,14 @@ char *tcp_getline_lnx (void *vstream)
 }
 #endif
 
-
 int try_auth = 0;
-unsigned int mail_lookup_auth_name (char *mechanism,long flags)
-{
-  int i;
-  AUTHENTICATOR *auth;
-
-  if(!try_auth) return 0;
-
-  for (i = 1, auth = mailauthenticators; auth; i++, auth = auth->next)
-    if (auth->client && !(flags & ~auth->flags) &&
-       !compare_cstring (auth->name,mechanism))
-      return i;
-  return 0;
-}
-
-// 22-Mar-2010 added
 int try_auth_smtp = 0;
-unsigned int mail_lookup_auth_name_smtp (char *mechanism,long flags)
+
+unsigned int mail_lookup_auth_name (char *mechanism,long flags)
 {
   int i;
   AUTHENTICATOR *auth;
 
-  if(!try_auth_smtp) return 0;
-
   for (i = 1, auth = mailauthenticators; auth; i++, auth = auth->next)
     if (auth->client && !(flags & ~auth->flags) &&
        !compare_cstring (auth->name,mechanism))
index a4ffc43..a0ae947 100755 (executable)
@@ -806,9 +806,14 @@ long mail_valid_net_parse_work (char *name,NETMBX *mb,char *service)
        else if (!compare_cstring (s,"loser")) mb->loser = T;
        else if (!compare_cstring (s,"tls") && !mb->notlsflag)
          mb->tlsflag = T;
-       //APOP Authentication - shasikala.p@siso.com
        else if (!compare_cstring (s,"apop"))
          mb->apop = T;
+       else if (!compare_cstring (s,"force_tls_v1_0"))
+         mb->force_tls_v1_0 = T;
+       else if (!compare_cstring (s,"needauth"))
+         mb->auth_method = AUTH_METHOD_DEFAULT;
+       else if (!compare_cstring (s,"xoauth2"))
+         mb->auth_method = AUTH_METHOD_XOAUTH2;
        else if (!compare_cstring (s,"tls-sslv23") && !mb->notlsflag)
          mb->tlssslv23 = mb->tlsflag = T;
        else if (!compare_cstring (s,"notls") && !mb->tlsflag)
@@ -1350,8 +1355,13 @@ MAILSTREAM *mail_open_work (DRIVER *d,MAILSTREAM *stream,char *name,
 MAILSTREAM *mail_close_full (MAILSTREAM *stream,long options)
 {
   int i;
+  char tmp[MAILTMPLEN] = { 0, };
   if (stream) {                        /* make sure argument given */
-                               /* do the driver's close action */
+       snprintf (tmp, MAILTMPLEN, "Checking 'unhealthy' flag of MAILSTEAM.. [%d]", stream->unhealthy);
+       MM_LOG (tmp,(long)WARN);
+       if(stream->unhealthy)
+               return NIL;
+       /* do the driver's close action */
     if (stream->dtb) (*stream->dtb->close) (stream,options);
     stream->dtb = NIL;         /* resign driver */
     if (stream->mailbox) fs_give ((void **) &stream->mailbox);
@@ -6226,6 +6236,9 @@ NETSTREAM *net_open (NETMBX *mb,NETDRIVER *dv,unsigned long port,
   NETSTREAM *stream = NIL;
   char tmp[MAILTMPLEN];
   unsigned long flags = mb->novalidate ? NET_NOVALIDATECERT : 0;
+
+  flags |= (mb->force_tls_v1_0) ? NET_FORCE_LOWER_TLS_VERSION : 0;
+
   if (strlen (mb->host) >= NETMAXHOST) {
     sprintf (tmp,"Invalid host name: %.80s",mb->host);
     MM_LOG (tmp,ERROR);
@@ -6373,6 +6386,8 @@ void net_close (NETSTREAM *stream)
 
 char *net_host (NETSTREAM *stream)
 {
+  if(stream == NULL || stream->stream == NULL)
+         return "";
   return (*stream->dtb->host) (stream->stream);
 }
 
@@ -6384,6 +6399,8 @@ char *net_host (NETSTREAM *stream)
 
 char *net_remotehost (NETSTREAM *stream)
 {
+  if(stream == NULL || stream->stream == NULL)
+    return "";
   return (*stream->dtb->remotehost) (stream->stream);
 }
 \f
@@ -6394,6 +6411,8 @@ char *net_remotehost (NETSTREAM *stream)
 
 unsigned long net_port (NETSTREAM *stream)
 {
+  if(stream == NULL || stream->stream == NULL)
+    return 0;
   return (*stream->dtb->port) (stream->stream);
 }
 
@@ -6405,5 +6424,7 @@ unsigned long net_port (NETSTREAM *stream)
 
 char *net_localhost (NETSTREAM *stream)
 {
+  if(stream == NULL || stream->stream == NULL)
+    return "";
   return (*stream->dtb->localhost) (stream->stream);
 }
index 138b162..51e5b7b 100755 (executable)
 #define OP_NOKOD (long) 0x800  /* suppress kiss-of-death */
 #define OP_SNIFF (long) 0x1000 /* metadata only open */
                                /* reserved for application use */
+
+#define OP_FORCE_LOWER_TLS_VERSION 0x2000 /* force lower TLS version */
 #define OP_RESERVED (unsigned long) 0xff000000
 
 
 #define NET_TLSCLIENT ((unsigned long) 0x10000000)
                                /* try SSL mode */
 #define NET_TRYSSL ((unsigned long) 0x8000000)
+                               /* force lower TLS version */
+#define NET_FORCE_LOWER_TLS_VERSION ((unsigned long) 0x4000000)
 \f
 /* Close options */
 
 
 #endif /* __FEATURE_XLIST_SUPPORT__ */
 
+#define AUTH_METHOD_NONE     0
+#define AUTH_METHOD_DEFAULT  1
+#define AUTH_METHOD_XOAUTH2  2
 
 /* Sort functions */
 
@@ -678,7 +685,9 @@ typedef struct net_mailbox {
   unsigned int norsh : 1;      /* don't use rsh/ssh */
   unsigned int loser : 1;      /* server is a loser */
   unsigned int tlssslv23 : 1;  /* force SSLv23 client method over TLS */
-  unsigned int apop; /*APOP Authentication - shasikala.p@siso.com*/
+  unsigned int apop; /*APOP Authentication */
+  unsigned int force_tls_v1_0 : 1; /* force TLS v1.0 */
+  unsigned int auth_method; /* Authentication method */
 } NETMBX;
 \f
 /* Item in an address list */
@@ -1637,6 +1646,9 @@ void mm_nocritical (MAILSTREAM *stream);
 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious);
 void mm_fatal (char *string);
 void *mm_cache (MAILSTREAM *stream,unsigned long msgno,long op);
+#ifdef __FEATURE_IMAP_ID_SUPPORT__
+void mm_imap_id (char **id_string);
+#endif /* __FEATURE_IMAP_ID_SUPPORT__ */
 
 extern STRINGDRIVER mail_string;
 void mail_versioncheck (char *version);
index 61a5972..be588c0 100755 (executable)
@@ -401,7 +401,11 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
                                       TLSv1_client_method () :
                                       SSLv23_client_method ())))
     return "SSL context failed";
-  SSL_CTX_set_options (stream->context,0);
+  if (flags & NET_FORCE_LOWER_TLS_VERSION)
+       SSL_CTX_set_options(stream->context, SSL_OP_NO_SSLv2|SSL_OP_NO_TLSv1_1|SSL_OP_NO_TLSv1_2);
+  else
+    SSL_CTX_set_options (stream->context,0);
+
                                /* disable certificate validation? */
   if (flags & NET_NOVALIDATECERT)
     SSL_CTX_set_verify (stream->context,SSL_VERIFY_NONE,NIL);
index 3bfdff3..72af170 100755 (executable)
@@ -223,7 +223,12 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
                                       TLSv1_client_method () :
                                       SSLv23_client_method ())))
     return "SSL context failed";
-  SSL_CTX_set_options (stream->context,0);
+
+  if (flags & NET_FORCE_LOWER_TLS_VERSION)
+       SSL_CTX_set_options(stream->context, SSL_OP_NO_SSLv2|SSL_OP_NO_TLSv1_1|SSL_OP_NO_TLSv1_2);
+  else
+    SSL_CTX_set_options (stream->context,0);
+
                                /* disable certificate validation? */
   if (flags & NET_NOVALIDATECERT)
     SSL_CTX_set_verify (stream->context,SSL_VERIFY_NONE,NIL);
index 07a724a..eff7747 100755 (executable)
@@ -738,6 +738,13 @@ void rfc822_parse_adrlist (ADDRESS **lst,char *string,char *host)
       last = adr;              /* new tail address */
       if (string) {            /* analyze what follows */
        rfc822_skipws (&string);
+
+       /* Recovery from failure on parsing */
+       if ( string != NULL) {
+               while (*string != ',' && *string != '\0')
+                       string++;
+    }
+
        switch (c = *(unsigned char *) string) {
        case ',':               /* comma? */
          ++string;             /* then another address follows */
@@ -985,9 +992,11 @@ ADDRESS *rfc822_parse_routeaddr (char *string,char **ret,char *defaulthost)
     if (!**ret) *ret = NIL;    /* wipe pointer if at end of string */
     return adr;                        /* return the address */
   }
-  sprintf (tmp,"Unterminated mailbox: %.80s@%.80s",adr->mailbox,
-          *adr->host == '@' ? "<null>" : adr->host);
-  MM_LOG (tmp,PARSE);
+  if (adr) {
+         sprintf (tmp,"Unterminated mailbox: %.80s@%.80s", (adr->mailbox == NULL) ? "<null>" : adr->mailbox,
+                         (adr->host == NULL || *adr->host == '@') ? "<null>" : adr->host);
+         MM_LOG (tmp,PARSE);
+  }
   adr->next = mail_newaddr ();
   adr->next->mailbox = cpystr ("MISSING_MAILBOX_TERMINATOR");
   adr->next->host = cpystr (errhst);
index 023464a..cbb9b78 100755 (executable)
@@ -249,7 +249,9 @@ SENDSTREAM *smtp_open_full (NETDRIVER *dv,char **hostlist,char *service,
                         NETMAXHOST-1);
                mb.host[NETMAXHOST-1] = '\0';
              }
-             if (!smtp_auth (stream,&mb,tmp)) stream = smtp_close (stream);
+             if(mb.auth_method > 0) {
+                 if (!smtp_auth (stream,&mb,tmp)) stream = smtp_close (stream);
+             }
            }
            else {              /* no available authenticators? */
              sprintf (tmp,"%sSMTP authentication not available: %.80s", mb.secflag ? "Secure " : "",mb.host);
@@ -294,6 +296,9 @@ long smtp_auth (SENDSTREAM *stream,NETMBX *mb,char *tmp)
   for (auths = ESMTP.auth, stream->saslcancel = NIL;
        !ret && stream->netstream && auths &&
        (at = mail_lookup_auth (find_rightmost_bit (&auths) + 1)); ) {
+
+    sprintf (tmp,"Trying using %s authentication. ", at->name);
+    mm_log (tmp,NIL);
     if (lsterr) {              /* previous authenticator failed? */
       sprintf (tmp,"Retrying using %s authentication after %.80s", at->name,lsterr);
       mm_log (tmp,NIL);
@@ -322,52 +327,6 @@ long smtp_auth (SENDSTREAM *stream,NETMBX *mb,char *tmp)
        }
        stream->sensitive = NIL;/* unhide */
       }
-#if 1          // for smtp.web.de
-               else if (!strcmp(at->name, "PLAIN")) {
-                       char* user = usr;
-                       char pwd[MAILTMPLEN];
-                       
-                       pwd[0] = NIL;
-                       mm_login(mb, user, pwd, trial);
-                       
-                       unsigned long rlen = strlen(mb->authuser) + strlen(user) + strlen(pwd) + 2;
-                       char* response = (char*) fs_get(rlen);
-                       char* t = response;
-                       char* u;
-                       
-                       if (mb->authuser[0])
-                               for (u =user; *u; *t++ = *u++);
-                       
-                       *t++ = '\0';
-                       
-                       for (u = (mb->authuser[0] ? mb->authuser : user); *u; *t++ = *u++);
-                       
-                       *t++ = '\0';
-                       
-                       for (u = pwd; *u; *t++ = *u++);
-                       
-                       unsigned long i, j;
-                       
-                       for (t = (char*) rfc822_binary(response, rlen, &i), u = t, j = 0; j < i; j++) {
-                               if (t[j] > ' ') *u++ = t[j];
-                       }
-                       
-                       *u = '\0';
-                       
-                       i = smtp_send(stream, "AUTH PLAIN", t);
-                       
-                       fs_give((void**)&t);
-                       
-                       memset(response, 0, rlen);
-                       fs_give((void**)&response);
-                       
-                       if (i == SMTPAUTHED) {
-                               ESMTP.auth = NIL;
-                               ret = LONGT;
-                       }
-                       else if (!trial) mm_log("SMTP Authentication cancelled", ERROR);
-               }
-#endif
          /* remember response if error and no cancel */
       if (!ret && trial) lsterr = cpystr (stream->reply);
     } while (!ret && stream->netstream && trial &&
@@ -768,9 +727,8 @@ long smtp_ehlo (SENDSTREAM *stream,char *host,NETMBX *mb)
        ESMTP.atrn.ok = T;
       }
       else if (!compare_cstring (s,"AUTH"))
-       //do if ((j = mail_lookup_auth_name (t,flags)) &&
-       do if ((j = mail_lookup_auth_name_smtp (t,flags)) &&            // 22-Mar-2010 Fix for SMTP Authorization issue - avoid race condition. change from     mail_lookup_auth_name to mail_lookup_auth_name_smtp
-              (--j < MAXAUTHENTICATORS)) ESMTP.auth |= (1 << j);
+       do if ((j = mail_lookup_auth_name (t,flags)) &&
+       (--j < MAXAUTHENTICATORS)) ESMTP.auth |= (1 << j);
        while ((t = strtok_r (NIL," ",&r)) && *t);
     }
                                /* EHLO options which do not take arguments */
@@ -795,17 +753,12 @@ long smtp_ehlo (SENDSTREAM *stream,char *host,NETMBX *mb)
   }
   while ((i < 100) || (stream->reply[3] == '-'));
                                /* disable LOGIN if PLAIN also advertised */
-  // 22-Mar-2010 change from   mail_lookup_auth_name to mail_lookup_auth_name_smtp
   /*
   if ((j = mail_lookup_auth_name ("PLAIN",NIL)) && (--j < MAXAUTHENTICATORS) &&
       (ESMTP.auth & (1 << j)) &&
       (j = mail_lookup_auth_name ("LOGIN",NIL)) && (--j < MAXAUTHENTICATORS))
     ESMTP.auth &= ~(1 << j);
-    */
-  if ((j = mail_lookup_auth_name_smtp ("PLAIN",NIL)) && (--j < MAXAUTHENTICATORS) &&
-      (ESMTP.auth & (1 << j)) &&
-      (j = mail_lookup_auth_name_smtp ("LOGIN",NIL)) && (--j < MAXAUTHENTICATORS))
-    ESMTP.auth &= ~(1 << j);
+   */
   return i;                    /* return the response code */
 }
 \f
index 3bfdff3..54f1d9f 100755 (executable)
@@ -223,7 +223,10 @@ static char *ssl_start_work (SSLSTREAM *stream,char *host,unsigned long flags)
                                       TLSv1_client_method () :
                                       SSLv23_client_method ())))
     return "SSL context failed";
-  SSL_CTX_set_options (stream->context,0);
+  if (flags & NET_FORCE_LOWER_TLS_VERSION)
+       SSL_CTX_set_options(stream->context, SSL_OP_NO_SSLv2|SSL_OP_NO_TLSv1_1|SSL_OP_NO_TLSv1_2);
+  else
+    SSL_CTX_set_options (stream->context,0);
                                /* disable certificate validation? */
   if (flags & NET_NOVALIDATECERT)
     SSL_CTX_set_verify (stream->context,SSL_VERIFY_NONE,NIL);
index a6508d0..75b0fa5 100644 (file)
@@ -1,9 +1,5 @@
 <manifest>
-  <define> 
-    <domain name="libuw-imap-toolkit"/>
-  </define>
-  <request>
-    <domain name="libuw-imap-toolkit"/>
-  </request>
+    <request>
+        <domain name="_"/>
+    </request>
 </manifest>
-
index 71fbbea..e2751f9 100644 (file)
@@ -1,11 +1,9 @@
 #sbs-git:slp/pkgs/u/uw-imap-toolkit uw-imap-toolkit 0.1.1 a675e5c581b6726dcb93c63d826d6827bf29d671
 %define _optdir        /opt
 %define _appdir        %{_optdir}/apps
-
-
 Name:       uw-imap-toolkit
 Summary:    IMAP-2007e developed by University of Washington
-Version: 0.1.1
+Version: 0.1.2
 Release:    0
 Group:      TO_BE/FILLED_IN
 License:    TO BE FILLED IN
@@ -59,6 +57,7 @@ rm -rf %{buildroot}
 
 
 %files -n libuw-imap-toolkit
+%manifest libuw-imap-toolkit.manifest
 %defattr(-,root,root,-) 
 %{_libdir}/libuw-imap-toolkit.so.*
 
index 9ed78c6..428b978 100755 (executable)
@@ -1,5 +1,5 @@
 prefix=@prefix@\r
-libdir=@libdir@\r
+libdir=@prefix@/lib\r
 includedir=@prefix@/include\r
  \r
 Name: IMAP Toolkit Library \r