Changeset 2081

Show
Ignore:
Timestamp:
06/06/07 12:58:10
Author:
pvanhoof
Message:

The use_ssl option

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2077 r2081  
    66        * Added the option --with-ssl=nss,openssl,none to the build to assist 
    77        the SSL library availability detection 
     8        * Changed the use_ssl options to "wrapped", "tls", "when-possible" and 
     9        "never" for both POP3 and IMAP 
     10        * Some connection fixes in the IMAP and POP3 connection procedures 
    811 
    9122007-06-05  Philip Van Hoof  <pvanhoof@gnome.org> 
  • trunk/README

    r1724 r2081  
    108108To use SSL (other values are "never" and "when-possible"): 
    109109 
    110 gconftool-2 -s /apps/tinymail/accounts/0/options -t list --list-type=string '[use_ssl=always]' 
     110gconftool-2 -s /apps/tinymail/accounts/0/options -t list --list-type=string '[use_ssl=wrapped]' 
    111111 
    112112Distribution specific: also check out requirements.txt 
  • trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c

    r2076 r2081  
    671671 
    672672static gboolean 
    673 connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex) 
     673connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, int must_tls, CamelException *ex) 
    674674{ 
    675675        CamelImapStore *store = (CamelImapStore *) service; 
     
    682682        gboolean not_ssl = TRUE; 
    683683 
    684         if (ssl_mode != MODE_CLEAR) { 
     684        if (ssl_mode != MODE_CLEAR)  
     685        { 
    685686                not_ssl = FALSE; 
     687 
    686688#ifdef HAVE_SSL 
    687                 if (ssl_mode == MODE_TLS) { 
     689                if (ssl_mode == MODE_TLS) 
    688690                        tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS); 
    689                 } else { 
     691                else  
    690692                        tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS); 
    691                 } 
    692693#else 
     694 
    693695                camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, 
    694                                       _("Could not connect to %s: %s"), 
    695                                       service->url->host, _("SSL unavailable")); 
    696                  
     696                                _("Could not connect to %s: %s"), 
     697                                service->url->host, _("SSL unavailable in this build")); 
     698 
    697699                return FALSE; 
     700 
    698701#endif /* HAVE_SSL */ 
    699         } else { 
     702        } else 
    700703                tcp_stream = camel_tcp_stream_raw_new (); 
    701         } 
    702          
    703         if (camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai) == -1)
     704 
     705        if (camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai) == -1)  
     706       
    704707                if (errno == EINTR) 
    705708                        camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, 
     
    710713                                              service->url->host, 
    711714                                              g_strerror (errno)); 
    712                  
    713715                camel_object_unref (tcp_stream); 
    714                  
    715716                return FALSE; 
    716717        } 
     
    738739        if (camel_imap_store_readline (store, &buf, ex) < 0)  
    739740        { 
    740  
    741                 g_mutex_lock (store->stream_lock); 
    742                 if (store->istream) { 
    743                         camel_object_unref (store->istream); 
    744                         store->istream = NULL; 
    745                 } 
    746                  
    747                 if (store->ostream) { 
    748                         camel_object_unref (store->ostream); 
    749                         store->ostream = NULL; 
    750                 } 
    751                 g_mutex_unlock (store->stream_lock); 
    752  
    753                 store->connected = FALSE; 
    754                  
    755                 return FALSE; 
    756         } 
    757          
     741                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     742                        _("Failed to connect to IMAP server %s"), 
     743                        service->url->host, _("Reading IMAP greeting failed")); 
     744                goto exception; 
     745        } 
     746 
    758747        if (!strncmp(buf, "* PREAUTH", 9)) 
    759748                store->preauthed = TRUE; 
    760          
    761         if (strstr (buf, "Courier-IMAP") || getenv("CAMEL_IMAP_BRAINDAMAGED")) { 
     749 
     750        if (strstr (buf, "Courier-IMAP") || getenv("CAMEL_IMAP_BRAINDAMAGED"))  
     751        { 
    762752                /* Courier-IMAP is braindamaged. So far this flag only 
    763753                 * works around the fact that Courier-IMAP is known to 
     
    767757                 * rather than getting individual parts. */ 
    768758                store->braindamaged = TRUE; 
    769         } else if (strstr (buf, "WEB.DE") || strstr (buf, "Mail2World")) { 
     759        } else if (strstr (buf, "WEB.DE") || strstr (buf, "Mail2World"))  
     760        { 
    770761                /* This is a workaround for servers which advertise 
    771762                 * IMAP4rev1 but which can sometimes subtly break in 
     
    786777                force_imap4 = TRUE; 
    787778        } 
    788          
    789779 
    790780        /* Tinymail hack: always use IMAP4, not IMAP4rev1 (sorry) */ 
    791  
    792781        /* force_imap4 = TRUE; */ 
    793782        store->braindamaged = TRUE; 
    794  
    795783        /* end of hack :) */ 
    796784 
    797785        g_free (buf); 
    798          
     786 
    799787        /* get the imap server capabilities */ 
    800788        if (!imap_get_capability (service, ex))  
    801789        { 
    802                 g_mutex_lock (store->stream_lock); 
    803                 if (store->istream) { 
    804                         camel_object_unref (store->istream); 
    805                         store->istream = NULL; 
    806                 } 
    807                  
    808                 if (store->ostream) { 
    809                         camel_object_unref (store->ostream); 
    810                         store->ostream = NULL; 
    811                 } 
    812                 g_mutex_unlock (store->stream_lock); 
    813  
    814                 store->connected = FALSE; 
    815                 return FALSE; 
    816         } 
    817          
    818         if (force_imap4) { 
     790                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     791                        _("Failed to connect to IMAP server %s"), 
     792                        service->url->host, _("Reading first CAPABILITY failed")); 
     793                goto exception; 
     794        } 
     795 
     796        if (must_tls && !(store->capabilities & IMAP_CAPABILITY_STARTTLS)) 
     797        { 
     798                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     799                        _("Failed to connect to IMAP server %s"), 
     800                        service->url->host, _("STARTTLS not announced as supported on this server")); 
     801                goto exception; 
     802        } 
     803 
     804        if (force_imap4)  
     805        { 
    819806                store->capabilities &= ~IMAP_CAPABILITY_IMAP4REV1; 
    820807                store->server_level = IMAP_LEVEL_IMAP4; 
    821808        } 
    822          
    823         if (not_ssl || ssl_mode != MODE_TLS) { 
    824  
     809 
     810        if (!must_tls && (not_ssl || ssl_mode != MODE_TLS))  
     811        { 
    825812                /* we're done */ 
    826  
    827813                return TRUE; 
    828  
    829         } 
    830          
     814        } 
     815 
     816 
    831817#ifdef HAVE_SSL 
    832         if (!(store->capabilities & IMAP_CAPABILITY_STARTTLS)) { 
     818 
     819        if (!(store->capabilities & IMAP_CAPABILITY_STARTTLS))  
     820        { 
    833821                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
    834822                                      _("Failed to connect to IMAP server %s in secure mode: %s"), 
    835823                                      service->url->host, _("STARTTLS not supported")); 
    836                  
    837824                goto exception; 
    838825        } 
    839          
     826 
    840827        /* as soon as we send a STARTTLS command, all hope is lost of a clean QUIT if problems arise */ 
    841828        clean_quit = FALSE; 
    842          
     829 
    843830        response = camel_imap_command (store, NULL, ex, "STARTTLS"); 
    844831        if (!response)  
     
    850837                store->ostream = NULL; 
    851838                g_mutex_unlock (store->stream_lock); 
    852  
    853                 return FALSE; 
    854         } 
    855          
     839                clean_quit = FALSE; 
     840                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     841                                _("Failed to connect to IMAP server %s in secure mode: %s"), 
     842                                service->url->host, _("STARTTLS not supported")); 
     843                goto exception; 
     844        } 
     845 
    856846        camel_imap_response_free_without_processing (store, response); 
    857          
     847 
    858848        /* Okay, now toggle SSL/TLS mode */ 
    859         if (camel_tcp_stream_ssl_enable_ssl (CAMEL_TCP_STREAM_SSL (tcp_stream)) == -1) { 
     849        if (camel_tcp_stream_ssl_enable_ssl (CAMEL_TCP_STREAM_SSL (tcp_stream)) == -1)  
     850        { 
    860851                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
    861                                       _("Failed to connect to IMAP server %s in secure mode: %s"), 
    862                                       service->url->host, _("SSL negotiations failed")); 
     852                                _("Failed to connect to IMAP server %s in secure mode: %s"), 
     853                                service->url->host, _("SSL negotiations failed")); 
    863854                goto exception; 
    864855        } 
     856 
    865857#else 
    866858        camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     
    869861        goto exception; 
    870862#endif /* HAVE_SSL */ 
    871          
     863 
     864 
    872865        /* rfc2595, section 4 states that after a successful STLS 
    873            command, the client MUST discard prior CAPA responses */ 
     866           command, the client MUST discard prior CAPA responses */ 
     867 
    874868        if (!imap_get_capability (service, ex))  
    875869        { 
    876  
    877                 g_mutex_lock (store->stream_lock); 
    878                 if (store->istream) { 
    879                         camel_object_unref (store->istream); 
    880                         store->istream = NULL; 
    881                 } 
    882                  
    883                 if (store->ostream) { 
    884                         camel_object_unref (store->ostream); 
    885                         store->ostream = NULL; 
    886                 } 
    887                 g_mutex_unlock (store->stream_lock); 
    888  
    889                 store->connected = FALSE; 
    890                  
    891                 return FALSE; 
     870                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     871                        _("Failed to connect to IMAP server %s"), 
     872                        service->url->host, _("Reading second CAPABILITY failed")); 
     873                goto exception; 
    892874        } 
    893875 
    894876        if (store->capabilities & IMAP_CAPABILITY_LOGINDISABLED ) {  
    895                 clean_quit = TRUE; 
    896877                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
    897                                 _("Failed to connect to IMAP server %s in secure mode: %s"), service->url->host, _("Unknown error")); 
     878                                _("Failed to connect to IMAP server %s in secure mode: %s"),  
     879                                service->url->host, _("Unknown error, LOGINDISABLED with SSL")); 
    898880                goto exception; 
    899881        } 
    900882 
    901883        return TRUE; 
    902          
    903  exception: 
    904          
    905         if (clean_quit && store->connected) { 
     884 
     885exception: 
     886 
     887        if (clean_quit && store->connected)  
     888        { 
    906889                /* try to disconnect cleanly */ 
    907890                response = camel_imap_command (store, NULL, ex, "LOGOUT"); 
     
    915898                store->istream = NULL; 
    916899        } 
    917          
    918900        if (store->ostream) { 
    919901                camel_object_unref (store->ostream); 
     
    921903        } 
    922904        g_mutex_unlock (store->stream_lock); 
    923  
    924905        store->connected = FALSE; 
    925          
     906 
    926907        return FALSE; 
    927908} 
     
    1012993        while (i) 
    1013994                g_free(child_env[--i]); 
    1014                  
     995 
    1015996        if (ret == -1) { 
    1016997                if (errno == EINTR) 
     
    10361017        store->preauthed = FALSE; 
    10371018        store->command = 0; 
    1038          
     1019 
    10391020        /* Read the greeting, if any, and deal with PREAUTH */ 
    10401021        if (camel_imap_store_readline (store, &buf, ex) < 0)  
     
    10551036                return FALSE; 
    10561037        } 
     1038 
    10571039        if (!strncmp(buf, "* PREAUTH", 9)) 
    10581040                store->preauthed = TRUE; 
    10591041        g_free (buf); 
    1060          
     1042 
    10611043        /* get the imap server capabilities */ 
    10621044        if (!imap_get_capability (service, ex))  
     
    10671049                        store->istream = NULL; 
    10681050                } 
    1069                  
    10701051                if (store->ostream) { 
    10711052                        camel_object_unref (store->ostream); 
     
    10771058                return FALSE; 
    10781059        } 
    1079          
     1060 
    10801061        return TRUE; 
    10811062         
     
    10891070        char *port; 
    10901071        int mode; 
     1072        int must_tls; 
    10911073} ssl_options[] = { 
    1092         { "",              "imaps", IMAPS_PORT, MODE_SSL   },  /* really old (1.x) */ 
    1093         { "always",        "imaps", IMAPS_PORT, MODE_SSL   }, 
    1094         { "when-possible", "imap",  IMAP_PORT,  MODE_TLS   }, 
    1095         { "never",         "imap",  IMAP_PORT,  MODE_CLEAR }, 
    1096         { NULL,            "imap",  IMAP_PORT,  MODE_CLEAR }, 
     1074        { "",              "imaps", IMAPS_PORT, MODE_SSL, 0   },  /* really old (1.x) */ 
     1075        { "wrapped",       "imaps", IMAPS_PORT, MODE_SSL, 0   }, 
     1076        { "tls",           "imap",  IMAPS_PORT, MODE_TLS, 1   }, 
     1077        { "when-possible", "imap",  IMAP_PORT,  MODE_TLS, 0   }, 
     1078        { "never",         "imap",  IMAP_PORT,  MODE_CLEAR, 0 }, 
     1079        { NULL,            "imap",  IMAP_PORT,  MODE_CLEAR, 0 }, 
    10971080}; 
    10981081 
     
    11031086        const char *ssl_mode; 
    11041087        struct addrinfo hints, *ai; 
    1105         int mode = -1, ret, i
     1088        int mode = -1, ret, i, must_tls = 0
    11061089        char *serv; 
    11071090        const char *port; 
     
    11131096            && (command = camel_url_get_param(service->url, "command"))) 
    11141097                return connect_to_server_process(service, command, ex); 
    1115 #endif   
    1116         if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) { 
     1098#endif 
     1099 
     1100        if ((ssl_mode = camel_url_get_param (service->url, "use_ssl")))  
     1101        { 
    11171102                for (i = 0; ssl_options[i].value; i++) 
    11181103                        if (!strcmp (ssl_options[i].value, ssl_mode)) 
     
    11211106                serv = ssl_options[i].serv; 
    11221107                port = ssl_options[i].port; 
    1123         } else { 
     1108                must_tls = ssl_options[i].must_tls; 
     1109        } else  
     1110        { 
    11241111                mode = MODE_CLEAR; 
    11251112                serv = "imap"; 
    11261113                port = IMAP_PORT; 
    1127         } 
    1128          
    1129         if (service->url->port) { 
     1114                must_tls = 0; 
     1115        } 
     1116 
     1117        if (service->url->port)  
     1118        { 
    11301119                serv = g_alloca (16); 
    11311120                sprintf (serv, "%d", service->url->port); 
    11321121                port = NULL; 
    11331122        } 
    1134          
     1123 
    11351124        memset (&hints, 0, sizeof (hints)); 
    11361125        hints.ai_socktype = SOCK_STREAM; 
    11371126        hints.ai_family = PF_UNSPEC; 
     1127 
    11381128        ai = camel_getaddrinfo(service->url->host, serv, &hints, ex); 
    1139         if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) { 
     1129 
     1130        if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL)  
     1131        { 
    11401132                camel_exception_clear (ex); 
    11411133                ai = camel_getaddrinfo(service->url->host, port, &hints, ex); 
    11421134        } 
    1143          
     1135 
    11441136        if (ai == NULL) 
    11451137                return FALSE; 
    1146          
    1147         ret = connect_to_server (service, ai, mode, ex); 
    1148          
     1138 
     1139        ret = connect_to_server (service, ai, mode, must_tls, ex); 
    11491140        camel_freeaddrinfo (ai); 
    1150          
     1141 
    11511142        return ret; 
    11521143} 
     
    14691460 
    14701461        auth_domain = camel_url_get_param (service->url, "auth-domain"); 
    1471          
    1472         if (store->preauthed) { 
     1462 
     1463        if (store->preauthed)  
     1464        { 
    14731465                if (camel_verbose_debug) 
    14741466                        fprintf(stderr, "Server %s has preauthenticated us.\n", 
     
    14771469        } 
    14781470 
    1479         if (service->url->authmech) { 
     1471        if (service->url->authmech)  
     1472        { 
    14801473                if (!g_hash_table_lookup (store->authtypes, service->url->authmech)) { 
    14811474                        camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, 
    1482                                               _("IMAP server %s does not support requested " 
    1483                                                "authentication type %s"), 
    1484                                               service->url->host, 
    1485                                               service->url->authmech); 
     1475                                        _("IMAP server %s does not support requested " 
     1476                                        "authentication type %s"), 
     1477                                        service->url->host, 
     1478                                        service->url->authmech); 
    14861479                        return FALSE; 
    14871480                } 
    1488                  
     1481 
    14891482                authtype = camel_sasl_authtype (service->url->authmech); 
    14901483                if (!authtype) { 
     
    14941487                        return FALSE; 
    14951488                } 
    1496                  
    1497                 if (!authtype->need_password) { 
     1489 
     1490                if (!authtype->need_password)  
     1491                { 
    14981492                        authenticated = try_auth (store, authtype->authproto, ex); 
    14991493                        if (!authenticated) 
     
    15011495                } 
    15021496        } 
    1503          
    1504         while (!authenticated) { 
    1505                 if (errbuf) { 
     1497 
     1498        while (!authenticated)  
     1499        { 
     1500                if (errbuf)  
     1501                { 
    15061502                        /* We need to un-cache the password before prompting again */ 
    15071503                        camel_session_forget_password (session, service, auth_domain, "password", ex); 
     
    15091505                        service->url->passwd = NULL; 
    15101506                } 
    1511                  
    1512                 if (!service->url->passwd) { 
     1507 
     1508                if (!service->url->passwd)  
     1509                { 
    15131510                        char *prompt; 
    15141511                         
    15151512                        prompt = g_strdup_printf (_("%sPlease enter the IMAP " 
    1516                                                     "password for %s@%s"), 
    1517                                                   errbuf ? errbuf : "", 
    1518                                                   service->url->user, 
    1519                                                   service->url->host); 
     1513                                                  "password for %s@%s"), 
     1514                                                errbuf ? errbuf : "", 
     1515                                                service->url->user, 
     1516                                                service->url->host); 
    15201517                        service->url->passwd = 
    15211518                                camel_session_get_password (session, service, auth_domain, 
    1522                                                            prompt, "password", CAMEL_SESSION_PASSWORD_SECRET, ex); 
     1519                                        prompt, "password", CAMEL_SESSION_PASSWORD_SECRET, ex); 
    15231520                        g_free (prompt); 
    15241521                        g_free (errbuf); 
    15251522                        errbuf = NULL; 
    1526                          
     1523 
    15271524                        if (!service->url->passwd) { 
    15281525                                camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, 
    1529                                                      _("You did not enter a password.")); 
     1526                                                _("You did not enter a password.")); 
    15301527                                return FALSE; 
    15311528                        } 
    15321529                } 
    15331530                 
    1534                 if (!store->connected) { 
     1531                if (!store->connected)  
     1532                { 
    15351533                        /* Some servers (eg, courier) will disconnect on 
    1536                          * a bad password. So reconnect here. 
    1537                          */ 
     1534                         * a bad password. So reconnect here. */ 
    15381535                        if (!connect_to_server_wrapper (service, ex)) 
    15391536                                return FALSE; 
    15401537                } 
    1541                  
     1538 
    15421539                if (authtype) 
    15431540                        authenticated = try_auth (store, authtype->authproto, ex); 
     
    15721569                        { 
    15731570                                errbuf = g_strdup_printf (_("Unable to authenticate " 
    1574                                                             "to IMAP server.\n%s\n\n"), 
    1575                                                           camel_exception_get_description (ex)); 
     1571                                                        "to IMAP server.\n%s\n\n"), 
     1572                                                        camel_exception_get_description (ex)); 
    15761573                                camel_exception_clear (ex); 
    15771574                                return FALSE; 
     
    15861583{ 
    15871584        CamelImapStore *store = CAMEL_IMAP_STORE (disco_store); 
    1588          
     1585 
    15891586        return camel_store_summary_count((CamelStoreSummary *)store->summary) != 0; 
    15901587} 
     
    16041601        CAMEL_SERVICE_REC_LOCK (store, connect_lock); 
    16051602 
    1606         if (!connect_to_server_wrapper (service, ex) || 
    1607             !imap_auth_loop (service, ex))
     1603        if (!connect_to_server_wrapper (service, ex) || !imap_auth_loop (service, ex))  
     1604       
    16081605                CAMEL_DISCO_STORE (store)->status = CAMEL_DISCO_STORE_OFFLINE; 
    16091606                CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
     
    16141611        /* Get namespace and hierarchy separator */ 
    16151612        if ((store->capabilities & IMAP_CAPABILITY_NAMESPACE) && 
    1616             !(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE)) { 
     1613                !(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE))  
     1614        { 
    16171615                response = camel_imap_command (store, NULL, ex, "NAMESPACE"); 
    16181616                if (!response) 
    16191617                        goto done; 
    1620                  
     1618 
    16211619                result = camel_imap_response_extract (store, response, "NAMESPACE", ex); 
    16221620                if (!result) 
    16231621                        goto done; 
    1624                  
     1622 
    16251623#if 0 
    16261624                /* new code... */ 
     
    16291627                /* end new code */ 
    16301628#endif 
    1631                  
     1629 
    16321630                name = camel_strstrcase (result, "NAMESPACE (("); 
    1633                 if (name) { 
     1631                if (name)  
     1632                { 
    16341633                        char *sep; 
    1635                          
    16361634                        name += 12; 
    16371635                        store->namespace = imap_parse_string ((const char **) &name, &len); 
     
    16461644                g_free (result); 
    16471645        } 
    1648          
     1646 
    16491647        if (!store->namespace) 
    16501648                store->namespace = g_strdup (""); 
    1651          
     1649 
    16521650        if (!store->dir_sep) { 
    1653                 if (store->server_level >= IMAP_LEVEL_IMAP4REV1) { 
     1651                if (store->server_level >= IMAP_LEVEL_IMAP4REV1)  
     1652                { 
    16541653                        /* This idiom means "tell me the hierarchy separator 
    16551654                         * for the given path, even if that path doesn't exist. 
     
    16671666                                                       store->namespace); 
    16681667                } 
     1668 
    16691669                if (!response) 
    16701670                        goto done; 
    1671                  
     1671 
    16721672                result = camel_imap_response_extract (store, response, "LIST", NULL); 
    1673                 if (result) { 
     1673                if (result)  
     1674                { 
    16741675                        imap_parse_list_response (store, result, NULL, &store->dir_sep, NULL); 
    16751676                        g_free (result); 
    16761677                } 
    1677                 if (!store->dir_sep) { 
     1678                if (!store->dir_sep) 
    16781679                        store->dir_sep = '/';   /* Guess */ 
    1679                 } 
    1680         } 
    1681          
     1680        } 
     1681 
    16821682        /* canonicalize the namespace to end with dir_sep */ 
    16831683        len = strlen (store->namespace); 
    1684         if (len && store->namespace[len - 1] != store->dir_sep) { 
    1685                 gchar *tmp; 
    1686                  
    1687                 tmp = g_strdup_printf ("%s%c", store->namespace, store->dir_sep); 
     1684        if (len && store->namespace[len - 1] != store->dir_sep)  
     1685        { 
     1686                gchar *tmp = g_strdup_printf ("%s%c", store->namespace, store->dir_sep); 
    16881687                g_free (store->namespace); 
    16891688                store->namespace = tmp; 
    16901689        } 
    1691          
     1690 
    16921691        ns = camel_imap_store_summary_namespace_new(store->summary, store->namespace, store->dir_sep); 
    16931692        camel_imap_store_summary_namespace_set(store->summary, ns); 
    16941693         
    16951694        if ((store->parameters & IMAP_PARAM_SUBSCRIPTIONS) 
    1696             && camel_store_summary_count((CamelStoreSummary *)store->summary) == 0) { 
     1695            && camel_store_summary_count((CamelStoreSummary *)store->summary) == 0)  
     1696        { 
    16971697                CamelStoreInfo *si; 
    16981698                char *pattern; 
    1699                  
     1699 
    17001700                get_folders_sync(store, store->namespace, ex); 
    17011701                if (camel_exception_is_set(ex)) 
     
    17091709                /* Make sure INBOX is present/subscribed */ 
    17101710                si = camel_store_summary_path((CamelStoreSummary *)store->summary, "INBOX"); 
    1711                 if (si == NULL || (si->flags & CAMEL_FOLDER_SUBSCRIBED) == 0) { 
     1711 
     1712                if (si == NULL || (si->flags & CAMEL_FOLDER_SUBSCRIBED) == 0)  
     1713                { 
    17121714                        response = camel_imap_command (store, NULL, ex, "SUBSCRIBE INBOX"); 
    17131715                        if (response != NULL) { 
     
    17201722                        get_folders_sync(store, "INBOX", ex); 
    17211723                } 
     1724 
    17221725                store->refresh_stamp = time(0); 
    17231726        } 
    1724          
    1725          
     1727 
    17261728 done: 
    17271729 
     
    17301732 
    17311733        CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); 
    1732          
    17331734        if (camel_exception_is_set (ex)) 
    17341735                camel_service_disconnect (service, TRUE, NULL); 
     
    17671768                store->istream = NULL; 
    17681769        } 
    1769          
     1770 
    17701771        if (store->ostream) { 
    17711772                camel_stream_close(store->ostream); 
     
    17861787                store->authtypes = NULL; 
    17871788        } 
    1788          
     1789 
    17891790        if (store->namespace && !(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE)) { 
    17901791                g_free (store->namespace); 
    17911792                store->namespace = NULL; 
    17921793        } 
    1793                  
     1794 
    17941795        return TRUE; 
    17951796} 
     
    18071808                camel_imap_response_free (store, response); 
    18081809        } 
    1809          
     1810 
    18101811        imap_disconnect_offline (service, clean, ex); 
    1811          
     1812 
    18121813        return TRUE; 
    18131814} 
     
    18291830                } 
    18301831        } 
    1831          
     1832 
    18321833        return FALSE; 
    18331834} 
     
    18391840        CamelImapResponse *response; 
    18401841        CamelFolder *current_folder; 
    1841          
     1842 
    18421843        CAMEL_SERVICE_REC_LOCK (imap_store, connect_lock); 
    18431844 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.c

    r2076 r2081  
    251251 
    252252static gboolean 
    253 connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex) 
     253connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, int must_tls, CamelException *ex) 
    254254{ 
    255255        CamelPOP3Store *store = CAMEL_POP3_STORE (service); 
     
    263263        store->connected = FALSE; 
    264264 
    265         if (ssl_mode != MODE_CLEAR) { 
     265        if (ssl_mode != MODE_CLEAR)  
     266        { 
     267 
    266268#ifdef HAVE_SSL 
    267                 if (ssl_mode == MODE_TLS) { 
     269                if (ssl_mode == MODE_TLS) 
    268270                        tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS); 
    269                 } else { 
     271                else  
    270272                        tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS); 
    271                 } 
    272273#else 
     274 
    273275                camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, 
    274                                       _("Could not connect to %s: %s"), 
    275                                       service->url->host, _("SSL unavailable")); 
    276                  
     276                                _("Could not connect to %s: %s"), 
     277                                service->url->host, _("SSL unavailable")); 
     278 
    277279                return FALSE; 
     280 
    278281#endif /* HAVE_SSL */ 
    279         } else { 
     282        } else  
    280283                tcp_stream = camel_tcp_stream_raw_new (); 
    281         } 
    282          
    283         if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1)
     284 
     285        if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1)  
     286       
    284287                if (errno == EINTR) 
    285288                        camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, 
    286                                             _("Connection canceled")); 
     289                                _("Connection canceled")); 
    287290                else 
    288291                        camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, 
    289                                              _("Could not connect to %s: %s"), 
    290                                              service->url->host, 
    291                                              g_strerror (errno)); 
     292                                _("Could not connect to %s: %s"), 
     293                                service->url->host, 
     294                                g_strerror (errno)); 
    292295                 
    293296                camel_object_unref (tcp_stream); 
     
    295298                return FALSE; 
    296299        } 
    297          
     300 
    298301        /* parent class connect initialization */ 
    299302        /*if (CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex) == FALSE) { 
     
    301304                return FALSE; 
    302305        }*/ 
    303          
     306 
    304307        if (camel_url_get_param (service->url, "disable_extensions")) 
    305308                flags |= CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS; 
    306          
     309 
    307310        if ((delete_days = (gchar *) camel_url_get_param(service->url,"delete_after")))  
    308311                store->delete_after =  atoi(delete_days); 
    309          
     312 
    310313        if (!(store->engine = camel_pop3_engine_new (tcp_stream, flags))) { 
    311314                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
    312                                      _("Failed to read a valid greeting from POP server %s"), 
    313                                      service->url->host); 
     315                        _("Failed to read a valid greeting from POP server %s"), 
     316                        service->url->host); 
    314317                camel_object_unref (tcp_stream); 
    315318                return FALSE; 
     
    319322        store->engine->partial_happening = FALSE; 
    320323 
    321         if (ssl_mode != MODE_TLS) { 
     324        if (!must_tls && (ssl_mode != MODE_TLS))  
     325        { 
    322326