Hello guys, I am a newbie in this forum and try to learn Poco for two days.
I've found that in loginUsingLogin, Poco just verified the base64 encoded "Username: " server reply, but some mail server will give back "username:" reply.
So I try to modify the code like this:
bool ci_equal(char ch1, char ch2)
{
return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
}
size_t ci_find(const std::string& str1, const std::string& str2)
{
std::string::const_iterator pos = std::search(str1.begin ( ), str1.end ( ), str2.begin ( ), str2.end ( ), ci_equal);
if (pos == str1.end ( ))
return std::string::npos;
else
return pos - str1.begin ( );
}
void SMTPClientSession::loginUsingLogin(const std::string& username, const std::string& password)
{
int status = 0;
std::string response;
status = sendCommand("AUTH LOGIN", response);
if (!isPositiveIntermediate(status)) throw SMTPException("Cannot authenticate LOGIN", response);
std::ostringstream usernameBase64;
Base64Encoder usernameEncoder(usernameBase64);
usernameEncoder << username;
usernameEncoder.close();
std::ostringstream passwordBase64;
Base64Encoder passwordEncoder(passwordBase64);
passwordEncoder << password;
passwordEncoder.close();
//Server request for username/password not defined could be either
//S: login:
//C: user_login
//S: password:
//C: user_password
//or
//S: password:
//C: user_password
//S: login:
//C: user_login
if (response.length() < 4)
{
return;
}
std::string strCommand = response.substr(4);
std::istringstream istrCommand(strCommand);
Base64Decoder commandDecoder(istrCommand);
std::string commandBase64;
commandDecoder >> commandBase64;
std::string strUsername("username:");
std::string strPassword("password:");
if (ci_find(commandBase64, strUsername) != std::string::npos) // username first (md5("Username:"))
{
status = sendCommand(usernameBase64.str(), response);
if (!isPositiveIntermediate(status)) throw SMTPException("Login using LOGIN user name failed", response);
status = sendCommand(passwordBase64.str(), response);
if (!isPositiveCompletion(status)) throw SMTPException("Login using LOGIN password failed", response);
}
else if (ci_find(commandBase64, strPassword) != std::string::npos) // password first (md5("Password:"))
{
status = sendCommand(passwordBase64.str(), response);
if (!isPositiveIntermediate(status)) throw SMTPException("Login using LOGIN password failed", response);
status = sendCommand(usernameBase64.str(), response);
if (!isPositiveCompletion(status)) throw SMTPException("Login using LOGIN user name failed", response);
}
}
just compare the base64 decoded string in case-insensitive mode!
Now i try to resolve another problem , I want to add some unicode content ,but I can not find any interface of that, I tried:
contentPart = new StringPartSource(strContent, "text/plain; charset="UTF-8"");
message.addContent(contentPart);
but I just received some wrong mail like this:
Content-Type: text/plain; charset=UTF-8
It should be like this:
Content-Type: text/plain; charset="UTF-8"
but the quate and split function in MessageHeader.cpp make this impossible. Any one can help me?
I





