コード例 #1
0
ファイル: cPop3.cpp プロジェクト: trimpsyw/vmime
// private
void cPop3::Connect()
{
    if (mi_Inbox)
        return;

    const char* s8_Protocol;
    if (me_Security == cCommon::Secur_SSL) s8_Protocol = "pop3s";
    else                                   s8_Protocol = "pop3";

    if (mu16_Port == 0)
        mu16_Port = utility::url::UNSPECIFIED_PORT;

    utility::url i_Url(s8_Protocol, ms_Server, mu16_Port, "", ms_User, ms_Password);

    mi_Session = create <net::session>();
    mi_Store   = mi_Session->getStore(i_Url);

    ref <cCertVerifier> i_Verifier = create<cCertVerifier>(mb_AllowInvalidCerts, mu16_ResIdCert);
    mi_Store->setCertificateVerifier(i_Verifier);
    mi_Store->setTimeoutHandlerFactory(create<TimeoutFactory>());

    if (ms_User.length() || ms_Password.length())
    {
        mi_Store->setProperty("options.need-authentication", true);
    }

    if (me_Security == cCommon::Secur_TLS_opt || me_Security == cCommon::Secur_TLS_force)
    {
        mi_Store->setProperty("connection.tls", true); // use STLS
    }

    if (me_Security == cCommon::Secur_TLS_force)
    {
        mi_Store->setProperty("connection.tls.required", true);
    }

    // Try to authenticate via APOP (disabled)
    // Requires that the server sends a greeting like:
    // +OK POP3 server ready <*****@*****.**>
    // which is parsed as "<" id-left "@" id-right ">" 
    // otherwise APOP is not executed. 
    // Most servers do not send this type of greeting.
    mi_Store->setProperty("store.pop3.options.apop", false);
    // Some servers close the connection after an unsuccessful APOP command, 
    // so the fallback may not always work!
    mi_Store->setProperty("store.pop3.options.apop.fallback", true);

    // Send commands "USER" and "PASS" to the server if SASL fails
    mi_Store->setProperty("options.sasl.fallback", true);

    #if VMIME_TRACE
        TRACE("POP3 Using vmime %s", VMIME_VERSION);
    #endif

    mi_Store->connect();

    mi_Inbox = mi_Store->getDefaultFolder();
    mi_Inbox->open(net::folder::MODE_READ_WRITE);
}
コード例 #2
0
ファイル: cSmtp.cpp プロジェクト: trimpsyw/vmime
// throws
void cSmtp::Send(cEmailBuilder* pi_Email)
{
    try
    {
        const char* s8_Protocol;
        if (me_Security == cCommon::Secur_SSL) s8_Protocol = "smtps";
        else                                   s8_Protocol = "smtp";

        if (mu16_Port == 0)
        {
            if (me_Security == cCommon::Secur_TLS_force) 
                mu16_Port = 587;
            else
                mu16_Port = utility::url::UNSPECIFIED_PORT;
        }

        utility::url i_Url(s8_Protocol, ms_Server, mu16_Port, "", ms_User, ms_Password);

        ref <net::session>   i_Session = create <net::session>();
	    ref <net::transport> i_Transp  = i_Session->getTransport(i_Url);

        ref <cCertVerifier> i_Verifier = create<cCertVerifier>(mb_AllowInvalidCerts, mu16_ResIdCert);
        i_Transp->setCertificateVerifier(i_Verifier);
        i_Transp->setTimeoutHandlerFactory(create<TimeoutFactory>());

        if (ms_User.length() || ms_Password.length())
        {
            i_Transp->setProperty("options.need-authentication", true);
        }

        if (me_Security == cCommon::Secur_TLS_opt || me_Security == cCommon::Secur_TLS_force)
        {
            i_Transp->setProperty("connection.tls", true); // use STARTTLS
        }

        if (me_Security == cCommon::Secur_TLS_force)
        {
            i_Transp->setProperty("connection.tls.required", true);
        }

        // "options.sasl.fallback" not available for SMTP

        TraceProgress i_Progress(1000, "SMTP"); // Trace progress once a second

        #if VMIME_TRACE
            TRACE("SMTP Using vmime %s", VMIME_VERSION);
        #endif

	    i_Transp->connect();
        i_Transp->send(pi_Email->BuildMessage(), &i_Progress);
        i_Transp->disconnect();
    }
    catch (...)
    {
        // http://stackoverflow.com/questions/21346400/destructors-not-executed-no-stack-unwinding-when-exception-is-thrown
        throw; 
    }
}
コード例 #3
0
// private
void cImap::Connect()
{
    if (mi_Store)
        return;

    const char* s8_Protocol;
    if (me_Security == cCommon::Secur_SSL) s8_Protocol = "imaps";
    else                                   s8_Protocol = "imap";

    if (mu16_Port == 0)
        mu16_Port = utility::url::UNSPECIFIED_PORT;

    utility::url i_Url(s8_Protocol, ms_Server, mu16_Port, "", ms_User, ms_Password);

    mi_Session = create <net::session>();

    ref<net::store> i_NewStore = mi_Session->getStore(i_Url);

    ref <cCertVerifier> i_Verifier = create<cCertVerifier>(mb_AllowInvalidCerts, mu16_ResIdCert);
    i_NewStore->setCertificateVerifier(i_Verifier);
    i_NewStore->setTimeoutHandlerFactory(create<TimeoutFactory>());

    if (ms_User.length() || ms_Password.length())
    {
        i_NewStore->setProperty("options.need-authentication", true);
    }

    if (me_Security == cCommon::Secur_TLS_opt || me_Security == cCommon::Secur_TLS_force)
    {
        i_NewStore->setProperty("connection.tls", true); // use STLS
    }

    if (me_Security == cCommon::Secur_TLS_force)
    {
        i_NewStore->setProperty("connection.tls.required", true);
    }

    // Send commands "USER" and "PASS" to the server if SASL fails
    i_NewStore->setProperty("options.sasl.fallback", true);

#if VMIME_TRACE
    TRACE("IMAP Using vmime %s", VMIME_VERSION);
#endif

    i_NewStore->connect();
    mi_Store = i_NewStore;
}