QByteArray SmtpAuthenticator::getAuthentication(const QMailAccountConfiguration::ServiceConfiguration &svcCfg, const QStringList &capabilities) { QByteArray result(QMailAuthenticator::getAuthentication(svcCfg, capabilities)); if (!result.isEmpty()) return result.prepend("AUTH "); #ifndef QT_NO_SSL SmtpConfiguration smtpCfg(svcCfg); if (smtpCfg.smtpAuthentication() != SmtpConfiguration::Auth_NONE) { QMailAccountId id(smtpCfg.id()); QByteArray username(smtpCfg.smtpUsername().toUtf8()); QByteArray password(smtpCfg.smtpPassword().toUtf8()); if (smtpCfg.smtpAuthentication() == SmtpConfiguration::Auth_LOGIN) { result = QByteArray("LOGIN"); gResponses[id] = (QList<QByteArray>() << username << password); } else if (smtpCfg.smtpAuthentication() == SmtpConfiguration::Auth_PLAIN) { result = QByteArray("PLAIN ") + QByteArray(username + '\0' + username + '\0' + password).toBase64(); gResponses[id] = (QList<QByteArray>() << QByteArray(username + '\0' + username + '\0' + password)); } } #endif if (!result.isEmpty()) { result.prepend("AUTH "); } return result; }
void SmtpClient::newConnection() { qMailLog(SMTP) << "newConnection" << flush; if (sending) { operationFailed(QMailServiceAction::Status::ErrConnectionInUse, tr("Cannot send message; transport in use")); return; } if (!config.id().isValid()) { status = Done; operationFailed(QMailServiceAction::Status::ErrConfiguration, tr("Cannot send message without account configuration")); return; } SmtpConfiguration smtpCfg(config); if ( smtpCfg.smtpServer().isEmpty() ) { status = Done; operationFailed(QMailServiceAction::Status::ErrConfiguration, tr("Cannot send message without SMTP server configuration")); return; } // Calculate the total indicative size of the messages we're sending totalSendSize = 0; foreach (uint size, sendSize.values()) totalSendSize += size; progressSendSize = 0; emit progressChanged(progressSendSize, totalSendSize); status = Init; sending = true; domainName = QByteArray(); outstandingResponses = 0; if (!transport) { // Set up the transport transport = new QMailTransport("SMTP"); connect(transport, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(transport, SIGNAL(connected(QMailTransport::EncryptType)), this, SLOT(connected(QMailTransport::EncryptType))); connect(transport, SIGNAL(bytesWritten(qint64)), this, SLOT(sent(qint64))); connect(transport, SIGNAL(updateStatus(QString)), this, SIGNAL(updateStatus(QString))); connect(transport, SIGNAL(errorOccurred(int,QString)), this, SLOT(transportError(int,QString))); }
void SmtpClient::setAccount(const QMailAccountId &id) { // Load the current configuration for this account config = QMailAccountConfiguration(id); #ifdef USE_ACCOUNTS_QT if (!ssoSessionManager) { SmtpConfiguration smtpCfg(config); ssoSessionManager = new SSOSessionManager(this); if (ssoSessionManager->createSsoIdentity(id, "smtp", smtpCfg.smtpAuthentication())) { ENFORCE(connect(ssoSessionManager, SIGNAL(ssoSessionResponse(QList<QByteArray>)) ,this, SLOT(onSsoSessionResponse(QList<QByteArray>)))); ENFORCE(connect(ssoSessionManager, SIGNAL(ssoSessionError(QString)),this, SLOT(onSsoSessionError(QString)))); qMailLog(SMTP) << Q_FUNC_INFO << "SSO identity is found for account id: "<< id; } else { delete ssoSessionManager; ssoSessionManager = 0; qMailLog(SMTP) << Q_FUNC_INFO << "SSO identity is not found for account id: "<< id << ", accounts configuration will be used"; } } #endif }
void SmtpClient::newConnection() { qMailLog(SMTP) << "newConnection" << flush; #ifdef USE_ACCOUNTS_QT loginFailed = false; #endif if (sending) { operationFailed(QMailServiceAction::Status::ErrConnectionInUse, tr("Cannot send message; transport in use")); return; } if (!config.id().isValid()) { status = Done; operationFailed(QMailServiceAction::Status::ErrConfiguration, tr("Cannot send message without account configuration")); return; } // Load the current configuration for this account // Reload the account configuration whenever a new SMTP // connection is created, in order to ensure the changes // in the account settings are being managed properly. config = QMailAccountConfiguration(config.id()); SmtpConfiguration smtpCfg(config); if ( smtpCfg.smtpServer().isEmpty() ) { status = Done; operationFailed(QMailServiceAction::Status::ErrConfiguration, tr("Cannot send message without SMTP server configuration")); return; } // Calculate the total indicative size of the messages we're sending totalSendSize = 0; foreach (uint size, sendSize.values()) totalSendSize += size; progressSendSize = 0; emit progressChanged(progressSendSize, totalSendSize); status = Init; sending = true; domainName = QByteArray(); outstandingResponses = 0; if (!transport) { // Set up the transport transport = new QMailTransport("SMTP"); connect(transport, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(transport, SIGNAL(connected(QMailTransport::EncryptType)), this, SLOT(connected(QMailTransport::EncryptType))); connect(transport, SIGNAL(bytesWritten(qint64)), this, SLOT(sent(qint64))); connect(transport, SIGNAL(updateStatus(QString)), this, SIGNAL(updateStatus(QString))); connect(transport, SIGNAL(errorOccurred(int,QString)), this, SLOT(transportError(int,QString))); #ifndef QT_NO_OPENSSL connect(transport, SIGNAL(sslErrorOccured(QMailServiceAction::Status::ErrorCode,QString)), this, SIGNAL(connectionError(QMailServiceAction::Status::ErrorCode,QString))); #endif }