Commit 7a94c1de authored by Sam Varshavchik's avatar Sam Varshavchik

cone: utf8 imap update.

parent f034b6b5
......@@ -303,7 +303,7 @@ void mail::imap::insertHandler(mail::imapHandler *handler)
LIBMAIL_THROW("mail::imap:: out of memory.");
const char *name=handler->getName();
if (handlers.count(name) > 0)
{
mail::imapHandler *oldHandler=
......@@ -581,6 +581,9 @@ int mail::imap::socketRead(const string &readbuffer)
upper(msg);
if (msg == "ENABLED")
return processedCnt;
if (msg == "CAPABILITY")
{
clearCapabilities();
......@@ -718,6 +721,18 @@ void mail::imap::setCapability(string status)
capabilities.insert(status);
}
const char *mail::imap::folder_chset()
{
return utf8_enabled() ? unicode_x_smap_modutf8:unicode_x_imap_modutf7;
}
bool mail::imap::utf8_enabled()
{
return hasCapability("ENABLE") &&
(hasCapability("UTF8=ACCEPT") ||
hasCapability("UTF8=ONLY"));
}
bool mail::imap::hasCapability(string status)
{
upper(status);
......@@ -1450,7 +1465,7 @@ void mail::imapFolderHeadersCallback
if (!prevWasNewline && !prevFoldingSpace)
cpy.insert(cpy.end(), c, b);
originalCallback.messageTextCallback(n, cpy);
}
......@@ -1677,7 +1692,7 @@ int mail::imapCommandHandler::process(mail::imap &imapAccount, string &buffer)
okfailWord == "OK", errmsg) ? p+1:0;
// Report any accumulated server messages in the response
if (!acctPtr.isDestroyed() && acctPtr->serverMsgs.size() > 0)
{
vector<string>::iterator b, e;
......
......@@ -234,6 +234,9 @@ public:
bool hasCapability(std::string capability);
std::string getCapability(std::string capability);
bool utf8_enabled();
const char *folder_chset();
std::string servertype;
std::string serverdescr;
......
......@@ -66,6 +66,7 @@ class imapGetMyRights::listMyRights : private vector<imapFolder>,
public:
listMyRights(string folderNameArg,
const char *folder_chset,
string &rightsArg);
~listMyRights();
......@@ -91,7 +92,7 @@ void mail::imapGetMyRights::installed(imap &imapAccount)
if (imapAccount.getCapability("ACL") == "ACL")
{
/* ACL 1 */
imapAccount.imapcmd("MYRIGHTS",
"MYRIGHTS "
+ imapAccount.quoteSimple(folderName)
......@@ -131,6 +132,8 @@ bool mail::imapGetMyRights::untaggedMessage(imap &imapAccount,
{
imapAccount
.installBackgroundTask(new listMyRights(folderName,
imapAccount
.folder_chset(),
rights));
return true;
}
......@@ -225,8 +228,9 @@ void mail::imapGetMyRights::parseMyRights::getRights(imap &imapAcct, Token t)
/* ---- Parse ACL2 LIST(MYRIGHTS) response ----- */
mail::imapGetMyRights::listMyRights::listMyRights(string folderNameArg,
const char *folder_chset,
string &rightsArg)
: imapLIST( *this, 0), folderName(folderNameArg),
: imapLIST( *this, 0, folder_chset), folderName(folderNameArg),
rights(rightsArg)
{
}
......@@ -319,6 +323,7 @@ class mail::imapGetRights::listGetRights : private vector<mail::imapFolder>,
public:
listGetRights(string folderNameArg,
const char *folder_chset,
list<pair< string, string> > &rightsArg);
~listGetRights();
......@@ -342,7 +347,7 @@ void mail::imapGetRights::installed(imap &imapAccount)
if (imapAccount.getCapability("ACL") == "ACL")
{
/* ACL 1 */
imapAccount.imapcmd("GETACL",
"GETACL "
+ imapAccount.quoteSimple(folderName)
......@@ -373,8 +378,11 @@ bool mail::imapGetRights::untaggedMessage(imap &imapAccount, string msgname)
if (msgname == "LIST")
{
imapAccount
.installBackgroundTask(new listGetRights(folderName,
rights));
.installBackgroundTask(new
listGetRights(folderName,
imapAccount
.folder_chset(),
rights));
return true;
}
......@@ -507,8 +515,9 @@ void mail::imapGetRights::parseGetRights::getRights(imap &imapAcct, Token t)
mail::imapGetRights
::listGetRights::listGetRights(string folderNameArg,
const char *folder_chset,
list<pair<string,string> > &rightsArg)
: imapLIST(*this, 0), folderName(folderNameArg),
: imapLIST(*this, 0, folder_chset), folderName(folderNameArg),
rights(rightsArg)
{
}
......@@ -746,6 +755,8 @@ bool mail::imapSetRights::untaggedMessage(imap &imapAccount, string msgname)
imapAccount
.installBackgroundTask(new imapGetRights
::listGetRights(folderName,
imapAccount
.folder_chset(),
dummy_rights));
return true;
}
......
......@@ -390,8 +390,11 @@ bool mail::imapCREATE::untaggedMessage(mail::imap &imapAccount, string msgname)
if (msgname == "LIST") // Untagged LIST replies
{
hiersep.clear();
imapAccount.installBackgroundTask( new mail::imapLIST(hiersep,
0, true));
imapAccount.installBackgroundTask( new mail::imapLIST
(hiersep,
0,
imapAccount.folder_chset(),
true));
return true;
}
return false;
......@@ -444,9 +447,9 @@ bool mail::imapCREATE::taggedMessage(mail::imap &imapAccount, string msgname,
p=unicode_convert_tobuf(encodedname.c_str(),
unicode_default_chset(),
unicode_x_imap_modutf7,
NULL);
unicode_default_chset(),
imapAccount.folder_chset(),
NULL);
if (p)
{
......@@ -515,7 +518,7 @@ public:
void timedOut(const char *errmsg);
bool untaggedMessage(imap &imapAccount, string msgname);
bool taggedMessage(imap &imapAccount, string msgname,
string message,
bool okfail, string errmsg);
......@@ -553,7 +556,7 @@ bool mail::imapRECREATE::untaggedMessage(mail::imap &imapAccount, string msgname
{
return false;
}
bool mail::imapRECREATE::taggedMessage(mail::imap &imapAccount, string msgname,
string message,
bool okfail, string errmsg)
......
......@@ -35,7 +35,9 @@ void mail::imap::readSubFolders(string path,
else
{
mail::imapListHandler *h=
new mail::imapListHandler(callback1, callback2, path,
new mail::imapListHandler(callback1, callback2,
folder_chset(),
path,
false);
installForegroundTask(h);
}
......@@ -69,6 +71,7 @@ void mail::imap::findFolder(string folder,
callback2)
: new mail::imapListHandler(callback1,
callback2,
folder_chset(),
folder,
true));
}
......@@ -78,8 +81,8 @@ string mail::imap::translatePath(string path)
if (!smap)
{
char *p=unicode_convert_tobuf(path.c_str(),
unicode_default_chset(),
unicode_x_imap_modutf7, NULL);
unicode_default_chset(),
folder_chset(), NULL);
if (p)
{
......@@ -236,9 +239,11 @@ string mail::imap::translatePath(string path)
mail::imapListHandler::
imapListHandler(mail::callback::folderList &myCallback,
mail::callback &myCallback2,
string myHier, bool oneFolderOnlyArg)
mail::callback &myCallback2,
const char *folder_chset,
string myHier, bool oneFolderOnlyArg)
: callback1(myCallback), callback2(myCallback2), hier(myHier),
folder_chset(folder_chset),
oneFolderOnly(oneFolderOnlyArg), fallbackOneFolderOnly(false)
{
}
......@@ -273,8 +278,9 @@ bool mail::imapListHandler::untaggedMessage(mail::imap &imapAccount, string name
if (name != "LIST")
return false;
imapAccount.installBackgroundTask( new mail::imapLIST(folders,
hier.length(),
oneFolderOnly));
hier.length(),
folder_chset,
oneFolderOnly));
return true;
}
......@@ -332,13 +338,14 @@ bool mail::imapListHandler::taggedMessage(mail::imap &imapAccount, string name,
// Untagged LIST parser
mail::imapLIST::imapLIST(vector<mail::imapFolder> &mylist,
size_t pfixLengthArg,
bool oneNameOnlyArg)
size_t pfixLengthArg,
const char *folder_chset,
bool oneNameOnlyArg)
: folderList(mylist), pfixLength(pfixLengthArg),
oneNameOnly(oneNameOnlyArg),
next_func(&mail::imapLIST::start_attribute_list),
hasChildren(false), hasNoChildren(false), marked(false),
unmarked(false), noSelect(false)
unmarked(false), noSelect(false), folder_chset(folder_chset)
{
}
......@@ -436,7 +443,7 @@ void mail::imapLIST::get_name(mail::imap &imapAccount, Token t)
nameVal.erase(0, pfixLength);
}
char *p=unicode_convert_tobuf(nameVal.c_str(),
unicode_x_imap_modutf7,
folder_chset,
unicode_default_chset(),
NULL);
......
......@@ -24,6 +24,7 @@ class imapListHandler : public imapCommandHandler {
mail::callback::folderList &callback1;
mail::callback &callback2;
std::string hier;
const char *folder_chset;
bool oneFolderOnly;
bool fallbackOneFolderOnly;
......@@ -36,8 +37,9 @@ class imapListHandler : public imapCommandHandler {
public:
imapListHandler(mail::callback::folderList &myCallback,
mail::callback &myCallback2,
std::string myHier, bool oneFolderOnlyArg);
mail::callback &myCallback2,
const char *folder_chset,
std::string myHier, bool oneFolderOnlyArg);
~imapListHandler();
const char *getName();
void timedOut(const char *errmsg);
......@@ -64,11 +66,14 @@ class imapLIST : public imapHandlerStructured {
bool hasChildren, hasNoChildren, marked, unmarked, noSelect;
std::string hiersep;
const char *folder_chset;
protected:
imapparsefmt xattributes;
public:
imapLIST(std::vector<imapFolder> &mylist, size_t pfixLengthArg,
bool oneNameOnlyArg=false);
const char *folder_chset,
bool oneNameOnlyArg=false);
~imapLIST();
void installed(imap &imapAccount);
......
......@@ -59,6 +59,9 @@ private:
void loginCallbackUid(std::string);
void loginCallbackPwd(std::string);
void initialize_namespaces(mail::imap &imapAccount,
std::string message);
public:
imapLoginHandler(mail::loginInfo myLoginInfo,
bool preauthenticatedArg);
......@@ -833,34 +836,25 @@ bool mail::imapLoginHandler::taggedMessage(mail::imap &imapAccount, string name,
}
else
{
imapAccount.namespaces
.push_back(mail::imapFolder(imapAccount,
"INBOX", "",
"INBOX", -1));
if (imapAccount.hasCapability("NAMESPACE"))
imapAccount.imapcmd("NAMESPACE",
"NAMESPACE\r\n");
if (imapAccount.utf8_enabled())
{
imapAccount.imapcmd("ENABLEUTF8",
"ENABLE UTF8=ACCEPT\r\n");
}
else
{
mail::imapFolder f(imapAccount, "",
"",
"Folders",
0);
f.hasMessages(false);
f.hasSubFolders(true);
imapAccount.namespaces.push_back(f);
completed=1;
mail::callback *callback=
myLoginInfo.callbackPtr;
imapAccount.uninstallHandler(this);
callback->success(message);
initialize_namespaces(imapAccount, message);
}
}
return (true);
}
if (name == "ENABLEUTF8")
{
initialize_namespaces(imapAccount, message);
return true;
}
if (name == "NAMESPACE")
{
vector <mail::imapFolder>::iterator b, e, save;
......@@ -931,6 +925,34 @@ bool mail::imapLoginHandler::taggedMessage(mail::imap &imapAccount, string name,
return (false);
}
void mail::imapLoginHandler::initialize_namespaces(mail::imap &imapAccount,
std::string message)
{
imapAccount.namespaces.push_back(mail::imapFolder(imapAccount,
"INBOX", "",
"INBOX", -1));
if (imapAccount.hasCapability("NAMESPACE"))
imapAccount.imapcmd("NAMESPACE", "NAMESPACE\r\n");
else
{
mail::imapFolder f(imapAccount, "",
"",
"Folders",
0);
f.hasMessages(false);
f.hasSubFolders(true);
imapAccount.namespaces.push_back(f);
completed=1;
mail::callback *callback=
myLoginInfo.callbackPtr;
imapAccount.uninstallHandler(this);
callback->success(message);
}
}
//////////////////////////////////////////////////////////////////////////
//
// CRAM handling
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment