diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /libmail/imaplogout.C | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'libmail/imaplogout.C')
| -rw-r--r-- | libmail/imaplogout.C | 143 | 
1 files changed, 143 insertions, 0 deletions
diff --git a/libmail/imaplogout.C b/libmail/imaplogout.C new file mode 100644 index 0000000..b509da2 --- /dev/null +++ b/libmail/imaplogout.C @@ -0,0 +1,143 @@ +/* +** Copyright 2002-2004, Double Precision Inc. +** +** See COPYING for distribution information. +*/ +#include "imap.H" +#include "misc.H" +#include "imapfolder.H" +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> +#include <stdio.h> + +#include <iostream> + +using namespace std; + +LIBMAIL_START + +///////////////////////////////////////////////////////////////////////// +// +// The LOGOUT command + +class imapLogoutHandler : public imapHandler { + +	bool eatEverything; + +private: +	mail::callback &callback; +	bool orderlyShutdown; + +	void dologout(imap &imapAccount, mail::callback &callback); + +	const char *getName(); +	void timedOut(const char *errmsg); +	void installed(imap &imapAccount); + +public: +	imapLogoutHandler(mail::callback &myCallback); +	~imapLogoutHandler(); +	int process(imap &imapAccount, string &buffer); +} ; +LIBMAIL_END + +////////////////////////////////////////////////////////////////////////////// +// +// Logging out. + +void mail::imap::logout(mail::callback &callback) +{ +	if (!socketConnected()) +        { +                callback.success("Already logged out."); +                return; +        } + +	orderlyShutdown=true; + +	if (currentFolder) +		currentFolder->closeInProgress=true; + +	installForegroundTask(new mail::imapLogoutHandler(callback)); +} + +int mail::imapLogoutHandler::process(mail::imap &imapAccount, string &buffer) +{ +	if (eatEverything) +		return buffer.size(); + +	size_t p=buffer.find('\n'); + +	if (p == std::string::npos) +	{ +		if (buffer.size() > 16000) +			return buffer.size() - 16000; +		// SANITY CHECK - DON'T LET HOSTILE SERVER DOS us +		return (0); +	} + +	string buffer_cpy=buffer; + +	buffer_cpy.erase(p); +	++p; + +	string::iterator b=buffer_cpy.begin(); +	string::iterator e=buffer_cpy.end(); +	string word=imapAccount.get_cmdreply(&b, &e); + +	upper(word); + +	if (word == (imapAccount.smap ? "+OK":"LOGOUT")) +		dologout(imapAccount, callback); + +	return p; +} + +const char *mail::imapLogoutHandler::getName() +{ +	return "LOGOUT"; +} + +void mail::imapLogoutHandler::timedOut(const char *errmsg) +{ +	callback.success(errmsg ? errmsg:"Timed out."); +} + +void mail::imapLogoutHandler::installed(mail::imap &imapAccount) +{ +	if (imapAccount.smap) +		imapAccount.imapcmd("", "LOGOUT\n"); +	else +		imapAccount.imapcmd("LOGOUT", "LOGOUT\r\n"); +} + +mail::imapLogoutHandler::imapLogoutHandler(mail::callback &myCallback) +		: eatEverything(false), +		  callback(myCallback), orderlyShutdown(false) +{ +} + +mail::imapLogoutHandler::~imapLogoutHandler() +{ +	if (!orderlyShutdown) +		callback.success("Logged out."); +} + +#include <fstream> + +void mail::imapLogoutHandler::dologout(mail::imap &imapAccount, +				       mail::callback &c) +{ +	if (!imapAccount.socketEndEncryption()) +	{ +		orderlyShutdown=true; +		imapAccount.uninstallHandler(this); +		c.success("Logged out."); +	} +	else +	{ +		eatEverything=true; +	} +}  | 
