Exemplo n.º 1
0
bool mail::imapFetchHandler::taggedMessage(mail::imap &imapAccount, string name,
					   string message,
					   bool okfail, string errmsg)
{
	if (name == getName())
	{
		if (!okfail)
		{
			if (failmsg.size() == 0)
				failmsg=errmsg;
		}

		// Long message sets are broken up.  We need to count the
		// tagged replies received, and only report smashing success
		// (or flaming failure) when the last one comes in.

		--counter;

		if (counter == 0)
		{
			if (failmsg.size() > 0)
				callback.fail(failmsg);
			else
				callback.success(errmsg);
			imapAccount.uninstallHandler(this);
		}
		return true;
	}
	return false;
}
Exemplo n.º 2
0
bool mail::imapDELETE::taggedMessage(mail::imap &imapAccount, string name,
				     string message,
				     bool okfail, string errmsg)
{
	if (name == "DELETE")
	{
		if (okfail)
			callback.success(errmsg);
		else
			callback.fail(errmsg);
		imapAccount.uninstallHandler(this);
		return true;
	}
	return false;
}
Exemplo n.º 3
0
bool mail::imapListHandler::taggedMessage(mail::imap &imapAccount, string name,
					  string message,
					  bool okfail,
					  string errmsg)
{
	if (name != "LIST")
		return false;

	if (okfail && oneFolderOnly && !fallbackOneFolderOnly &&
	    folders.size() == 0)
	{
		fallbackOneFolderOnly=true;
		imapAccount.imapcmd("LIST",
				    "LIST " +
				    imapAccount.quoteSimple(hier)
				    + " \"\"\r\n");
		return true;
	}

	if (okfail)
	{
		vector<const mail::folder *> folderPtrs;

		vector<mail::imapFolder>::iterator b, e;

		b=folders.begin();
		e=folders.end();

		while (b != e)
		{
			if (fallbackOneFolderOnly)
			{
				b->path=hier;
			}

			folderPtrs.push_back( &*b);
			b++;
		}

		callback1.success(folderPtrs);
		callback2.success("OK");
	}
	else
		callback2.fail(errmsg);

	imapAccount.uninstallHandler(this);
	return true;
}
Exemplo n.º 4
0
bool mail::imapCREATE::taggedMessage(mail::imap &imapAccount, string msgname,
				     string message,
				     bool okfail, string errmsg)
{
	if (msgname != "CREATE")
		return false;

	if (!okfail)
	{
		callback2.fail(errmsg);
		imapAccount.uninstallHandler(this);
		return true;
	}

	if (!listHierSent)
	{
		if (hiersep.size() == 0)
		{
			callback2.fail("IMAP server failed to process the LIST command.");
			imapAccount.uninstallHandler(this);
			return true;
		}


		listHierSent=true;
		encodedname=name;

		// The folder name should be utf7-encoded

		{
			char *p=libmail_u_convert_toutf8(encodedname.c_str(),
							 unicode_default_chset(),
							 NULL);

			if (!p && strchr(p, *hiersep[0].getHierSep().c_str())
			    != NULL)
			{
				if (p)
					free(p);
				callback2.fail("Folder name contains an invalid character.");
				imapAccount.uninstallHandler(this);
				return true;
			}
			free(p);


			p=libmail_u_convert_tobuf(encodedname.c_str(),
						  unicode_default_chset(),
						  unicode_x_imap_modutf7,
						  NULL);

			if (p)
			{
				try {
					encodedname=p;
					free(p);
				} catch (...) {
					free(p);
					LIBMAIL_THROW(LIBMAIL_THROW_EMPTY);
				}
			}
		}


		imapAccount.imapcmd("CREATE",
				    (renamePath.size() > 0
				     ? string("RENAME ") +
				     imapAccount.quoteSimple(renamePath) + " ":
				     string("CREATE ")) +
				    imapAccount
				    .quoteSimple(parentPath +
						 encodedname +
						 (!hasMessages ?
						  hiersep[0].getHierSep()
						  :""))
				    + "\r\n");
		return true;

	}

	mail::imapFolder new_folder(imapAccount, parentPath + encodedname,
				    hiersep[0].getHierSep(),
				    name, -1);

	new_folder.hasMessages(hasMessages);
	new_folder.hasSubFolders(hasSubfolders);

	vector<const mail::folder *> dummy_list;

	dummy_list.push_back(&new_folder);

	callback1.success(dummy_list);
	callback2.success(errmsg);
	imapAccount.uninstallHandler(this);
	return true;
}