summaryrefslogtreecommitdiff
path: root/src/imapserver.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/imapserver.cc')
-rw-r--r--[-rwxr-xr-x]src/imapserver.cc90
1 files changed, 38 insertions, 52 deletions
diff --git a/src/imapserver.cc b/src/imapserver.cc
index 2980d9b..4ec646d 100755..100644
--- a/src/imapserver.cc
+++ b/src/imapserver.cc
@@ -2,13 +2,14 @@
* @file imapserver.cc
* @brief Implementation of the IMAPServer class.
* @author Andreas Aardal Hanssen
- * @date 2005
+ * @date 2005
* --------------------------------------------------------------------
*/
+#include "imapserver.h"
+
#include "broker.h"
#include "globals.h"
#include "imapparser.h"
-#include "imapserver.h"
#include "iodevice.h"
#include "iofactory.h"
#include "session.h"
@@ -28,9 +29,7 @@ IMAPServer::IMAPServer(int argc, char **argv)
Session::getInstance().setState(Session::AUTHENTICATED);
}
-IMAPServer::~IMAPServer(void)
-{
-}
+IMAPServer::~IMAPServer(void) {}
int IMAPServer::initialize(void)
{
@@ -41,14 +40,14 @@ int IMAPServer::initialize(void)
void IMAPServer::prepareForNextRequest(void)
{
- serverStatus = OK;
+ serverStatus = OK;
- bincClient.setFlags(IODevice::HasInputLimit);
- bincClient.flush();
- bincClient.setMaxInputBufferSize(INPUT_BUFFER_LIMIT);
+ bincClient.setFlags(IODevice::HasInputLimit);
+ bincClient.flush();
+ bincClient.setMaxInputBufferSize(INPUT_BUFFER_LIMIT);
- Session::getInstance().setLastError("");
- Session::getInstance().clearResponseCode();
+ Session::getInstance().setLastError("");
+ Session::getInstance().clearResponseCode();
}
int IMAPServer::runStub(void)
@@ -68,15 +67,12 @@ int IMAPServer::run(void)
bincDebug << "IMAPServer::run(), started server" << endl;
if (this->stubMode) {
- if (session.hasEnv("PROTOCOLDUMP"))
- bincClient.enableProtocolDumping();
- bincLog << "bincimap-up: pid " << pid
- << " Connected: <" << session.getIP() << ">\n";
+ if (session.hasEnv("PROTOCOLDUMP")) bincClient.enableProtocolDumping();
+ bincLog << "bincimap-up: pid " << pid << " Connected: <" << session.getIP() << ">\n";
showGreeting();
} else {
- bincLog << "bincimapd: pid " << pid
- << " Logged in: <" << session.getEnv("USER")
- << "@" << session.getEnv("TCPREMOTEIP") << ">\n";
+ bincLog << "bincimapd: pid " << pid << " Logged in: <" << session.getEnv("USER") << "@"
+ << session.getEnv("TCPREMOTEIP") << ">\n";
}
bincLog.flush();
@@ -89,8 +85,8 @@ int IMAPServer::run(void)
BrokerFactory &brokerFactory = BrokerFactory::getInstance();
Broker *broker = brokerFactory.getBroker(session.getState());
- bincDebug << "IMAPServer::run(), found broker " << (uintptr_t) broker
- << " for state " << session.getState() << endl;
+ bincDebug << "IMAPServer::run(), found broker " << (uintptr_t)broker << " for state "
+ << session.getState() << endl;
bool skipToNextRequest = false;
@@ -112,16 +108,16 @@ int IMAPServer::run(void)
serverStatus = RequestRejected;
string err = "The command \"";
if (clientRequest.getUidMode()) err += "UID ";
- err += clientRequest.getName();
- err += "\" is unsupported in this state. ";
- session.setLastError(err);
- skipToNextRequest = true;
+ err += clientRequest.getName();
+ err += "\" is unsupported in this state. ";
+ session.setLastError(err);
+ skipToNextRequest = true;
} else {
int parseResult = o->parse(clientRequest);
if (parseResult == Operator::TIMEOUT) {
serverStatus = Timeout;
} else if (parseResult == Operator::REJECT) {
- serverStatus = RequestRejected;
+ serverStatus = RequestRejected;
} else if (parseResult == Operator::ERROR) {
serverStatus = RequestError;
} else {
@@ -131,11 +127,11 @@ int IMAPServer::run(void)
int processResult = o->process(*dep, clientRequest);
if (processResult == Operator::OK) {
} else if (processResult == Operator::NO) {
- serverStatus = RequestRejected;
+ serverStatus = RequestRejected;
} else if (processResult == Operator::BAD) {
- serverStatus = RequestError;
+ serverStatus = RequestError;
} else if (processResult == Operator::NOTHING) {
- serverStatus = RequestIgnore; // answer given already
+ serverStatus = RequestIgnore; // answer given already
} else if (processResult == Operator::ABORT) {
session.setState(Session::LOGOUT);
}
@@ -146,21 +142,17 @@ int IMAPServer::run(void)
// If a syntax error was detected, we skip all characters in the
// input stream up to and including '\n'.
if (serverStatus == RequestRejected) {
- bincClient << clientRequest.getTag() << " NO "
- << session.getResponseCode()
- << clientRequest.getName() << " failed: "
- << session.getLastError() << endl;
+ bincClient << clientRequest.getTag() << " NO " << session.getResponseCode()
+ << clientRequest.getName() << " failed: " << session.getLastError() << endl;
} else if (serverStatus == RequestError) {
- bincClient << "* BAD "
- << session.getLastError() << endl;
+ bincClient << "* BAD " << session.getLastError() << endl;
skipToNextRequest = true;
} else if (serverStatus == RequestIgnore) {
- ;
+ ;
} else if (serverStatus == OK && session.getState() != Session::LOGOUT) {
bincClient << clientRequest.getTag() << " OK";
if (clientRequest.getUidMode()) bincClient << " UID";
- bincClient << " " << session.getResponseCode()
- << clientRequest.getName() << " completed";
+ bincClient << " " << session.getResponseCode() << clientRequest.getName() << " completed";
if (clientRequest.getContextInfo() != "")
bincClient << " (" << clientRequest.getContextInfo() << ")";
@@ -181,38 +173,32 @@ int IMAPServer::run(void)
break;
}
}
- } while (session.getState() != Session::LOGOUT); // do line 81
+ } while (session.getState() != Session::LOGOUT); // do line 81
// Session finished - write some log information
string userID = this->stubMode ? session.getIP() : session.getEnv("USER");
if (this->stubMode) {
- bincLog << "bincimap-up: pid " << pid
- << " (Read: " << session.getReadBytes()
+ bincLog << "bincimap-up: pid " << pid << " (Read: " << session.getReadBytes()
<< " Written: " << session.getWriteBytes() << ")\n";
} else {
- bincLog << "bincimapd: pid " << pid
- << " (Bodies: " << session.getBodies()
+ bincLog << "bincimapd: pid " << pid << " (Bodies: " << session.getBodies()
<< " Statements: " << session.getStatements() << ")\n";
}
if (serverStatus == Timeout) {
- bincClient << "* BYE Timeout after " << session.timeout()
- << " seconds of inactivity\n";
+ bincClient << "* BYE Timeout after " << session.timeout() << " seconds of inactivity\n";
bincClient.flush();
- bincLog << "bincimapd: pid " << pid
- << " Timed out: <" << userID << "> after " << IDLE_TIMEOUT << "s";
+ bincLog << "bincimapd: pid " << pid << " Timed out: <" << userID << "> after " << IDLE_TIMEOUT
+ << "s";
} else if (serverStatus == ClientDisconnected) {
- bincLog << "bincimapd: pid " << pid
- << "Disconnected: <" << userID << ">\n";
+ bincLog << "bincimapd: pid " << pid << "Disconnected: <" << userID << ">\n";
} else {
if (this->stubMode) {
- bincLog << "bincimap-up: pid " << pid
- << " Logged out: <" << userID << ">\n";
+ bincLog << "bincimap-up: pid " << pid << " Logged out: <" << userID << ">\n";
} else {
- bincLog << "bincimapd: pid " << pid
- << " Disconnected: <" << userID << ">\n";
+ bincLog << "bincimapd: pid " << pid << " Disconnected: <" << userID << ">\n";
}
}
bincLog.flush();