summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2023-10-07 18:49:13 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2023-10-08 11:35:51 +0200
commit3b1278f5459514a6d6364f068ff97b8a0432057b (patch)
tree6e1369f28c64b45ac3254225242ebf3844ad0291
parentc0234d1b0cea8ac830e9397da8b2270a8f2b45ca (diff)
formatted source and header files
-rw-r--r--src/address.cc5
-rw-r--r--src/argparser.cc81
-rw-r--r--src/authenticate.cc161
-rw-r--r--src/base64.cc28
-rw-r--r--src/bincimap-up.cc4
-rw-r--r--src/bincimap-updatecache.cc13
-rw-r--r--src/bincimapd.cc4
-rw-r--r--src/broker.cc116
-rw-r--r--src/convert.cc27
-rw-r--r--src/depot.cc200
-rw-r--r--src/greeting.cc18
-rw-r--r--src/imapparser.cc70
-rw-r--r--[-rwxr-xr-x]src/imapserver.cc90
-rw-r--r--src/include/argparser.h14
-rw-r--r--src/include/authenticate.h10
-rw-r--r--src/include/broker.h12
-rw-r--r--src/include/convert.h109
-rw-r--r--src/include/depot.h11
-rw-r--r--src/include/globals.h10
-rw-r--r--src/include/imapparser.h23
-rw-r--r--src/include/imapserver.h2
-rw-r--r--src/include/iodevice.h54
-rw-r--r--src/include/iofactory.h37
-rw-r--r--src/include/mailbox.h48
-rw-r--r--src/include/maildir.h53
-rw-r--r--src/include/maildirmessage.h42
-rw-r--r--src/include/message.h43
-rw-r--r--src/include/mime-inputsource.h32
-rw-r--r--src/include/mime-utils.h10
-rw-r--r--src/include/mime.h96
-rw-r--r--src/include/operators.h96
-rw-r--r--src/include/pendingupdates.h38
-rw-r--r--src/include/recursivedescent.h8
-rw-r--r--src/include/session.h18
-rw-r--r--src/include/status.h73
-rw-r--r--src/include/stdiodevice.h4
-rw-r--r--src/include/syslogdevice.h8
-rw-r--r--src/iodevice.cc49
-rw-r--r--src/iofactory.cc18
-rw-r--r--src/mailbox.cc32
-rw-r--r--src/maildir-close.cc10
-rw-r--r--src/maildir-create.cc37
-rw-r--r--src/maildir-delete.cc21
-rw-r--r--src/maildir-expunge.cc20
-rw-r--r--src/maildir-readcache.cc28
-rw-r--r--src/maildir-scan.cc191
-rw-r--r--src/maildir-scanfilesnames.cc15
-rw-r--r--src/maildir-select.cc8
-rw-r--r--src/maildir-updateflags.cc43
-rw-r--r--src/maildir-writecache.cc23
-rw-r--r--src/maildir.cc387
-rw-r--r--src/maildirmessage.cc543
-rw-r--r--src/mime-getpart.cc31
-rw-r--r--src/mime-parsefull.cc160
-rw-r--r--src/mime-parseonlyheader.cc34
-rw-r--r--src/mime-printbody.cc28
-rw-r--r--src/mime-printdoc.cc22
-rw-r--r--src/mime-printheader.cc43
-rw-r--r--src/mime.cc41
-rw-r--r--src/multilogdevice.cc24
-rw-r--r--src/operator-append.cc101
-rw-r--r--src/operator-authenticate.cc130
-rw-r--r--src/operator-capability.cc35
-rw-r--r--src/operator-check.cc27
-rw-r--r--src/operator-close.cc18
-rw-r--r--src/operator-copy.cc48
-rw-r--r--src/operator-create.cc21
-rw-r--r--src/operator-delete.cc25
-rw-r--r--src/operator-examine.cc8
-rw-r--r--src/operator-expunge.cc36
-rw-r--r--src/operator-fetch.cc283
-rw-r--r--src/operator-id.cc23
-rw-r--r--src/operator-idle.cc84
-rw-r--r--src/operator-list.cc60
-rw-r--r--src/operator-login.cc43
-rw-r--r--src/operator-logout.cc38
-rw-r--r--src/operator-lsub.cc49
-rw-r--r--src/operator-namespace.cc26
-rw-r--r--src/operator-noop-pending.cc30
-rw-r--r--src/operator-noop.cc25
-rw-r--r--src/operator-rename.cc34
-rw-r--r--src/operator-search.cc354
-rw-r--r--src/operator-select.cc71
-rw-r--r--src/operator-starttls.cc62
-rw-r--r--src/operator-status.cc37
-rw-r--r--src/operator-store.cc75
-rw-r--r--src/operator-subscribe.cc28
-rw-r--r--src/operator-unsubscribe.cc30
-rw-r--r--src/pendingupdates.cc70
-rw-r--r--src/recursivedescent.cc599
-rw-r--r--src/regmatch.cc9
-rw-r--r--src/session-initialize-bincimap-up.cc73
-rw-r--r--src/session-initialize-bincimapd.cc102
-rw-r--r--src/session.cc30
-rw-r--r--src/status.cc8
-rw-r--r--src/stdiodevice.cc28
-rw-r--r--src/syslogdevice.cc10
-rw-r--r--src/tools.cc9
98 files changed, 3107 insertions, 3108 deletions
diff --git a/src/address.cc b/src/address.cc
index 7739500..eff4ccd 100644
--- a/src/address.cc
+++ b/src/address.cc
@@ -5,7 +5,9 @@
* @date 2005
* ---------------------------------------------------------------- **/
#include "address.h"
+
#include "convert.h"
+
#include <string>
using namespace ::std;
@@ -19,7 +21,8 @@ Address::Address(const string &name, const string &addr)
if (pos != string::npos) {
this->local = addr.substr(0, pos);
this->host = addr.substr(pos + 1);
- } else this->local = addr;
+ } else
+ this->local = addr;
}
//------------------------------------------------------------------------
diff --git a/src/argparser.cc b/src/argparser.cc
index c8b482c..1382610 100644
--- a/src/argparser.cc
+++ b/src/argparser.cc
@@ -5,10 +5,11 @@
* @date 2005
* ------------------------------------------------------------------ **/
#include "argparser.h"
+
#include "convert.h"
-#include <string>
#include <map>
+#include <string>
using namespace ::std;
using namespace Binc;
@@ -39,7 +40,7 @@ bool CommandLineArgs::parse(int argc, char *argv[])
}
if (s[0] != '-') {
- // read value of last argument
+ // read value of last argument
if (lastKey == "") {
unqualified.push_back(s);
continue;
@@ -56,32 +57,32 @@ bool CommandLineArgs::parse(int argc, char *argv[])
lastKey = "";
lastIsBoolean = false;
} else if (s[1] == '-') {
- if (lastKey != "") {
- if (lastIsBoolean) {
- args[lastKey] = "yes";
- passedArgs[lastKey] = true;
- lastKey = "";
- lastIsBoolean = false;
- } else {
- errString = "expected value of ";
- errString += lastKey;
- return false;
- }
+ if (lastKey != "") {
+ if (lastIsBoolean) {
+ args[lastKey] = "yes";
+ passedArgs[lastKey] = true;
+ lastKey = "";
+ lastIsBoolean = false;
+ } else {
+ errString = "expected value of ";
+ errString += lastKey;
+ return false;
}
+ }
- // break if '--' is detected
- if (s.length() == 2) {
- ac = i + 1;
- break;
+ // break if '--' is detected
+ if (s.length() == 2) {
+ ac = i + 1;
+ break;
}
- // parse --argument
+ // parse --argument
string arg = s.substr(2);
string val;
string::size_type epos = arg.find('=');
if (epos != string::npos) {
val = arg.substr(epos + 1);
- arg = arg.substr(0, epos);
+ arg = arg.substr(0, epos);
}
if (reg.find(arg) == reg.end()) {
@@ -124,7 +125,7 @@ bool CommandLineArgs::parse(int argc, char *argv[])
}
}
- // parse -argument
+ // parse -argument
string arg = s.substr(1);
if (arg.length() == 1) {
map<string, ArgOpts>::const_iterator it = reg.begin();
@@ -178,26 +179,26 @@ bool CommandLineArgs::parse(int argc, char *argv[])
}
}
- if (lastKey != "") {
- if (lastIsBoolean) {
- args[lastKey] = "yes";
- passedArgs[lastKey] = true;
- } else {
- errString = "expected value of ";
- errString += lastKey;
- return false;
+ if (lastKey != "") {
+ if (lastIsBoolean) {
+ args[lastKey] = "yes";
+ passedArgs[lastKey] = true;
+ } else {
+ errString = "expected value of ";
+ errString += lastKey;
+ return false;
+ }
}
}
- }
// assign default "no" values for arguments that were not passed.
map<string, ArgOpts>::const_iterator it = reg.begin();
for (; it != reg.end(); ++it) {
if (args.find(it->first) == args.end()) {
if (!it->second.o) {
- errString = "missing argument: ";
- errString += it->first;
- return false;
+ errString = "missing argument: ";
+ errString += it->first;
+ return false;
}
if (it->second.b) args[it->first] = "no";
}
@@ -214,29 +215,26 @@ string CommandLineArgs::errorString(void) const
}
//----------------------------------------------------------------------
-const string CommandLineArgs::operator [](const string &arg) const
+const string CommandLineArgs::operator[](const string &arg) const
{
if (args.find(arg) == args.end()) return "";
return args.find(arg)->second;
}
//----------------------------------------------------------------------
-void CommandLineArgs::addOptional(const string &arg, const string &desc,
- bool boolean)
+void CommandLineArgs::addOptional(const string &arg, const string &desc, bool boolean)
{
registerArg(arg, desc, boolean, true);
}
//----------------------------------------------------------------------
-void CommandLineArgs::addRequired(const string &arg,
- const string &desc, bool boolean)
+void CommandLineArgs::addRequired(const string &arg, const string &desc, bool boolean)
{
registerArg(arg, desc, boolean, false);
}
//----------------------------------------------------------------------
-void CommandLineArgs::registerArg(const string &arg, const string &desc,
- bool boolean, bool optional)
+void CommandLineArgs::registerArg(const string &arg, const string &desc, bool boolean, bool optional)
{
string name = arg;
@@ -252,7 +250,8 @@ void CommandLineArgs::registerArg(const string &arg, const string &desc,
//----------------------------------------------------------------------
bool CommandLineArgs::hasArg(const std::string &arg) const
{
- string tmp = arg; lowercase(tmp);
+ string tmp = arg;
+ lowercase(tmp);
return passedArgs.find(tmp) != passedArgs.end();
}
@@ -295,7 +294,7 @@ string CommandLineArgs::usageString(void) const
tmp += it->second.desc;
tmp += '\n';
}
-
+
tmp += '\n';
tmp += tail;
tmp += '\n';
diff --git a/src/authenticate.cc b/src/authenticate.cc
index bdd18c9..88bfa63 100644
--- a/src/authenticate.cc
+++ b/src/authenticate.cc
@@ -7,25 +7,26 @@
#include <string>
#include <vector>
-#include <sys/types.h>
+#include <errno.h>
+#include <signal.h>
+
#include <grp.h>
#include <pwd.h>
-#include <signal.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
// #ifndef HAVE_SYS_WAIT_H
// #include <wait.h>
-//#else
+// #else
#include <sys/wait.h>
-//#endif
+// #endif
#include "authenticate.h"
+#include "convert.h"
+#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
#include "session.h"
-#include "convert.h"
-#include "globals.h"
using namespace ::std;
using namespace Binc;
@@ -36,16 +37,18 @@ using namespace Binc;
// 3 = timeout
// -1 = abort
//------------------------------------------------------------------------
-int Binc::authenticate(Depot &depot, const string &username,
- const string &password, const string &challenge)
+int Binc::authenticate(Depot &depot,
+ const string &username,
+ const string &password,
+ const string &challenge)
{
Session &session = Session::getInstance();
session.setUserID(username);
// check if checkpassword is present
if (::access(session.unparsedArgs[0], X_OK) != 0) { // x is enough
- bincError << "unable to start authenticator " << session.unparsedArgs[0]
- << ": " << strerror(errno) << endl;
+ bincError << "unable to start authenticator " << session.unparsedArgs[0] << ": " << strerror(errno)
+ << endl;
return 1;
}
@@ -60,22 +63,19 @@ int Binc::authenticate(Depot &depot, const string &username,
bool authenticated = false;
if (pipe(authintercom) == -1) {
- session.setLastError("An error occurred when creating pipes: "
- + string(strerror(errno)));
+ session.setLastError("An error occurred when creating pipes: " + string(strerror(errno)));
return -1;
}
if (pipe(intercomw) == -1) {
- session.setLastError("An error occurred when creating pipes: "
- + string(strerror(errno)));
+ session.setLastError("An error occurred when creating pipes: " + string(strerror(errno)));
close(authintercom[0]);
close(authintercom[1]);
return -1;
}
if (pipe(intercomr) == -1) {
- session.setLastError("An error occurred when creating pipes: "
- + string(strerror(errno)));
+ session.setLastError("An error occurred when creating pipes: " + string(strerror(errno)));
close(intercomw[0]);
close(intercomr[0]);
close(authintercom[0]);
@@ -98,9 +98,7 @@ int Binc::authenticate(Depot &depot, const string &username,
int result;
int childspid = fork();
if (childspid == -1) {
- bincLog << "bincimap-up: pid " << pid
- << " failed to start main server: "
- << strerror(errno) << endl;
+ bincLog << "bincimap-up: pid " << pid << " failed to start main server: " << strerror(errno) << endl;
return 1;
}
@@ -111,43 +109,39 @@ int Binc::authenticate(Depot &depot, const string &username,
if (dup2(intercomr[1], 1) == -1) {
bincDebug << "bincimap-up: pid " << pid
- << " authenticate(), [auth module] dup2 failed: "
- << strerror(errno) << endl;
+ << " authenticate(), [auth module] dup2 failed: " << strerror(errno) << endl;
bincDebug.flush();
exit(111);
}
if (dup2(intercomw[0], 0) == -1) {
- bincDebug << "bincimap-up: pid " << pid
- << " authenticate(), [auth module] dup2 failed: "
- << strerror(errno) << endl;
+ bincDebug << "bincimap-up: pid " << pid
+ << " authenticate(), [auth module] dup2 failed: " << strerror(errno) << endl;
bincDebug.flush();
exit(111);
}
if (dup2(authintercom[0], 3) == -1) {
- bincDebug << "bincimap-up: pid " << pid
- << " authenticate(), [auth module] dup2 failed: "
- << strerror(errno) << endl;
+ bincDebug << "bincimap-up: pid " << pid
+ << " authenticate(), [auth module] dup2 failed: " << strerror(errno) << endl;
bincDebug.flush();
exit(111);
}
if (session.unparsedArgs[0] != 0) {
execvp(session.unparsedArgs[0], &session.unparsedArgs[0]);
- bincDebug << "bincimap-up: pid " << pid
- << " authenticate(), [auth module] invocation of "
- << session.unparsedArgs[0]
- << " failed: " << strerror(errno) << endl;
+ bincDebug << "bincimap-up: pid " << pid << " authenticate(), [auth module] invocation of "
+ << session.unparsedArgs[0] << " failed: " << strerror(errno) << endl;
bincDebug.flush();
exit(111);
}
-
- bincLog << "bincimap-up: pid " << pid
+
+ bincLog << "bincimap-up: pid " << pid
<< " missing mandatory -- in argument list,"
" after bincimap-up + arguments, before authenticator."
" Please check your run scripts and the man page bincimap(1) for"
- " more on how to invoke Binc IMAP." << endl;
+ " more on how to invoke Binc IMAP."
+ << endl;
bincDebug.flush();
exit(111);
}
@@ -173,8 +167,7 @@ int Binc::authenticate(Depot &depot, const string &username,
cpTmp += timestamp.length();
*cpTmp++ = '\0';
- bincDebug << "bincimap-up: pid " << pid
- << " authenticate(), writing username/password to "
+ bincDebug << "bincimap-up: pid " << pid << " authenticate(), writing username/password to "
<< session.unparsedArgs[0] << endl;
// write the userid
@@ -182,10 +175,8 @@ int Binc::authenticate(Depot &depot, const string &username,
int res = write(authintercom[1], checkpasswordData, dataSize);
delete[] checkpasswordData;
if (res != dataSize) {
- bincWarning << "bincimap-up: pid " << pid
- << " error writing to authenticator "
- << session.unparsedArgs[0] << ": "
- << strerror(errno) << endl;
+ bincWarning << "bincimap-up: pid " << pid << " error writing to authenticator "
+ << session.unparsedArgs[0] << ": " << strerror(errno) << endl;
return 1;
}
@@ -199,7 +190,7 @@ int Binc::authenticate(Depot &depot, const string &username,
FD_ZERO(&rmask);
FD_SET(fileno(stdin), &rmask);
FD_SET(intercomr[0], &rmask);
-
+
int maxfd = intercomr[0];
bool disconnected = false;
bool timedout = false;
@@ -225,16 +216,14 @@ int Binc::authenticate(Depot &depot, const string &username,
} while (n < 0 && errno == EINTR);
if (n < 0) {
- bincWarning << "bincimpa-up: pid " << pid
- << " error: invalid exit from select, "
+ bincWarning << "bincimpa-up: pid " << pid << " error: invalid exit from select, "
<< strerror(errno) << endl;
break;
}
if (n == 0) {
- bincLog << "bincimap-up: pid " << pid
- << " server timed out after "
- << IDLE_TIMEOUT << " seconds" << endl;
+ bincLog << "bincimap-up: pid " << pid << " server timed out after " << IDLE_TIMEOUT << " seconds"
+ << endl;
timedout = true;
break;
}
@@ -252,8 +241,8 @@ int Binc::authenticate(Depot &depot, const string &username,
break;
}
- // Fall through. Triggered when there was no data
- // to read, even though no error has occurred
+ // Fall through. Triggered when there was no data
+ // to read, even though no error has occurred
if (ret == -2) continue;
int w;
@@ -264,9 +253,8 @@ int Binc::authenticate(Depot &depot, const string &username,
if (w > 0) Session::getInstance().addReadBytes(w);
if (w < 0) {
- bincDebug << "bincimap-up: pid " << pid
- << " error writing to server: "
- << strerror(errno) << endl;
+ bincDebug << "bincimap-up: pid " << pid << " error writing to server: " << strerror(errno)
+ << endl;
eof = true;
}
} while (bincClient.canRead());
@@ -276,17 +264,16 @@ int Binc::authenticate(Depot &depot, const string &username,
char buf[8192];
int ret = read(intercomr[0], buf, sizeof(buf));
if (ret == 0) {
- // Main server has shut down
+ // Main server has shut down
eof = true;
- break;
+ break;
} else if (ret == -1) {
- bincDebug << "bincimap-up: pid " << pid
- << " error reading from server: "
- << strerror(errno) << endl;
+ bincDebug << "bincimap-up: pid " << pid << " error reading from server: " << strerror(errno)
+ << endl;
eof = true;
break;
} else {
- // umask(0);
+ // umask(0);
Session::getInstance().addWriteBytes(ret);
bincClient << string(buf, ret);
@@ -298,11 +285,10 @@ int Binc::authenticate(Depot &depot, const string &username,
close(intercomr[0]);
close(intercomw[1]);
- // catch the dead baby
+ // catch the dead baby
if (waitpid(childspid, &result, 0) != childspid) {
- bincLog << "bincimap-up: pid " << pid
- << " <" << username << "> authentication failed: "
- << (authenticated ? "server " : session.unparsedArgs[0])
+ bincLog << "bincimap-up: pid " << pid << " <" << username
+ << "> authentication failed: " << (authenticated ? "server " : session.unparsedArgs[0])
<< " waitpid returned unexpected value" << endl;
string tmp = strerror(errno);
@@ -316,43 +302,40 @@ int Binc::authenticate(Depot &depot, const string &username,
if (disconnected) return 0;
if (WIFSIGNALED(result)) {
- bincLog << "bincimap-up: pid " << pid
- << " <" << username << "> authentication failed: "
- << (authenticated ? "server" : session.unparsedArgs[0])
+ bincLog << "bincimap-up: pid " << pid << " <" << username
+ << "> authentication failed: " << (authenticated ? "server" : session.unparsedArgs[0])
<< " died by signal " << WTERMSIG(result) << endl;
sleep(AUTH_PENALTY);
session.setState(Session::LOGOUT);
return -1;
}
- bincDebug << "bincimap-up: pid " << pid
- << " authenticate() ,"
- << (authenticated ? "authenticator" : "server")
- << " exited with code " << WEXITSTATUS(result) << endl;
+ bincDebug << "bincimap-up: pid " << pid << " authenticate() ,"
+ << (authenticated ? "authenticator" : "server") << " exited with code "
+ << WEXITSTATUS(result) << endl;
switch (WEXITSTATUS(result)) {
- case 0: break;
- case 1:
+ case 0:
+ break;
+ case 1:
// authentication failed - sleep
- bincLog << "bincimap-up: pid " << pid
- << " <" << username << "> failed to log in" << endl;
- sleep(AUTH_PENALTY);
- return 2;
- case 2: case 111: // wrong call or missing auth data
- // abused
- bincLog << "bincimap-up: pid " << pid
- << " <" << username << "> authentication failed: "
- << (authenticated ? "authenticator" : "server")
- << " reports wrong usage" << endl;
- sleep(AUTH_PENALTY);
- return 2;
- default:
+ bincLog << "bincimap-up: pid " << pid << " <" << username << "> failed to log in" << endl;
+ sleep(AUTH_PENALTY);
+ return 2;
+ case 2:
+ case 111: // wrong call or missing auth data
+ // abused
+ bincLog << "bincimap-up: pid " << pid << " <" << username
+ << "> authentication failed: " << (authenticated ? "authenticator" : "server")
+ << " reports wrong usage" << endl;
+ sleep(AUTH_PENALTY);
+ return 2;
+ default:
// internal error -- or authenticator fooled us
- bincLog << "bincimap-up: pid " << pid
- << " <" << username << "> authentication failed: "
- << (authenticated ? "authenticator" : "server")
- << " returned " << WEXITSTATUS(result) << endl;
- return -1;
+ bincLog << "bincimap-up: pid " << pid << " <" << username
+ << "> authentication failed: " << (authenticated ? "authenticator" : "server")
+ << " returned " << WEXITSTATUS(result) << endl;
+ return -1;
}
return 0;
diff --git a/src/base64.cc b/src/base64.cc
index 367a3e4..5b182b2 100644
--- a/src/base64.cc
+++ b/src/base64.cc
@@ -2,20 +2,21 @@
* @file base64.cc
* @brief Implementation of base64 Utilities
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
#include "base64.h"
-#include <string>
+
#include <iostream>
+#include <string>
using namespace ::std;
-typedef unsigned char bbyte; /* Byte type */
+typedef unsigned char bbyte; /* Byte type */
#define TRUE 1
#define FALSE 0
-#define LINELEN 72 /* Encoded line length (max 76) */
+#define LINELEN 72 /* Encoded line length (max 76) */
static bbyte dtable[256];
@@ -38,14 +39,13 @@ string Binc::base64encode(const string &s_in)
string::const_iterator s_i = s_in.begin();
while (s_i != s_in.end()) {
-
bbyte igroup[3], ogroup[4];
int c, n;
igroup[0] = igroup[1] = igroup[2] = 0;
for (n = 0; n < 3 && s_i != s_in.end(); n++) {
c = *s_i++;
- igroup[n] = (bbyte) c;
+ igroup[n] = (bbyte)c;
}
if (n > 0) {
ogroup[0] = dtable[igroup[0] >> 2];
@@ -53,9 +53,9 @@ string Binc::base64encode(const string &s_in)
ogroup[2] = dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
ogroup[3] = dtable[igroup[2] & 0x3F];
- /* Replace characters in output stream with "=" pad
- characters if fewer than three characters were
- read from the end of the input stream. */
+ /* Replace characters in output stream with "=" pad
+ characters if fewer than three characters were
+ read from the end of the input stream. */
if (n < 3) {
ogroup[3] = '=';
@@ -89,9 +89,9 @@ string Binc::base64decode(const string &s_in)
for (i = '0'; i <= '9'; i++) {
dtable[i] = 52 + (i - '0');
}
- dtable[(int) '+'] = 62;
- dtable[(int) '/'] = 63;
- dtable[(int) '='] = 0;
+ dtable[(int)'+'] = 62;
+ dtable[(int)'/'] = 63;
+ dtable[(int)'='] = 0;
/*CONSTANTCONDITION*/
string::const_iterator s_i = s_in.begin();
@@ -101,8 +101,8 @@ string Binc::base64decode(const string &s_in)
for (i = 0; i < 4 && s_i != s_in.end(); i++) {
int c = *s_i++;
if (dtable[c] & 0x80) return result;
- a[i] = (bbyte) c;
- b[i] = (bbyte) dtable[c];
+ a[i] = (bbyte)c;
+ b[i] = (bbyte)dtable[c];
}
o[0] = (b[0] << 2) | (b[1] >> 4);
diff --git a/src/bincimap-up.cc b/src/bincimap-up.cc
index 77576de..c74b98f 100644
--- a/src/bincimap-up.cc
+++ b/src/bincimap-up.cc
@@ -2,12 +2,12 @@
* @file bincimap-up.cc
* @brief Implementation of the preauthenticated bincimap stub
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ------------------------------------------------------------------ **/
#include "imapserver.h"
//------------------------------------------------------------------------
-int main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
Binc::IMAPServer imapServer(argc, argv);
int initResult = imapServer.initialize();
diff --git a/src/bincimap-updatecache.cc b/src/bincimap-updatecache.cc
index 4efe723..b89abdf 100644
--- a/src/bincimap-updatecache.cc
+++ b/src/bincimap-updatecache.cc
@@ -32,9 +32,10 @@ int main(int argc, char *argv[])
Depot *depot;
if ((depot = depotfactory.get(depottype)) == 0) {
- fprintf(stderr, "Found no Depot for \"%s\". Please check " \
- " your configurations file under the Mailbox section.\n",
- depottype.c_str());
+ fprintf(stderr,
+ "Found no Depot for \"%s\". Please check "
+ " your configurations file under the Mailbox section.\n",
+ depottype.c_str());
return 1;
}
@@ -44,14 +45,12 @@ int main(int argc, char *argv[])
Mailbox *mailbox = depot->get(depot->filenameToMailbox(argv[1]));
if (!mailbox) {
- fprintf(stderr, "selecting mailbox failed: %s\n",
- depot->getLastError().c_str());
+ fprintf(stderr, "selecting mailbox failed: %s\n", depot->getLastError().c_str());
return 1;
}
if (!mailbox->selectMailbox(argv[1], argv[1])) {
- fprintf(stderr, "selecting mailbox failed: %s\n",
- mailbox->getLastError().c_str());
+ fprintf(stderr, "selecting mailbox failed: %s\n", mailbox->getLastError().c_str());
return 1;
}
diff --git a/src/bincimapd.cc b/src/bincimapd.cc
index d4d8508..b8ba1cb 100644
--- a/src/bincimapd.cc
+++ b/src/bincimapd.cc
@@ -7,9 +7,7 @@
#include "imapserver.h"
namespace Binc {
- void showGreeting(void)
- {
- }
+ void showGreeting(void) {}
}
int main(int argc, char *argv[])
diff --git a/src/broker.cc b/src/broker.cc
index 9d7f728..4cb7787 100644
--- a/src/broker.cc
+++ b/src/broker.cc
@@ -4,15 +4,16 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <map>
-#include <string>
-
#include "broker.h"
+
#include "convert.h"
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
+#include <map>
+#include <string>
+
using namespace ::std;
using namespace Binc;
@@ -27,8 +28,7 @@ BrokerFactory::BrokerFactory(void)
//----------------------------------------------------------------------
BrokerFactory::~BrokerFactory(void)
{
- for (map<int, Broker *>::iterator i = brokers.begin();
- i != brokers.end(); ++i)
+ for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i)
delete i->second;
}
@@ -42,10 +42,9 @@ BrokerFactory &BrokerFactory::getInstance(void)
//----------------------------------------------------------------------
void BrokerFactory::addCapability(const std::string &c)
{
- for (map<int, Broker *>::iterator i = brokers.begin();
- i != brokers.end(); ++i) {
- CapabilityOperator * o;
- o = dynamic_cast<CapabilityOperator*>(i->second->get("CAPABILITY"));
+ for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i) {
+ CapabilityOperator *o;
+ o = dynamic_cast<CapabilityOperator *>(i->second->get("CAPABILITY"));
if (o != 0) {
o->addCapability(c);
break;
@@ -57,8 +56,7 @@ void BrokerFactory::addCapability(const std::string &c)
void BrokerFactory::assign(const string &fname, Operator *o)
{
int deletable = true;
- for (map<int, Broker *>::iterator i = brokers.begin();
- i != brokers.end(); ++i)
+ for (map<int, Broker *>::iterator i = brokers.begin(); i != brokers.end(); ++i)
if (i->first & o->getState()) {
i->second->assign(fname, o, deletable);
deletable = false;
@@ -86,14 +84,10 @@ Broker *BrokerFactory::getBroker(int state)
}
//----------------------------------------------------------------------
-Broker::Broker(void)
-{
-}
+Broker::Broker(void) {}
//----------------------------------------------------------------------
-Broker::~Broker(void)
-{
-}
+Broker::~Broker(void) {}
//----------------------------------------------------------------------
void Broker::assign(const string &fname, Operator *o, bool deletable)
@@ -119,70 +113,70 @@ Operator::ParseResult Broker::parseStub(Request &command)
string cmd;
switch (expectTag(tag)) {
- case Operator::ACCEPT:
- break;
- case Operator::REJECT:
- session.setLastError("Syntax error; first token must be a tag");
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
+ case Operator::ACCEPT:
+ break;
+ case Operator::REJECT:
+ session.setLastError("Syntax error; first token must be a tag");
+ case Operator::ERROR:
+ return Operator::ERROR;
+ case Operator::TIMEOUT:
+ return Operator::TIMEOUT;
}
switch (expectSPACE()) {
+ case Operator::ACCEPT:
+ break;
+ case Operator::REJECT:
+ session.setLastError("Syntax error; second token must be a SPACE");
+ case Operator::ERROR:
+ return Operator::ERROR;
+ case Operator::TIMEOUT:
+ return Operator::TIMEOUT;
+ }
+
+ switch (expectAstring(cmd)) {
+ case Operator::ACCEPT:
+ break;
+ case Operator::REJECT:
+ session.setLastError("Syntax error; third token must be a command");
+ case Operator::ERROR:
+ return Operator::ERROR;
+ case Operator::TIMEOUT:
+ return Operator::TIMEOUT;
+ }
+
+ uppercase(cmd);
+
+ if (cmd == "UID") {
+ command.setUidMode();
+
+ switch (expectSPACE()) {
case Operator::ACCEPT:
break;
case Operator::REJECT:
- session.setLastError("Syntax error; second token must be a SPACE");
+ session.setLastError("Syntax error; after UID there"
+ " must come a SPACE");
case Operator::ERROR:
return Operator::ERROR;
case Operator::TIMEOUT:
return Operator::TIMEOUT;
- }
+ }
- switch (expectAstring(cmd)) {
+ switch (expectAstring(cmd)) {
case Operator::ACCEPT:
break;
case Operator::REJECT:
- session.setLastError("Syntax error; third token must be a command");
+ session.setLastError("Syntax error; after UID "
+ "SPACE there must come a command");
case Operator::ERROR:
return Operator::ERROR;
case Operator::TIMEOUT:
return Operator::TIMEOUT;
- }
-
- uppercase(cmd);
-
- if (cmd == "UID") {
- command.setUidMode();
-
- switch (expectSPACE()) {
- case Operator::ACCEPT:
- break;
- case Operator::REJECT:
- session.setLastError("Syntax error; after UID there"
- " must come a SPACE");
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
- }
-
- switch (expectAstring(cmd)) {
- case Operator::ACCEPT:
- break;
- case Operator::REJECT:
- session.setLastError("Syntax error; after UID "
- "SPACE there must come a command");
- case Operator::ERROR:
- return Operator::ERROR;
- case Operator::TIMEOUT:
- return Operator::TIMEOUT;
- }
-
- uppercase(cmd);
}
+ uppercase(cmd);
+ }
+
command.setTag(tag);
command.setName(cmd);
diff --git a/src/convert.cc b/src/convert.cc
index 5af4f3c..ac1c01b 100644
--- a/src/convert.cc
+++ b/src/convert.cc
@@ -2,18 +2,17 @@
* @file convert.cc
* @brief Implementation of miscellaneous convertion functions
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
#include "convert.h"
+
#include <string>
using namespace ::std;
using namespace Binc;
//------------------------------------------------------------------------
-BincStream::BincStream(void)
-{
-}
+BincStream::BincStream(void) {}
//------------------------------------------------------------------------
BincStream::~BincStream(void)
@@ -24,8 +23,7 @@ BincStream::~BincStream(void)
//------------------------------------------------------------------------
string BincStream::popString(unsigned int size)
{
- if (size > nstr.length())
- size = nstr.length();
+ if (size > nstr.length()) size = nstr.length();
string tmp = nstr.substr(0, size);
nstr = nstr.substr(size);
return tmp;
@@ -34,8 +32,7 @@ string BincStream::popString(unsigned int size)
//------------------------------------------------------------------------
char BincStream::popChar(void)
{
- if (nstr.length() == 0)
- return '\0';
+ if (nstr.length() == 0) return '\0';
char c = nstr[0];
nstr = nstr.substr(1);
@@ -69,45 +66,45 @@ void BincStream::clear(void)
//------------------------------------------------------------------------
unsigned int BincStream::getSize(void) const
{
- return (unsigned int) nstr.length();
+ return (unsigned int)nstr.length();
}
//------------------------------------------------------------------------
-BincStream &BincStream::operator << (std::ostream&(*)(std::ostream&))
+BincStream &BincStream::operator<<(std::ostream &(*)(std::ostream &))
{
nstr += "\r\n";
return *this;
}
//------------------------------------------------------------------------
-BincStream &BincStream::operator << (const string &t)
+BincStream &BincStream::operator<<(const string &t)
{
nstr += t;
return *this;
}
//------------------------------------------------------------------------
-BincStream &BincStream::operator << (int t)
+BincStream &BincStream::operator<<(int t)
{
nstr += toString(t);
return *this;
}
//------------------------------------------------------------------------
-BincStream &BincStream::operator << (unsigned long t)
+BincStream &BincStream::operator<<(unsigned long t)
{
nstr += toString(t);
return *this;
}
-BincStream &BincStream::operator << (unsigned int t)
+BincStream &BincStream::operator<<(unsigned int t)
{
nstr += toString(t);
return *this;
}
//------------------------------------------------------------------------
-BincStream &BincStream::operator << (char t)
+BincStream &BincStream::operator<<(char t)
{
nstr += t;
return *this;
diff --git a/src/depot.cc b/src/depot.cc
index 599bf97..c31c04b 100644
--- a/src/depot.cc
+++ b/src/depot.cc
@@ -2,43 +2,41 @@
* @file depot.cc
* @brief Implementation of the Depot class.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ------------------------------------------------------------------ **/
-#include <map>
-#include <string>
-#include <unistd.h>
-#include <errno.h>
-
#include "depot.h"
-#include "mailbox.h"
-#include "status.h"
+
#include "convert.h"
#include "iodevice.h"
#include "iofactory.h"
+#include "mailbox.h"
+#include "status.h"
+
+#include <map>
+#include <string>
+
+#include <errno.h>
+
+#include <unistd.h>
using namespace ::std;
using namespace Binc;
//--------------------------------------------------------------------
-DepotFactory::DepotFactory(void)
-{
-}
+DepotFactory::DepotFactory(void) {}
//--------------------------------------------------------------------
DepotFactory::~DepotFactory(void)
{
- for (vector<Depot *>::iterator i = depots.begin(); i != depots.end();
- ++i)
+ for (vector<Depot *>::iterator i = depots.begin(); i != depots.end(); ++i)
delete *i;
}
//--------------------------------------------------------------------
Depot *DepotFactory::get(const string &name) const
{
- for (vector<Depot *>::const_iterator i = depots.begin(); i != depots.end();
- ++i)
- if ((*i)->getName() == name)
- return *i;
+ for (vector<Depot *>::const_iterator i = depots.begin(); i != depots.end(); ++i)
+ if ((*i)->getName() == name) return *i;
return 0;
}
@@ -77,9 +75,7 @@ Depot::Depot(const string &name) : enditerator(0, 0)
}
//--------------------------------------------------------------------
-Depot::~Depot(void)
-{
-}
+Depot::~Depot(void) {}
//--------------------------------------------------------------------
const string &Depot::getLastError(void) const
@@ -96,8 +92,7 @@ void Depot::setLastError(const string &error) const
//--------------------------------------------------------------------
void Depot::assign(Mailbox *m)
{
- for (vector<Mailbox *>::const_iterator i = backends.begin();
- i != backends.end(); ++i)
+ for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i)
if (*i == m) break;
backends.push_back(m);
@@ -106,10 +101,8 @@ void Depot::assign(Mailbox *m)
//--------------------------------------------------------------------
Mailbox *Depot::get(const string &s_in) const
{
- for (vector<Mailbox *>::const_iterator i = backends.begin();
- i != backends.end(); ++i)
- if ((*i)->isMailbox(mailboxToFilename(s_in)))
- return *i;
+ for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i)
+ if ((*i)->isMailbox(mailboxToFilename(s_in))) return *i;
setLastError("No such mailbox " + toImapString(s_in));
return 0;
@@ -118,8 +111,7 @@ Mailbox *Depot::get(const string &s_in) const
//--------------------------------------------------------------------
bool Depot::setSelected(Mailbox *m)
{
- for (vector<Mailbox *>::const_iterator i = backends.begin();
- i != backends.end(); ++i)
+ for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i)
if (*i == m) {
selectedmailbox = m;
return true;
@@ -168,8 +160,7 @@ const char Depot::getDelimiter(void) const
//--------------------------------------------------------------------
bool Depot::setDefaultType(const string &name)
{
- for (vector<Mailbox *>::const_iterator i = backends.begin();
- i != backends.end(); ++i)
+ for (vector<Mailbox *>::const_iterator i = backends.begin(); i != backends.end(); ++i)
if ((*i)->getTypeName() == name) {
defaultmailbox = *i;
return true;
@@ -259,15 +250,15 @@ bool Depot::renameMailbox(const string &s_in, const string &t_in) const
sourcename = source;
destname = dest;
- } else if (entry.length() > source.length()
- && entry[source.length()] == '.') {
- sourcename = entry;
- destname = dest + entry.substr(source.length());
- } else continue;
+ } else if (entry.length() > source.length() && entry[source.length()] == '.') {
+ sourcename = entry;
+ destname = dest + entry.substr(source.length());
+ } else
+ continue;
if (rename(sourcename.c_str(), destname.c_str()) != 0) {
- bincWarning << "error renaming " << sourcename << " to "
- << destname << ": " << strerror(errno) << endl;
+ bincWarning << "error renaming " << sourcename << " to " << destname << ": " << strerror(errno)
+ << endl;
} else
nrenamed++;
@@ -280,12 +271,10 @@ bool Depot::renameMailbox(const string &s_in, const string &t_in) const
}
if (nrenamed == 0) {
- setLastError("An error occurred when renaming "
- + toImapString(s_in)
- + " to " + toImapString(t_in)
- + ". Try creating a new mailbox,"
- " then copy over all messages."
- " Finally, delete the original mailbox");
+ setLastError("An error occurred when renaming " + toImapString(s_in) + " to " + toImapString(t_in)
+ + ". Try creating a new mailbox,"
+ " then copy over all messages."
+ " Finally, delete the original mailbox");
return false;
} else
return true;
@@ -299,13 +288,12 @@ bool Depot::getStatus(const std::string &s_in, Status &dest) const
if (m == 0) {
setLastError("Unrecognized mailbox: " + toImapString(s_in));
return false;
-}
-
+ }
+
int statusid = m->getStatusID(mailboxToFilename(mailbox));
if (mailboxstatuses.find(mailbox) != mailboxstatuses.end()) {
dest = mailboxstatuses[mailbox];
- if (dest.getStatusID() == statusid)
- return true;
+ if (dest.getStatusID() == statusid) return true;
}
if (!m->getStatus(mailboxToFilename(mailbox), dest)) {
@@ -327,10 +315,8 @@ vector<string> Depot::getSubscriptions(void) const
//----------------------------------------------------------------------
void Depot::subscribeTo(const std::string mailbox)
{
- for (vector<string>::iterator i = subscribed.begin();
- i != subscribed.end(); ++i) {
- if (*i == mailbox)
- return;
+ for (vector<string>::iterator i = subscribed.begin(); i != subscribed.end(); ++i) {
+ if (*i == mailbox) return;
}
subscribed.push_back(mailbox);
@@ -339,8 +325,7 @@ void Depot::subscribeTo(const std::string mailbox)
//----------------------------------------------------------------------
bool Depot::unsubscribeTo(const std::string mailbox)
{
- for (vector<string>::iterator i = subscribed.begin();
- i != subscribed.end(); ++i) {
+ for (vector<string>::iterator i = subscribed.begin(); i != subscribed.end(); ++i) {
if (*i == mailbox) {
subscribed.erase(i);
return true;
@@ -366,11 +351,9 @@ void Depot::loadSubscribes(void)
while ((c = fgetc(fp)) != EOF) {
if (c == '\n') {
if (current != "") {
- if (current == "INBOX")
- current = ".";
+ if (current == "INBOX") current = ".";
- if (current.substr(0, 5) == "INBOX")
- current = current.substr(5);
+ if (current.substr(0, 5) == "INBOX") current = current.substr(5);
if (addedEntries.find(current) == addedEntries.end()) {
subscribed.push_back(filenameToMailbox(current));
@@ -379,7 +362,7 @@ void Depot::loadSubscribes(void)
current = "";
}
} else
- current += c;
+ current += c;
}
fclose(fp);
@@ -402,39 +385,33 @@ bool Depot::saveSubscribes(void) const
strcpy(ftemplate, tpl.c_str());
int fd = mkstemp(ftemplate);
if (fd == -1) {
- bincWarning << "unable to create temporary file \""
- << tpl << "\"" << endl;
+ bincWarning << "unable to create temporary file \"" << tpl << "\"" << endl;
delete[] ftemplate;
return false;
}
map<string, bool> addedEntries;
- for (vector<string>::const_iterator i = subscribed.begin();
- i != subscribed.end(); ++i) {
+ for (vector<string>::const_iterator i = subscribed.begin(); i != subscribed.end(); ++i) {
if (addedEntries.find(*i) == addedEntries.end()) {
addedEntries[*i] = true;
string w = mailboxToFilename(*i) + "\n";
- if (write(fd, w.c_str(), w.length()) != (ssize_t) w.length()) {
- bincWarning << "failed to write to " << tpl << ": "
- << strerror(errno) << endl;
+ if (write(fd, w.c_str(), w.length()) != (ssize_t)w.length()) {
+ bincWarning << "failed to write to " << tpl << ": " << strerror(errno) << endl;
break;
}
}
}
-
+
if ((fsync(fd) && (errno != EROFS || errno != EINVAL)) || close(fd)) {
- bincWarning << "failed to close " << ftemplate
- << ": " << strerror(errno) << endl;
- delete[] ftemplate;
- return false;
+ bincWarning << "failed to close " << ftemplate << ": " << strerror(errno) << endl;
+ delete[] ftemplate;
+ return false;
}
if (rename(ftemplate, ".subscribed") != 0) {
- bincWarning << "failed to rename " << ftemplate
- << " to .subscribed: "
- << strerror(errno) << endl;
- delete[] ftemplate;
- return false;
+ bincWarning << "failed to rename " << ftemplate << " to .subscribed: " << strerror(errno) << endl;
+ delete[] ftemplate;
+ return false;
}
delete[] ftemplate;
@@ -462,8 +439,7 @@ Depot::iterator::iterator(DIR *dp, struct dirent *sp)
//--------------------------------------------------------------------
Depot::iterator::iterator(const iterator &copy)
{
- if (*copy.ref != 0)
- ++(*copy.ref);
+ if (*copy.ref != 0) ++(*copy.ref);
ref = copy.ref;
dirp = copy.dirp;
@@ -477,10 +453,9 @@ Depot::iterator::~iterator(void)
}
//--------------------------------------------------------------------
-Depot::iterator &Depot::iterator::operator =(const iterator &copy)
+Depot::iterator &Depot::iterator::operator=(const iterator &copy)
{
- if (*copy.ref != 0)
- ++(*copy.ref);
+ if (*copy.ref != 0) ++(*copy.ref);
deref();
@@ -507,28 +482,27 @@ void Depot::iterator::deref(void)
}
//--------------------------------------------------------------------
-string Depot::iterator::operator * (void) const
+string Depot::iterator::operator*(void) const
{
- if (direntp == 0)
- return "";
+ if (direntp == 0) return "";
return direntp->d_name;
}
//--------------------------------------------------------------------
-void Depot::iterator::operator ++ (void)
+void Depot::iterator::operator++(void)
{
direntp = readdir(dirp);
}
//--------------------------------------------------------------------
-bool Depot::iterator::operator == (Depot::iterator i) const
+bool Depot::iterator::operator==(Depot::iterator i) const
{
return direntp == i.direntp;
}
//--------------------------------------------------------------------
-bool Depot::iterator::operator != (Depot::iterator i) const
+bool Depot::iterator::operator!=(Depot::iterator i) const
{
return direntp != i.direntp;
}
@@ -562,9 +536,7 @@ MaildirPPDepot::MaildirPPDepot(void) : Depot("Maildir++")
}
//--------------------------------------------------------------------
-MaildirPPDepot::~MaildirPPDepot(void)
-{
-}
+MaildirPPDepot::~MaildirPPDepot(void) {}
//--------------------------------------------------------------------
const string &MaildirPPDepot::getPersonalNamespace(void) const
@@ -575,7 +547,8 @@ const string &MaildirPPDepot::getPersonalNamespace(void) const
//--------------------------------------------------------------------
string MaildirPPDepot::mailboxToFilename(const string &m) const
{
- string prefix = "INBOX"; prefix += delimiter;
+ string prefix = "INBOX";
+ prefix += delimiter;
string mm = m;
trim(mm, string(&delimiter, 1));
@@ -584,7 +557,8 @@ string MaildirPPDepot::mailboxToFilename(const string &m) const
if (tmp != "INBOX" && tmp.substr(0, 6) != prefix) {
setLastError("With a Maildir++ depot, you must create all"
" mailboxes under INBOX. Try creating"
- " " + prefix + mm + " .");
+ " "
+ + prefix + mm + " .");
return "";
}
@@ -592,7 +566,8 @@ string MaildirPPDepot::mailboxToFilename(const string &m) const
twodelim += delimiter;
twodelim += delimiter;
- if (mm == "INBOX") return ".";
+ if (mm == "INBOX")
+ return ".";
else if (mm.length() <= 6) {
setLastError("With a Maildir++ depot, you must create all"
" mailboxes under INBOX.");
@@ -602,8 +577,7 @@ string MaildirPPDepot::mailboxToFilename(const string &m) const
" mailboxes under INBOX.");
return "";
} else if (mm.find(twodelim) != string::npos) {
- setLastError("Invalid character combination "
- + twodelim + " in mailbox name");
+ setLastError("Invalid character combination " + twodelim + " in mailbox name");
return "";
} else if (mm != "" && delimiter != '.' && mm.substr(1).find('.') != string::npos) {
setLastError("Invalid character '.' in mailbox name");
@@ -620,26 +594,25 @@ string MaildirPPDepot::mailboxToFilename(const string &m) const
//--------------------------------------------------------------------
string MaildirPPDepot::filenameToMailbox(const string &m) const
{
- if (m == ".") return "INBOX";
- else if (delimiter != '.' && m.find(delimiter) != string::npos) return "";
+ if (m == ".")
+ return "INBOX";
+ else if (delimiter != '.' && m.find(delimiter) != string::npos)
+ return "";
else if (m != "" && m[0] == '.') {
string tmp = m;
for (string::iterator i = tmp.begin(); i != tmp.end(); ++i)
if (*i == '.') *i = delimiter;
return "INBOX" + tmp;
- } else return "";
+ } else
+ return "";
}
//--------------------------------------------------------------------
-IMAPdirDepot::IMAPdirDepot(void) : Depot("IMAPdir")
-{
-}
+IMAPdirDepot::IMAPdirDepot(void) : Depot("IMAPdir") {}
//--------------------------------------------------------------------
-IMAPdirDepot::~IMAPdirDepot(void)
-{
-}
+IMAPdirDepot::~IMAPdirDepot(void) {}
//--------------------------------------------------------------------
string IMAPdirDepot::mailboxToFilename(const string &m) const
@@ -653,8 +626,7 @@ string IMAPdirDepot::mailboxToFilename(const string &m) const
twodelim += delimiter;
if (mm.find(twodelim) != string::npos) {
- setLastError("Invalid character combination "
- + twodelim + " in mailbox name");
+ setLastError("Invalid character combination " + twodelim + " in mailbox name");
return "";
}
@@ -670,7 +642,7 @@ string IMAPdirDepot::mailboxToFilename(const string &m) const
else
tmp += "\\.";
} else {
- tmp += *i;
+ tmp += *i;
}
++i;
@@ -686,24 +658,28 @@ string IMAPdirDepot::filenameToMailbox(const string &m) const
bool escape = false;
// hide the magic "." mailbox.
- if (m == "." || m == "..")
- return "";
+ if (m == "." || m == "..") return "";
string::const_iterator i = m.begin();
while (i != m.end()) {
if (*i == '.') {
- if (i != m.begin() && !escape) tmp += delimiter;
- else if (i == m.begin() || escape) tmp += '.';
+ if (i != m.begin() && !escape)
+ tmp += delimiter;
+ else if (i == m.begin() || escape)
+ tmp += '.';
escape = false;
} else if (*i == '\\') {
- if (!escape) escape = true; else {
+ if (!escape)
+ escape = true;
+ else {
tmp += '\\';
escape = false;
}
} else if (*i == delimiter) {
return "";
} else {
- if (escape) return "";
+ if (escape)
+ return "";
else {
tmp += *i;
escape = false;
diff --git a/src/greeting.cc b/src/greeting.cc
index 3a2a394..95e93c0 100644
--- a/src/greeting.cc
+++ b/src/greeting.cc
@@ -4,12 +4,12 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <time.h>
-
+#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
#include "session.h"
-#include "globals.h"
+
+#include <time.h>
using namespace ::std;
using namespace Binc;
@@ -20,7 +20,6 @@ namespace Binc {
void showGreeting(void);
};
-
//------------------------------------------------------------------------
void Binc::showGreeting(void)
{
@@ -31,16 +30,11 @@ void Binc::showGreeting(void)
char mytime[ISO8601SIZE];
unsigned int size = strftime(mytime, sizeof(mytime), "%Y-%m-%d %H:%M:%S %z", mytm);
- if (size >= sizeof(mytime) || size == 0)
- mytime[0] = 0;
+ if (size >= sizeof(mytime) || size == 0) mytime[0] = 0;
if (session.hasEnv("VERBOSE_GREETING")) {
- bincClient << "* OK Welcome to Binc IMAP "
- << BINC_VERSION
- << " "
- << IMAP_VERSION
- << " by Andreas Aardal Hanssen & Erwin Hoffmann at "
- << mytime << endl;
+ bincClient << "* OK Welcome to Binc IMAP " << BINC_VERSION << " " << IMAP_VERSION
+ << " by Andreas Aardal Hanssen & Erwin Hoffmann at " << mytime << endl;
} else {
bincClient << "* OK Welcome to Binc IMAP at " << mytime << endl;
}
diff --git a/src/imapparser.cc b/src/imapparser.cc
index 2e7d746..fc2e071 100644
--- a/src/imapparser.cc
+++ b/src/imapparser.cc
@@ -2,32 +2,32 @@
* @file imapparser.cc
* @brief Implementation of the common items for parsing IMAP input
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
#include "imapparser.h"
+
#include "convert.h"
-#include <stdio.h>
-#include <map>
+#include <exception>
#include <iostream>
-#include <vector>
+#include <map>
#include <string>
-#include <exception>
+#include <vector>
+
+#include <stdio.h>
using namespace ::std;
using namespace Binc;
//------------------------------------------------------------------------
-Request::Request(void)
- : extra(0), flags(), statuses(), bset(), searchkey(), fatt()
+Request::Request(void) : extra(0), flags(), statuses(), bset(), searchkey(), fatt()
{
uidmode = false;
}
Request::~Request(void)
{
- if (extra != 0)
- delete extra;
+ if (extra != 0) delete extra;
}
//------------------------------------------------------------------------
@@ -62,7 +62,7 @@ void Request::setMode(const string &m_in)
//------------------------------------------------------------------------
const string &Request::getMode(void) const
-{
+{
return mode;
}
@@ -218,18 +218,17 @@ vector<string> &Request::getFlags(void)
}
//------------------------------------------------------------------------
-SequenceSet::SequenceSet(void) : limited(true), nullSet(false)
-{
-}
+SequenceSet::SequenceSet(void) : limited(true), nullSet(false) {}
//------------------------------------------------------------------------
-SequenceSet::SequenceSet(const SequenceSet &copy)
- : limited(copy.limited), nullSet(copy.nullSet), internal(copy.internal)
-{
-}
+SequenceSet::SequenceSet(const SequenceSet &copy)
+ : limited(copy.limited)
+ , nullSet(copy.nullSet)
+ , internal(copy.internal)
+{}
//------------------------------------------------------------------------
-SequenceSet &SequenceSet::operator = (const SequenceSet &copy)
+SequenceSet &SequenceSet::operator=(const SequenceSet &copy)
{
limited = copy.limited;
nullSet = copy.nullSet;
@@ -239,9 +238,7 @@ SequenceSet &SequenceSet::operator = (const SequenceSet &copy)
}
//------------------------------------------------------------------------
-SequenceSet::~SequenceSet(void)
-{
-}
+SequenceSet::~SequenceSet(void) {}
//------------------------------------------------------------------------
SequenceSet &SequenceSet::null(void)
@@ -301,11 +298,12 @@ void SequenceSet::addNumber(unsigned int a)
bool SequenceSet::isInSet(unsigned int n) const
{
unsigned int maxvalue = 0;
- for (vector<Range>::const_iterator i = internal.begin();
- i != internal.end(); ++i) {
+ for (vector<Range>::const_iterator i = internal.begin(); i != internal.end(); ++i) {
const Range &r = *i;
- if (r.from > maxvalue) maxvalue = r.from;
- else if (r.to > maxvalue) maxvalue = r.to;
+ if (r.from > maxvalue)
+ maxvalue = r.from;
+ else if (r.to > maxvalue)
+ maxvalue = r.to;
if (n >= (*i).from && n <= (*i).to) {
return true;
@@ -316,11 +314,10 @@ bool SequenceSet::isInSet(unsigned int n) const
}
//------------------------------------------------------------------------
-BincImapParserFetchAtt::BincImapParserFetchAtt(const std::string &typeName)
- : type(typeName)
+BincImapParserFetchAtt::BincImapParserFetchAtt(const std::string &typeName) : type(typeName)
{
offsetstart = 0;
- offsetlength = (unsigned int) -1;
+ offsetlength = (unsigned int)-1;
hassection = false;
}
@@ -338,24 +335,21 @@ string BincImapParserFetchAtt::toString(void)
tmp += "[";
tmp += section;
if (sectiontext != "") {
- if (section != "")
- tmp += ".";
+ if (section != "") tmp += ".";
tmp += sectiontext;
if (headerlist.size() > 0) {
tmp += " (";
- for (vector<string>::iterator i = headerlist.begin();
- i != headerlist.end(); ++i) {
- if (i != headerlist.begin())
- tmp += " ";
- tmp += Binc::toImapString(*i);
- }
+ for (vector<string>::iterator i = headerlist.begin(); i != headerlist.end(); ++i) {
+ if (i != headerlist.begin()) tmp += " ";
+ tmp += Binc::toImapString(*i);
+ }
tmp += ")";
}
}
tmp += "]";
- if (offsetstart == 0 && offsetlength == (unsigned int) -1)
+ if (offsetstart == 0 && offsetlength == (unsigned int)-1)
tmp += " ";
else
tmp += "<" + Binc::toString(offsetstart) + "> ";
@@ -373,7 +367,7 @@ BincImapParserSearchKey::BincImapParserSearchKey(void)
}
//------------------------------------------------------------------------
-const SequenceSet& BincImapParserSearchKey::getSet(void) const
+const SequenceSet &BincImapParserSearchKey::getSet(void) const
{
return bset;
}
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();
diff --git a/src/include/argparser.h b/src/include/argparser.h
index 6106974..ba7838d 100644
--- a/src/include/argparser.h
+++ b/src/include/argparser.h
@@ -18,8 +18,7 @@ namespace Binc {
bool o;
std::string desc;
- inline ArgOpts(const std::string &chr, bool boolean, bool optional,
- const std::string &descr)
+ inline ArgOpts(const std::string &chr, bool boolean, bool optional, const std::string &descr)
{
c = chr;
b = boolean;
@@ -37,12 +36,10 @@ namespace Binc {
int argc(void) const;
- const std::string operator [](const std::string &arg) const;
+ const std::string operator[](const std::string &arg) const;
- void addOptional(const std::string &arg, const std::string &desc,
- bool boolean);
- void addRequired(const std::string &arg, const std::string &desc,
- bool boolean);
+ void addOptional(const std::string &arg, const std::string &desc, bool boolean);
+ void addRequired(const std::string &arg, const std::string &desc, bool boolean);
bool hasArg(const std::string &arg) const;
std::string usageString(void) const;
@@ -52,8 +49,7 @@ namespace Binc {
const std::vector<std::string> &getUnqualifiedArgs() const;
private:
- void registerArg(const std::string &arg, const std::string &desc,
- bool boolean, bool optional);
+ void registerArg(const std::string &arg, const std::string &desc, bool boolean, bool optional);
std::string errString;
std::map<std::string, ArgOpts> reg;
diff --git a/src/include/authenticate.h b/src/include/authenticate.h
index 0ef6796..a3d63ce 100644
--- a/src/include/authenticate.h
+++ b/src/include/authenticate.h
@@ -6,13 +6,15 @@
* ----------------------------------------------------------------- **/
#ifndef authenticate_h_included
#define authenticate_h_included
-#include <string>
-
#include "depot.h"
+#include <string>
+
namespace Binc {
- int authenticate(Depot &, const std::string &username,
- const std::string &password, const std::string &challenge);
+ int authenticate(Depot &,
+ const std::string &username,
+ const std::string &password,
+ const std::string &challenge);
}
#endif
diff --git a/src/include/broker.h b/src/include/broker.h
index 6d148ae..ac78041 100644
--- a/src/include/broker.h
+++ b/src/include/broker.h
@@ -9,8 +9,8 @@
#include "depot.h"
#include "operators.h"
-#include <string>
#include <map>
+#include <string>
namespace Binc {
@@ -60,7 +60,7 @@ namespace Binc {
std::map<std::string, bool> deletables;
public:
- Operator * get(const std::string &name) const;
+ Operator *get(const std::string &name) const;
void assign(const std::string &fname, Operator *o, bool deletable = false);
Operator::ParseResult parseStub(Request &cmd);
@@ -71,13 +71,9 @@ namespace Binc {
~Broker(void);
};
- inline Broker::Broker(Broker &)
- {
- }
+ inline Broker::Broker(Broker &) {}
- inline Broker::Broker(const Broker &)
- {
- }
+ inline Broker::Broker(const Broker &) {}
}
diff --git a/src/include/convert.h b/src/include/convert.h
index cea2906..9e51027 100644
--- a/src/include/convert.h
+++ b/src/include/convert.h
@@ -2,22 +2,23 @@
* @file convert.h
* @brief Declaration of miscellaneous convertion functions.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
#ifndef convert_h_included
#define convert_h_included
+#include "address.h"
+#include "depot.h"
+
#include <cstring>
-#include <string>
-#include <vector>
#include <iomanip>
#include <iostream>
+#include <string>
+#include <vector>
#include <stdio.h>
-#include <sys/stat.h>
-#include "address.h"
-#include "depot.h"
+#include <sys/stat.h>
namespace Binc {
@@ -67,7 +68,7 @@ namespace Binc {
tmp += hexchars[((c & 0xf0) >> 4)];
tmp += hexchars[c & 0x0f];
}
-
+
return tmp;
}
@@ -77,8 +78,7 @@ namespace Binc {
// const
char hexchars[] = "0123456789abcdef";
std::string tmp;
- for (std::string::const_iterator i = s.begin();
- i != s.end() && i + 1 != s.end(); i += 2) {
+ for (std::string::const_iterator i = s.begin(); i != s.end() && i + 1 != s.end(); i += 2) {
int n;
unsigned char c = *i;
unsigned char d = *(i + 1);
@@ -91,14 +91,14 @@ namespace Binc {
n += (t - hexchars);
if (n >= 0 && n <= 255)
- tmp += (char) n;
+ tmp += (char)n;
else
return "out of range";
}
return tmp;
}
-
+
//----------------------------------------------------------------------
inline std::string toImapString(const std::string &s_in)
{
@@ -142,8 +142,7 @@ namespace Binc {
}
//----------------------------------------------------------------------
- inline const std::string unfold(const std::string &a,
- bool removecomment = true)
+ inline const std::string unfold(const std::string &a, bool removecomment = true)
{
std::string tmp;
bool incomment = false;
@@ -152,55 +151,55 @@ namespace Binc {
unsigned char c = (unsigned char)*i;
if (!inquotes && removecomment) {
if (c == '(') {
- incomment = true;
+ incomment = true;
tmp += " ";
} else if (c == ')') {
- incomment = false;
+ incomment = false;
} else if (c != 0x0a && c != 0x0d) {
- tmp += *i;
+ tmp += *i;
}
} else if (c != 0x0a && c != 0x0d) {
- tmp += *i;
+ tmp += *i;
}
if (!incomment) {
- if (*i == '\"')
- inquotes = !inquotes;
+ if (*i == '\"') inquotes = !inquotes;
}
}
trim(tmp);
return tmp;
}
-
+
//----------------------------------------------------------------------
- inline void split(const std::string &s_in, const std::string &delim,
- std::vector<std::string> &dest, bool skipempty = true)
+ inline void split(const std::string &s_in,
+ const std::string &delim,
+ std::vector<std::string> &dest,
+ bool skipempty = true)
{
std::string token;
for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
if (delim.find(*i) != std::string::npos) {
- if (!skipempty || token != "")
- dest.push_back(token);
+ if (!skipempty || token != "") dest.push_back(token);
token = "";
} else
token += *i;
}
- if (token != "")
- dest.push_back(token);
+ if (token != "") dest.push_back(token);
}
//----------------------------------------------------------------------
- inline void splitAddr(const std::string &s_in,
- std::vector<std::string> &dest, bool skipempty = true)
+ inline void splitAddr(const std::string &s_in, std::vector<std::string> &dest, bool skipempty = true)
{
static const std::string delim = ",";
std::string token;
bool inquote = false;
for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
- if (inquote && *i == '\"') inquote = false;
- else if (!inquote && *i == '\"') inquote = true;
+ if (inquote && *i == '\"')
+ inquote = false;
+ else if (!inquote && *i == '\"')
+ inquote = true;
if (!inquote && delim.find(*i) != std::string::npos) {
if (!skipempty || token != "") dest.push_back(token);
@@ -208,8 +207,7 @@ namespace Binc {
} else
token += *i;
}
- if (token != "")
- dest.push_back(token);
+ if (token != "") dest.push_back(token);
}
//----------------------------------------------------------------------
@@ -220,8 +218,7 @@ namespace Binc {
if (s_in.length() >= 5) {
std::string a = s_in.substr(0, 5);
uppercase(a);
- return a == "INBOX" ?
- a + (s_in.length() > 5 ? s_in.substr(5) : "") : s_in;
+ return a == "INBOX" ? a + (s_in.length() > 5 ? s_in.substr(5) : "") : s_in;
}
return s_in;
@@ -232,22 +229,22 @@ namespace Binc {
{
std::string regex = "^";
for (std::string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
- if (*i == '.' || *i == '[' || *i == ']' || *i == '{' || *i == '}' ||
- *i == '(' || *i == ')' || *i == '^' || *i == '$' || *i == '?' ||
- *i == '+' || *i == '\\') {
- regex += "\\";
- regex += *i;
- } else if (*i == '*')
- regex += ".*?";
- else if (*i == '%') {
- regex += "(\\";
- regex += delimiter;
- regex += "){0,1}";
- regex += "[^\\";
- regex += delimiter;
- regex += "]*?";
- } else
- regex += *i;
+ if (*i == '.' || *i == '[' || *i == ']' || *i == '{' || *i == '}' || *i == '(' || *i == ')'
+ || *i == '^' || *i == '$' || *i == '?' || *i == '+' || *i == '\\')
+ {
+ regex += "\\";
+ regex += *i;
+ } else if (*i == '*')
+ regex += ".*?";
+ else if (*i == '%') {
+ regex += "(\\";
+ regex += delimiter;
+ regex += "){0,1}";
+ regex += "[^\\";
+ regex += delimiter;
+ regex += "]*?";
+ } else
+ regex += *i;
}
if (regex[regex.length() - 1] == '?')
@@ -265,12 +262,12 @@ namespace Binc {
public:
//--
- BincStream &operator << (std::ostream&(*)(std::ostream&));
- BincStream &operator << (const std::string &t);
- BincStream &operator << (unsigned long t);
- BincStream &operator << (unsigned int t);
- BincStream &operator << (int t);
- BincStream &operator << (char t);
+ BincStream &operator<<(std::ostream &(*)(std::ostream &));
+ BincStream &operator<<(const std::string &t);
+ BincStream &operator<<(unsigned long t);
+ BincStream &operator<<(unsigned int t);
+ BincStream &operator<<(int t);
+ BincStream &operator<<(char t);
//--
std::string popString(unsigned int size);
diff --git a/src/include/depot.h b/src/include/depot.h
index 844a987..bd4f743 100644
--- a/src/include/depot.h
+++ b/src/include/depot.h
@@ -38,10 +38,10 @@ namespace Binc {
//--
class iterator {
public:
- std::string operator * (void) const;
- void operator ++ (void);
- bool operator != (iterator) const;
- bool operator == (iterator) const;
+ std::string operator*(void) const;
+ void operator++(void);
+ bool operator!=(iterator) const;
+ bool operator==(iterator) const;
iterator(void);
iterator(const iterator &copy);
@@ -50,7 +50,7 @@ namespace Binc {
void deref(void);
- iterator &operator =(const iterator &copy);
+ iterator &operator=(const iterator &copy);
friend class Depot;
@@ -134,6 +134,7 @@ namespace Binc {
//--
MaildirPPDepot();
~MaildirPPDepot();
+
private:
std::string privateNamespace;
};
diff --git a/src/include/globals.h b/src/include/globals.h
index dd63b5f..d86ae4d 100644
--- a/src/include/globals.h
+++ b/src/include/globals.h
@@ -9,15 +9,15 @@
#define BINC_VERSION "2.0.14"
#define IMAP_VERSION "IMAP4rev1"
-#define BINC_CACHE "BINC-CACHE-1.0"
-#define IMAP_PORT "143"
-#define IMAPS_PORT "993"
+#define BINC_CACHE "BINC-CACHE-1.0"
+#define IMAP_PORT "143"
+#define IMAPS_PORT "993"
namespace Binc {
- static const int IDLE_TIMEOUT = 30*60;
+ static const int IDLE_TIMEOUT = 30 * 60;
static const int AUTH_TIMEOUT = 60;
static const int AUTH_PENALTY = 5;
- static const int TRANSFER_TIMEOUT = 20*60;
+ static const int TRANSFER_TIMEOUT = 20 * 60;
static const int TRANSFER_BUFFER_SIZE = 1024;
static const int INPUT_BUFFER_LIMIT = 8192;
diff --git a/src/include/imapparser.h b/src/include/imapparser.h
index 4f77985..5dfffb4 100644
--- a/src/include/imapparser.h
+++ b/src/include/imapparser.h
@@ -2,14 +2,14 @@
* @file imapparser.h
* @brief Declaration of the common items for parsing IMAP input
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
#ifndef imapparser_h_included
#define imapparser_h_included
/* stl includes */
-#include <string>
#include <map>
+#include <string>
#include <vector>
namespace Binc {
@@ -19,13 +19,17 @@ namespace Binc {
void addRange(unsigned int a_in, unsigned int b_in);
bool isInSet(unsigned int n) const;
void addNumber(unsigned int a_in);
- inline bool isLimited(void) const { return limited; }
+
+ inline bool isLimited(void) const
+ {
+ return limited;
+ }
static SequenceSet &all(void);
static SequenceSet &null(void);
- SequenceSet &operator = (const SequenceSet &copy);
+ SequenceSet &operator=(const SequenceSet &copy);
SequenceSet(void);
SequenceSet(const SequenceSet &copy);
@@ -74,11 +78,12 @@ namespace Binc {
int type;
unsigned int number;
SequenceSet bset;
- enum {KEY_AND, KEY_OR, KEY_NOT, KEY_OTHER, KEY_SET};
-
+
+ enum { KEY_AND, KEY_OR, KEY_NOT, KEY_OTHER, KEY_SET };
+
std::vector<BincImapParserSearchKey> children;
- const SequenceSet& getSet(void) const;
+ const SequenceSet &getSet(void) const;
BincImapParserSearchKey(void);
};
@@ -106,9 +111,9 @@ namespace Binc {
std::string literal;
std::string contextInfo;
bool uidmode;
-
+
public:
- BincImapParserData * extra;
+ BincImapParserData *extra;
std::vector<std::string> flags;
std::vector<std::string> statuses;
diff --git a/src/include/imapserver.h b/src/include/imapserver.h
index 940234e..d3268ba 100644
--- a/src/include/imapserver.h
+++ b/src/include/imapserver.h
@@ -19,7 +19,7 @@ namespace Binc {
enum ServerStatus {
OK,
RequestError,
- RequestIgnore, // required for StartTLS, premature answer
+ RequestIgnore, // required for StartTLS, premature answer
RequestRejected,
ClientDisconnected,
Timeout
diff --git a/src/include/iodevice.h b/src/include/iodevice.h
index 070ac3f..73dd2ab 100644
--- a/src/include/iodevice.h
+++ b/src/include/iodevice.h
@@ -7,12 +7,13 @@
#ifndef iodevice_h_included
#define iodevice_h_included
-#include "convert.h" // BincStream
-//#include <iostream>
+#include "convert.h" // BincStream
+// #include <iostream>
#include <string>
-#include <unistd.h> // ::write
-const char CMS_END_OF_LINE[4] = { 0x0d, '\n', 0x00, 0x00 };
+#include <unistd.h> // ::write
+
+const char CMS_END_OF_LINE[4] = {0x0d, '\n', 0x00, 0x00};
namespace Binc {
/*!
@@ -45,13 +46,10 @@ namespace Binc {
/*!
Errors from when an operation returned false.
*/
- enum Error {
- Unknown,
- Timeout
- };
+ enum Error { Unknown, Timeout };
/*!
- Constructs an invalid IODevice.
+ Constructs an invalid IODevice.
Instances of IODevice perform no operations, and all boolean
functions always return false. This constructor is only useful
@@ -132,13 +130,8 @@ namespace Binc {
*/
unsigned int getTimeout(void) const;
- enum LogLevel {
- ErrorLevel,
- InfoLevel,
- WarningLevel,
- DebugLevel
- };
-
+ enum LogLevel { ErrorLevel, InfoLevel, WarningLevel, DebugLevel };
+
/*!
Sets the output level for the following write operations on this
device.
@@ -210,13 +203,13 @@ namespace Binc {
\sa setMaxOutputBufferSize()
*/
- template <class T> IODevice &operator << (const T &source);
+ template<class T> IODevice &operator<<(const T &source);
/*!
Writes data to the device. This function specializes on standard
ostream derivates, such as std::endl.
*/
- IODevice &operator << (std::ostream &(*source)(std::ostream &));
+ IODevice &operator<<(std::ostream &(*source)(std::ostream &));
/*!
Returns true if data can be read from the device; otherwise
@@ -227,7 +220,7 @@ namespace Binc {
/*!
Reads data from the device, and stores this in a string. Returns
true on success; otherwise returns false.
-
+
\param dest The incoming data is stored in this string.
\param max No more than this number of bytes is read from the
device.
@@ -286,7 +279,7 @@ namespace Binc {
return values are "client" and "log".
*/
virtual std::string service(void) const;
-
+
protected:
/*!
Waits until data can be written to the device. If the timeout is
@@ -308,13 +301,9 @@ namespace Binc {
virtual bool waitForRead(void) const;
/*!
- Types of results from a write.
+ Types of results from a write.
*/
- enum WriteResult {
- WriteWait = 0,
- WriteDone = 1 << 0,
- WriteError = 1 << 1
- };
+ enum WriteResult { WriteWait = 0, WriteDone = 1 << 0, WriteError = 1 << 1 };
/*!
Writes as much data as possible to the device. If some but not
@@ -327,7 +316,7 @@ namespace Binc {
/*!
Reads data from the device, and stores it in the input buffer.
Returns true on success; otherwise returns false.
-
+
This method will fail if there is no more data available, if a
timeout occurred or if an error with the device prevents more
data from being read.
@@ -359,20 +348,19 @@ namespace Binc {
};
//----------------------------------------------------------------------
- template <class T> IODevice &IODevice::operator << (const T &source)
+ template<class T> IODevice &IODevice::operator<<(const T &source)
{
if ((flags & IsEnabled) && outputLevel <= outputLevelLimit) {
outputBuffer << source;
- if (dumpfd) {
- BincStream ss;
+ if (dumpfd) {
+ BincStream ss;
ss << source;
- ::write(dumpfd, ss.str().c_str(), ss.getSize());
+ ::write(dumpfd, ss.str().c_str(), ss.getSize());
}
if (flags & HasInputLimit)
- if (outputBuffer.getSize() > maxOutputBufferSize)
- flush();
+ if (outputBuffer.getSize() > maxOutputBufferSize) flush();
}
return *this;
diff --git a/src/include/iofactory.h b/src/include/iofactory.h
index 6ebccaa..1a50e4e 100644
--- a/src/include/iofactory.h
+++ b/src/include/iofactory.h
@@ -6,11 +6,11 @@
* ----------------------------------------------------------------- **/
#ifndef IOFACTORY_H_INCLUDED
#define IOFACTORY_H_INCLUDED
+#include "iodevice.h"
+
#include <map>
#include <string>
-#include "iodevice.h"
-
namespace Binc {
class IOFactory {
public:
@@ -23,31 +23,34 @@ namespace Binc {
private:
IOFactory(void);
-
+
std::map<std::string, IODevice *> devices;
};
}
-#define bincClient \
- IOFactory::getClient()
+#define bincClient IOFactory::getClient()
-#if defined (DEBUG)
-//#define bincError if (false) std::cout
+#if defined(DEBUG)
+// #define bincError if (false) std::cout
#define bincError std::cerr
// #define bincWarning if (false) std::cout
#define bincWarning std::cerr
-#define bincDebug std::cerr
-//#define bincDebug if (false) std::cout
+#define bincDebug std::cerr
+// #define bincDebug if (false) std::cout
#else
-#define bincError \
- IOFactory::getLogger().setOutputLevel(IODevice::ErrorLevel);IOFactory::getLogger()
-#define bincWarning \
- IOFactory::getLogger().setOutputLevel(IODevice::WarningLevel);IOFactory::getLogger()
-#define bincDebug \
- IOFactory::getLogger().setOutputLevel(IODevice::DebugLevel);IOFactory::getLogger()
+#define bincError \
+ IOFactory::getLogger().setOutputLevel(IODevice::ErrorLevel); \
+ IOFactory::getLogger()
+#define bincWarning \
+ IOFactory::getLogger().setOutputLevel(IODevice::WarningLevel); \
+ IOFactory::getLogger()
+#define bincDebug \
+ IOFactory::getLogger().setOutputLevel(IODevice::DebugLevel); \
+ IOFactory::getLogger()
#endif
-#define bincLog \
- IOFactory::getLogger().setOutputLevel(IODevice::InfoLevel);IOFactory::getLogger()
+#define bincLog \
+ IOFactory::getLogger().setOutputLevel(IODevice::InfoLevel); \
+ IOFactory::getLogger()
#endif
diff --git a/src/include/mailbox.h b/src/include/mailbox.h
index db98cc0..870a695 100644
--- a/src/include/mailbox.h
+++ b/src/include/mailbox.h
@@ -7,17 +7,18 @@
#ifndef mailbox_h_included
#define mailbox_h_included
+#include "imapparser.h"
+
#include <map>
-#include <string>
#include <queue>
+#include <string>
#include <vector>
-#include <time.h>
#include <stdio.h>
#include <string.h>
-#include <sys/types.h>
+#include <time.h>
-#include "imapparser.h"
+#include <sys/types.h>
namespace Binc {
@@ -29,17 +30,16 @@ namespace Binc {
//------------------------------------------------------------------------
class Mailbox {
public:
-
//----------------------------------------------------------------------
class BaseIterator {
public:
BaseIterator(int sqn = 0);
virtual ~BaseIterator(void);
- virtual Message &operator *(void) = 0;
- virtual void operator ++(void) = 0;
- virtual bool operator !=(const BaseIterator &d) const = 0;
- virtual bool operator ==(const BaseIterator &d) const = 0;
+ virtual Message &operator*(void) = 0;
+ virtual void operator++(void) = 0;
+ virtual bool operator!=(const BaseIterator &d) const = 0;
+ virtual bool operator==(const BaseIterator &d) const = 0;
virtual void erase(void) = 0;
@@ -51,10 +51,10 @@ namespace Binc {
public:
iterator(BaseIterator &i);
- Message &operator *(void);
- void operator ++(void);
- bool operator ==(const iterator &) const;
- bool operator !=(const iterator &) const;
+ Message &operator*(void);
+ void operator++(void);
+ bool operator==(const iterator &) const;
+ bool operator!=(const iterator &) const;
unsigned int getSqnr() const;
@@ -64,17 +64,12 @@ namespace Binc {
BaseIterator &realIterator;
};
- enum Iterator {
- INCLUDE_EXPUNGED = 1,
- SKIP_EXPUNGED = 2
- };
+ enum Iterator { INCLUDE_EXPUNGED = 1, SKIP_EXPUNGED = 2 };
- enum Mode {
- UID_MODE = 4,
- SQNR_MODE = 8
- };
+ enum Mode { UID_MODE = 4, SQNR_MODE = 8 };
- virtual iterator begin(const SequenceSet &bset, unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const = 0;
+ virtual iterator begin(const SequenceSet &bset,
+ unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const = 0;
virtual iterator end(void) const = 0;
//-- Generic for one mailbox type
@@ -97,13 +92,16 @@ namespace Binc {
virtual unsigned int getUidNext(void) const = 0;
virtual unsigned int getUidValidity(void) const = 0;
- virtual bool getUpdates(bool scan, unsigned int type,
- PendingUpdates &updates, bool forceScan) = 0;
+ virtual bool getUpdates(bool scan, unsigned int type, PendingUpdates &updates, bool forceScan) = 0;
virtual void updateFlags(void) = 0;
virtual void expungeMailbox(void) = 0;
virtual bool selectMailbox(const std::string &name, const std::string &s_in) = 0;
- virtual bool createMailbox(const std::string &s, mode_t mode, uid_t owner = 0, gid_t group = 0, bool root = false) = 0;
+ virtual bool createMailbox(const std::string &s,
+ mode_t mode,
+ uid_t owner = 0,
+ gid_t group = 0,
+ bool root = false) = 0;
virtual bool deleteMailbox(const std::string &s) = 0;
virtual void closeMailbox(void) = 0;
diff --git a/src/include/maildir.h b/src/include/maildir.h
index 4a262b5..dda88df 100644
--- a/src/include/maildir.h
+++ b/src/include/maildir.h
@@ -6,13 +6,13 @@
* ----------------------------------------------------------------- **/
#ifndef maildir_h_included
#define maildir_h_included
-#include <string>
-#include <vector>
-#include <map>
-
#include "mailbox.h"
#include "maildirmessage.h"
+#include <map>
+#include <string>
+#include <vector>
+
namespace Binc {
static const std::string CACHEFILEVERSION = "1.0.5";
static const std::string UIDVALFILEVERSION = "1.0.5";
@@ -26,7 +26,7 @@ namespace Binc {
private:
std::string lock;
};
-
+
//------------------------------------------------------------------------
class MaildirIndexItem {
public:
@@ -35,14 +35,12 @@ namespace Binc {
};
//------------------------------------------------------------------------
- class MaildirIndex
- {
+ class MaildirIndex {
private:
std::map<std::string, MaildirIndexItem> idx;
public:
- void insert(const std::string &unique, unsigned int uid,
- const std::string &fileName = "");
+ void insert(const std::string &unique, unsigned int uid, const std::string &fileName = "");
void remove(const std::string &unique);
void clear(void);
void clearFileNames(void);
@@ -59,18 +57,19 @@ namespace Binc {
class iterator : public BaseIterator {
public:
iterator(void);
- iterator(Maildir *home, MessageMap::iterator i,
+ iterator(Maildir *home,
+ MessageMap::iterator i,
const SequenceSet &bset,
unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE);
iterator(const iterator &copy);
~iterator(void);
- Message &operator *(void);
- void operator ++(void);
- bool operator ==(const BaseIterator &) const;
- bool operator !=(const BaseIterator &) const;
+ Message &operator*(void);
+ void operator++(void);
+ bool operator==(const BaseIterator &) const;
+ bool operator!=(const BaseIterator &) const;
- iterator &operator =(const iterator &copy);
+ iterator &operator=(const iterator &copy);
void erase(void);
@@ -94,7 +93,8 @@ namespace Binc {
const std::string getTypeName(void) const;
- Mailbox::iterator begin(const SequenceSet &bset, unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const;
+ Mailbox::iterator begin(const SequenceSet &bset,
+ unsigned int mod = INCLUDE_EXPUNGED | SQNR_MODE) const;
Mailbox::iterator end(void) const;
unsigned int getMaxUid(void) const;
@@ -102,8 +102,7 @@ namespace Binc {
unsigned int getUidValidity(void) const;
unsigned int getUidNext(void) const;
- bool getUpdates(bool doscan, unsigned int type,
- PendingUpdates &updates, bool forceScan);
+ bool getUpdates(bool doscan, unsigned int type, PendingUpdates &updates, bool forceScan);
const std::string &getPath(void) const;
void setPath(const std::string &path_in);
@@ -119,7 +118,11 @@ namespace Binc {
bool selectMailbox(const std::string &name, const std::string &s_in);
void closeMailbox(void);
void expungeMailbox(void);
- bool createMailbox(const std::string &s, mode_t mode, uid_t owner = 0, gid_t group = 0, bool root = false);
+ bool createMailbox(const std::string &s,
+ mode_t mode,
+ uid_t owner = 0,
+ gid_t group = 0,
+ bool root = false);
bool deleteMailbox(const std::string &s);
Message *createMessage(const std::string &mbox, time_t idate = 0);
@@ -136,21 +139,13 @@ namespace Binc {
friend class MaildirMessage;
protected:
- enum ReadCacheResult {
- Ok,
- NoCache,
- Error
- };
+ enum ReadCacheResult { Ok, NoCache, Error };
ReadCacheResult readCache(void);
bool writeCache(void);
bool scanFileNames(void) const;
- enum ScanResult {
- Success = 0,
- TemporaryError = 1,
- PermanentError = 2
- };
+ enum ScanResult { Success = 0, TemporaryError = 1, PermanentError = 2 };
ScanResult scan(bool forceScan = false);
diff --git a/src/include/maildirmessage.h b/src/include/maildirmessage.h
index 9e9c717..6bc2a20 100644
--- a/src/include/maildirmessage.h
+++ b/src/include/maildirmessage.h
@@ -6,19 +6,19 @@
* ----------------------------------------------------------------- **/
#ifndef maildirmessage_h_included
#define maildirmessage_h_included
-#include <string>
-#include <map>
-#include <vector>
+#include "address.h"
+#include "message.h"
+#include "mime.h"
+
#include <exception>
#include <iostream>
-#include <time.h>
+#include <map>
+#include <string>
+#include <vector>
#include <stdio.h>
#include <string.h>
-
-#include "message.h"
-#include "address.h"
-#include "mime.h"
+#include <time.h>
namespace Binc {
@@ -84,7 +84,7 @@ namespace Binc {
unsigned char getStdFlags(void) const;
/*
- */
+ */
void setCustomFlag(const std::string &flag);
void removeCustomFlag(const std::string &flag);
void resetCustomFlags(void);
@@ -187,8 +187,7 @@ namespace Binc {
*/
const std::string &getHeader(const std::string &header);
- bool headerContains(const std::string &header,
- const std::string &text);
+ bool headerContains(const std::string &header, const std::string &text);
bool bodyContains(const std::string &text);
bool textContains(const std::string &text);
@@ -202,7 +201,7 @@ namespace Binc {
bool includeHeaders = false,
unsigned int startOffset = 0,
unsigned int length = UINTMAX,
- bool mime = false) const;
+ bool mime = false) const;
unsigned int getHeaderSize(const std::string &section,
std::vector<std::string> headers,
@@ -214,9 +213,9 @@ namespace Binc {
bool printBody(const std::string &section = "",
unsigned int startOffset = 0,
unsigned int length = UINTMAX) const;
- unsigned int getBodySize(const std::string &section,
- unsigned int startOffset = 0,
- unsigned int length = UINTMAX) const;
+ unsigned int getBodySize(const std::string &section,
+ unsigned int startOffset = 0,
+ unsigned int length = UINTMAX) const;
bool printDoc(unsigned int startOffset = 0,
unsigned int length = UINTMAX,
@@ -235,10 +234,10 @@ namespace Binc {
friend class Maildir;
- bool operator < (const MaildirMessage &a) const;
+ bool operator<(const MaildirMessage &a) const;
MaildirMessage(const MaildirMessage &copy);
- MaildirMessage &operator = (const MaildirMessage &copy);
+ MaildirMessage &operator=(const MaildirMessage &copy);
enum Flags {
None = 0x00,
@@ -280,16 +279,11 @@ namespace Binc {
};
//------------------------------------------------------------------------
- class MaildirMessageCache
- {
+ class MaildirMessageCache {
public:
~MaildirMessageCache();
- enum ParseStatus {
- NotParsed,
- HeaderParsed,
- AllParsed
- };
+ enum ParseStatus { NotParsed, HeaderParsed, AllParsed };
static MaildirMessageCache &getInstance(void);
diff --git a/src/include/message.h b/src/include/message.h
index 76607e5..e1bbf2b 100644
--- a/src/include/message.h
+++ b/src/include/message.h
@@ -6,8 +6,9 @@
* ----------------------------------------------------------------- **/
#ifndef message_h_included
#define message_h_included
-#include <vector>
#include <string>
+#include <vector>
+
#include <time.h>
#ifndef UINTMAX
@@ -30,21 +31,20 @@ namespace Binc {
*/
class Message {
public:
-
/*!
Standard IMAP message flags.
*/
enum Flags {
- F_NONE = 0x00, /*!< No flag is set */
- F_SEEN = 0x01, /*!< The message has been seen */
- F_ANSWERED = 0x02, /*!< The message has been answered */
- F_DELETED = 0x04, /*!< The message is marked as deleted */
- F_DRAFT = 0x08, /*!< The message is a draft */
- F_RECENT = 0x10, /*!< The message arrived recently */
- F_FLAGGED = 0x20, /*!< The message is flagged / important */
- F_EXPUNGED = 0x40, /*!< The message has been expunged */
- F_PASSED = 0x80 /*!< The message has been bounced */
+ F_NONE = 0x00, /*!< No flag is set */
+ F_SEEN = 0x01, /*!< The message has been seen */
+ F_ANSWERED = 0x02, /*!< The message has been answered */
+ F_DELETED = 0x04, /*!< The message is marked as deleted */
+ F_DRAFT = 0x08, /*!< The message is a draft */
+ F_RECENT = 0x10, /*!< The message arrived recently */
+ F_FLAGGED = 0x20, /*!< The message is flagged / important */
+ F_EXPUNGED = 0x40, /*!< The message has been expunged */
+ F_PASSED = 0x80 /*!< The message has been bounced */
};
virtual void setUID(unsigned int) = 0;
@@ -79,8 +79,7 @@ namespace Binc {
virtual const std::string &getHeader(const std::string &header) = 0;
- virtual bool headerContains(const std::string &header,
- const std::string &text) = 0;
+ virtual bool headerContains(const std::string &header, const std::string &text) = 0;
virtual bool bodyContains(const std::string &text) = 0;
virtual bool textContains(const std::string &text) = 0;
@@ -90,11 +89,11 @@ namespace Binc {
virtual bool printEnvelope(void) const = 0;
virtual bool printHeader(const std::string &section,
- std::vector<std::string> headers,
- bool includeHeaders = false,
- unsigned int startOffset = 0,
- unsigned int length = UINTMAX,
- bool mime = false) const = 0;
+ std::vector<std::string> headers,
+ bool includeHeaders = false,
+ unsigned int startOffset = 0,
+ unsigned int length = UINTMAX,
+ bool mime = false) const = 0;
virtual unsigned int getHeaderSize(const std::string &section,
std::vector<std::string> headers,
@@ -129,13 +128,9 @@ namespace Binc {
static std::string lastError;
};
- inline Message::Message(void)
- {
- }
+ inline Message::Message(void) {}
- inline Message::~Message(void)
- {
- }
+ inline Message::~Message(void) {}
inline void Message::setLastError(const std::string &error) const
{
diff --git a/src/include/mime-inputsource.h b/src/include/mime-inputsource.h
index e37d508..8ff97f4 100644
--- a/src/include/mime-inputsource.h
+++ b/src/include/mime-inputsource.h
@@ -8,6 +8,7 @@
#define mime_inputsource_h_included
#include <string.h>
+
#include <unistd.h>
namespace Binc {
@@ -50,9 +51,7 @@ namespace Binc {
seek(start);
}
- inline MimeInputSource::~MimeInputSource(void)
- {
- }
+ inline MimeInputSource::~MimeInputSource(void) {}
inline bool MimeInputSource::fillInputBuffer(void)
{
@@ -67,18 +66,18 @@ namespace Binc {
const char c = raw[i];
if (c == '\r') {
if (lastChar == '\r') {
- data[tail++ & (0x4000-1)] = '\r';
- data[tail++ & (0x4000-1)] = '\n';
+ data[tail++ & (0x4000 - 1)] = '\r';
+ data[tail++ & (0x4000 - 1)] = '\n';
}
} else if (c == '\n') {
- data[tail++ & (0x4000-1)] = '\r';
- data[tail++ & (0x4000-1)] = '\n';
+ data[tail++ & (0x4000 - 1)] = '\r';
+ data[tail++ & (0x4000 - 1)] = '\n';
} else {
if (lastChar == '\r') {
- data[tail++ & (0x4000-1)] = '\r';
- data[tail++ & (0x4000-1)] = '\n';
+ data[tail++ & (0x4000 - 1)] = '\r';
+ data[tail++ & (0x4000 - 1)] = '\n';
}
- data[tail++ & (0x4000-1)] = c;
+ data[tail++ & (0x4000 - 1)] = c;
}
lastChar = c;
@@ -92,15 +91,13 @@ namespace Binc {
offset = head = tail = 0;
lastChar = '\0';
- if (fd != -1)
- lseek(fd, 0, SEEK_SET);
+ if (fd != -1) lseek(fd, 0, SEEK_SET);
}
inline void MimeInputSource::seek(unsigned int seekToOffset)
{
- if (offset > seekToOffset)
- reset();
-
+ if (offset > seekToOffset) reset();
+
char c;
int n = 0;
while (seekToOffset > offset) {
@@ -111,10 +108,9 @@ namespace Binc {
inline bool MimeInputSource::getChar(char *c)
{
- if (head == tail && !fillInputBuffer())
- return false;
+ if (head == tail && !fillInputBuffer()) return false;
- *c = data[head++ & (0x4000-1)];
+ *c = data[head++ & (0x4000 - 1)];
++offset;
return true;
}
diff --git a/src/include/mime-utils.h b/src/include/mime-utils.h
index 732234a..8a59041 100644
--- a/src/include/mime-utils.h
+++ b/src/include/mime-utils.h
@@ -7,19 +7,17 @@
#ifndef mime_utils_h_included
#define mime_utils_h_included
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
-inline bool compareStringToQueue(const char *s_in, char *bqueue,
- int pos, int size)
+inline bool compareStringToQueue(const char *s_in, char *bqueue, int pos, int size)
{
for (int i = 0; i < size; ++i)
- if (s_in[i] != bqueue[(pos + i) % size])
- return false;
+ if (s_in[i] != bqueue[(pos + i) % size]) return false;
return true;
}
diff --git a/src/include/mime.h b/src/include/mime.h
index 2033442..f35ebb2 100644
--- a/src/include/mime.h
+++ b/src/include/mime.h
@@ -6,28 +6,36 @@
* ----------------------------------------------------------------- **/
#ifndef mime_h_included
#define mime_h_included
+#include <map>
#include <string>
#include <vector>
-#include <map>
+
#include <stdio.h>
namespace Binc {
- //----------------------------------------------------------------------
+ //----------------------------------------------------------------------
class HeaderItem {
private:
mutable std::string key;
mutable std::string value;
public:
- inline const std::string &getKey(void) const { return key; }
- inline const std::string &getValue(void) const { return value; }
+ inline const std::string &getKey(void) const
+ {
+ return key;
+ }
+
+ inline const std::string &getValue(void) const
+ {
+ return value;
+ }
//--
HeaderItem(void);
HeaderItem(const std::string &key, const std::string &value);
};
- //----------------------------------------------------------------------
+ //----------------------------------------------------------------------
class Header {
private:
mutable std::vector<HeaderItem> content;
@@ -46,6 +54,7 @@ namespace Binc {
//----------------------------------------------------------------------
class IODevice;
class MimeDocument;
+
class MimePart {
protected:
public:
@@ -64,32 +73,66 @@ namespace Binc {
mutable unsigned int size;
public:
- enum FetchType {
- FetchBody,
- FetchHeader,
- FetchMime
- };
+ enum FetchType { FetchBody, FetchHeader, FetchMime };
mutable Header h;
mutable std::vector<MimePart> members;
- inline const std::string &getSubType(void) const { return subtype; }
- inline bool isMultipart(void) const { return multipart; }
- inline bool isMessageRFC822(void) const { return messagerfc822; }
- inline unsigned int getSize(void) const { return bodylength; }
- inline unsigned int getNofLines(void) const { return nlines; }
- inline unsigned int getNofBodyLines(void) const { return nbodylines; }
- inline unsigned int getBodyLength(void) const { return bodylength; }
- inline unsigned int getBodyStartOffset(void) const { return bodystartoffsetcrlf; }
+ inline const std::string &getSubType(void) const
+ {
+ return subtype;
+ }
+
+ inline bool isMultipart(void) const
+ {
+ return multipart;
+ }
+
+ inline bool isMessageRFC822(void) const
+ {
+ return messagerfc822;
+ }
+
+ inline unsigned int getSize(void) const
+ {
+ return bodylength;
+ }
+
+ inline unsigned int getNofLines(void) const
+ {
+ return nlines;
+ }
+
+ inline unsigned int getNofBodyLines(void) const
+ {
+ return nbodylines;
+ }
+
+ inline unsigned int getBodyLength(void) const
+ {
+ return bodylength;
+ }
+
+ inline unsigned int getBodyStartOffset(void) const
+ {
+ return bodystartoffsetcrlf;
+ }
void printBody(int fd, Binc::IODevice &output, unsigned int startoffset, unsigned int length) const;
- void printHeader(int fd, Binc::IODevice &output, std::vector<std::string> headers,
- bool includeheaders, unsigned int startoffset, unsigned int length, std::string &storage) const;
+ void printHeader(int fd,
+ Binc::IODevice &output,
+ std::vector<std::string> headers,
+ bool includeheaders,
+ unsigned int startoffset,
+ unsigned int length,
+ std::string &storage) const;
void printDoc(int fd, Binc::IODevice &output, unsigned int startoffset, unsigned int length) const;
virtual void clear(void) const;
- const MimePart *getPart(const std::string &findpart, std::string genpart, FetchType fetchType = FetchBody) const;
+ const MimePart *getPart(const std::string &findpart,
+ std::string genpart,
+ FetchType fetchType = FetchBody) const;
virtual int parseOnlyHeader(const std::string &toboundary) const;
virtual int parseFull(const std::string &toboundary, int &boundarysize) const;
@@ -108,8 +151,15 @@ namespace Binc {
void parseFull(int fd) const;
void clear(void) const;
- inline bool isHeaderParsed(void) { return headerIsParsed; }
- inline bool isAllParsed(void) { return allIsParsed; }
+ inline bool isHeaderParsed(void)
+ {
+ return headerIsParsed;
+ }
+
+ inline bool isAllParsed(void)
+ {
+ return allIsParsed;
+ }
//--
MimeDocument(void);
diff --git a/src/include/operators.h b/src/include/operators.h
index c030918..a4e0f74 100644
--- a/src/include/operators.h
+++ b/src/include/operators.h
@@ -6,20 +6,21 @@
* ----------------------------------------------------------------- **/
#ifndef operators_h_included
#define operators_h_included
-#include <string>
-#include <vector>
-
-#include "imapparser.h"
#include "depot.h"
+#include "imapparser.h"
#include "message.h"
+#include <string>
+#include <vector>
+
namespace Binc {
-
+
//--------------------------------------------------------------------
class Operator {
public:
- enum ProcessResult {OK, BAD, NO, NOTHING, ABORT};
- enum ParseResult {ACCEPT, REJECT, ERROR, TIMEOUT};
+ enum ProcessResult { OK, BAD, NO, NOTHING, ABORT };
+
+ enum ParseResult { ACCEPT, REJECT, ERROR, TIMEOUT };
virtual ProcessResult process(Depot &, Request &) = 0;
virtual ParseResult parse(Request &) const = 0;
@@ -27,7 +28,7 @@ namespace Binc {
virtual const std::string getName(void) const = 0;
//--
- virtual ~Operator(void) {};
+ virtual ~Operator(void){};
};
//--------------------------------------------------------------------
@@ -51,10 +52,9 @@ namespace Binc {
const std::string getName(void) const;
int getState(void) const;
- ProcessResult Login(std::string& username, std::string& password);
- ProcessResult Plain(std::string& username, std::string& password);
- ProcessResult Cram(std::string& username, std::string& password,
- std::string& challenge);
+ ProcessResult Login(std::string &username, std::string &password);
+ ProcessResult Plain(std::string &username, std::string &password);
+ ProcessResult Cram(std::string &username, std::string &password, std::string &challenge);
AuthenticateOperator(void);
~AuthenticateOperator(void);
@@ -63,13 +63,14 @@ namespace Binc {
//--------------------------------------------------------------------
class CapabilityOperator : public Operator {
std::vector<std::string> capabilities;
+
public:
ProcessResult process(Depot &, Request &);
virtual ParseResult parse(Request &) const;
const std::string getName(void) const;
int getState(void) const;
-
+
void addCapability(const std::string &cap);
CapabilityOperator(void);
@@ -162,6 +163,7 @@ namespace Binc {
ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const;
ParseResult expectOffset(BincImapParserFetchAtt &f_in) const;
ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const;
+
public:
ProcessResult process(Depot &, Request &);
virtual ParseResult parse(Request &) const;
@@ -194,6 +196,7 @@ namespace Binc {
ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const;
ParseResult expectOffset(BincImapParserFetchAtt &f_in) const;
ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const;
+
public:
ProcessResult process(Depot &, Request &);
virtual ParseResult parse(Request &) const;
@@ -208,15 +211,11 @@ namespace Binc {
//--------------------------------------------------------------------
class ListOperator : public Operator {
protected:
- enum MailboxFlags {
- DIR_SELECT = 0x01,
- DIR_MARKED = 0x02,
- DIR_NOINFERIORS = 0x04,
- DIR_LEAF = 0x08
- };
+ enum MailboxFlags { DIR_SELECT = 0x01, DIR_MARKED = 0x02, DIR_NOINFERIORS = 0x04, DIR_LEAF = 0x08 };
std::map<std::string, unsigned int> cache;
time_t cacheTimeout;
+
public:
ProcessResult process(Depot &, Request &);
virtual ParseResult parse(Request &) const;
@@ -322,7 +321,6 @@ namespace Binc {
//------------------------------------------------------------------
class SearchNode {
-
std::string date;
std::string astring;
std::string bstring;
@@ -336,12 +334,43 @@ namespace Binc {
public:
enum {
- S_ALL, S_ANSWERED, S_BCC, S_BEFORE, S_BODY, S_CC, S_DELETED,
- S_FLAGGED, S_FROM, S_KEYWORD, S_NEW, S_OLD, S_ON, S_RECENT,
- S_SEEN, S_SINCE, S_SUBJECT, S_TEXT, S_TO, S_UNANSWERED,
- S_UNDELETED, S_UNFLAGGED, S_UNKEYWORD, S_UNSEEN, S_DRAFT,
- S_HEADER, S_LARGER, S_NOT, S_OR, S_SENTBEFORE, S_SENTON,
- S_SENTSINCE, S_SMALLER, S_UID, S_UNDRAFT, S_SET, S_AND
+ S_ALL,
+ S_ANSWERED,
+ S_BCC,
+ S_BEFORE,
+ S_BODY,
+ S_CC,
+ S_DELETED,
+ S_FLAGGED,
+ S_FROM,
+ S_KEYWORD,
+ S_NEW,
+ S_OLD,
+ S_ON,
+ S_RECENT,
+ S_SEEN,
+ S_SINCE,
+ S_SUBJECT,
+ S_TEXT,
+ S_TO,
+ S_UNANSWERED,
+ S_UNDELETED,
+ S_UNFLAGGED,
+ S_UNKEYWORD,
+ S_UNSEEN,
+ S_DRAFT,
+ S_HEADER,
+ S_LARGER,
+ S_NOT,
+ S_OR,
+ S_SENTBEFORE,
+ S_SENTON,
+ S_SENTSINCE,
+ S_SMALLER,
+ S_UID,
+ S_UNDRAFT,
+ S_SET,
+ S_AND
};
static bool convertDate(const std::string &date, time_t &t, const std::string &delim = "-");
@@ -349,8 +378,10 @@ namespace Binc {
void order(void);
- bool match(Mailbox *, Message *,
- unsigned seqnr, unsigned int lastmessage,
+ bool match(Mailbox *,
+ Message *,
+ unsigned seqnr,
+ unsigned int lastmessage,
unsigned int lastuid) const;
int getType(void) const;
@@ -360,10 +391,9 @@ namespace Binc {
void init(const BincImapParserSearchKey &a);
//-
- static bool compareNodes(const SearchNode &a,
- const SearchNode &b)
+ static bool compareNodes(const SearchNode &a, const SearchNode &b)
{
- return a.getWeight() < b.getWeight();
+ return a.getWeight() < b.getWeight();
}
SearchNode(void);
@@ -371,7 +401,6 @@ namespace Binc {
};
public:
-
ProcessResult process(Depot &, Request &);
virtual ParseResult parse(Request &) const;
@@ -411,7 +440,7 @@ namespace Binc {
const std::string getName(void) const;
int getState(void) const;
- int goStartTLS(void) const;
+ int goStartTLS(void) const;
StarttlsOperator(void);
~StarttlsOperator(void);
@@ -419,7 +448,6 @@ namespace Binc {
//--------------------------------------------------------------------
class StatusOperator : public Operator {
-
std::map<int, Status> statuses;
public:
diff --git a/src/include/pendingupdates.h b/src/include/pendingupdates.h
index ea192de..c1adda0 100644
--- a/src/include/pendingupdates.h
+++ b/src/include/pendingupdates.h
@@ -16,12 +16,7 @@ namespace Binc {
//------------------------------------------------------------------------
class PendingUpdates {
public:
- enum {
- EXPUNGE = 0x01,
- FLAGS = 0x02,
- EXISTS = 0x04,
- RECENT = 0x08
- };
+ enum { EXPUNGE = 0x01, FLAGS = 0x02, EXISTS = 0x04, RECENT = 0x08 };
//----------------------------------------------------------------------
class expunged_const_iterator {
@@ -29,10 +24,10 @@ namespace Binc {
std::vector<unsigned int>::iterator internal;
public:
- unsigned int operator * (void) const;
- void operator ++ (void);
- bool operator != (expunged_const_iterator) const;
- bool operator == (expunged_const_iterator) const;
+ unsigned int operator*(void) const;
+ void operator++(void);
+ bool operator!=(expunged_const_iterator) const;
+ bool operator==(expunged_const_iterator) const;
//--
expunged_const_iterator(void);
@@ -48,7 +43,7 @@ namespace Binc {
private:
std::map<unsigned int, unsigned int>::iterator internal;
std::map<unsigned int, unsigned int> *sqnrtouid;
- std::map<unsigned int, std::vector<std::string> > *sqnrtocflags;
+ std::map<unsigned int, std::vector<std::string>> *sqnrtocflags;
public:
unsigned int first(void) const;
@@ -56,13 +51,13 @@ namespace Binc {
std::vector<std::string> getCustomFlags(void) const;
unsigned int getUID(void) const;
- void operator ++ (void);
- bool operator != (flagupdates_const_iterator) const;
+ void operator++(void);
+ bool operator!=(flagupdates_const_iterator) const;
//--
flagupdates_const_iterator(void);
flagupdates_const_iterator(std::map<unsigned int, unsigned int>::iterator i,
- std::map<unsigned int, std::vector<std::string> > *,
+ std::map<unsigned int, std::vector<std::string>> *,
std::map<unsigned int, unsigned int> *);
};
@@ -72,8 +67,9 @@ namespace Binc {
//--
void addExpunged(unsigned int uid);
- void addFlagUpdates(unsigned int sqnr, unsigned int uid,
- unsigned int flags,
+ void addFlagUpdates(unsigned int sqnr,
+ unsigned int uid,
+ unsigned int flags,
const std::vector<std::string> &cflags);
void setExists(unsigned int n);
void setRecent(unsigned int n);
@@ -90,7 +86,7 @@ namespace Binc {
std::vector<unsigned int> expunges;
std::map<unsigned int, unsigned int> flagupdates;
std::map<unsigned int, unsigned int> sqnrtouid;
- std::map<unsigned int, std::vector<std::string> > sqnrtocflags;
+ std::map<unsigned int, std::vector<std::string>> sqnrtocflags;
unsigned int exists;
unsigned int recent;
@@ -98,9 +94,11 @@ namespace Binc {
bool newrecent;
};
- bool pendingUpdates(Mailbox *, int type, bool rescan,
- bool showAll = false,
- bool forceScan = false,
+ bool pendingUpdates(Mailbox *,
+ int type,
+ bool rescan,
+ bool showAll = false,
+ bool forceScan = false,
bool uidfetchflags = false);
}
diff --git a/src/include/recursivedescent.h b/src/include/recursivedescent.h
index ea8fe33..96c3a7e 100644
--- a/src/include/recursivedescent.h
+++ b/src/include/recursivedescent.h
@@ -6,12 +6,12 @@
* ----------------------------------------------------------------- **/
#ifndef expectcommand_h_inluded
#define expectcommand_h_inluded
-#include <stack>
-#include <string>
-
#include "imapparser.h"
#include "operators.h"
+#include <stack>
+#include <string>
+
namespace Binc {
extern std::stack<int> inputBuffer;
@@ -39,7 +39,7 @@ namespace Binc {
Operator::ParseResult expectAtom(std::string &s_in);
Operator::ParseResult expectAtomChar(int &i_in);
Operator::ParseResult expectString(std::string &s_in);
-
+
Operator::ParseResult expectDate(std::string &s_in);
Operator::ParseResult expectNumber(unsigned int &i_in);
diff --git a/src/include/session.h b/src/include/session.h
index 94825cd..ee96613 100644
--- a/src/include/session.h
+++ b/src/include/session.h
@@ -6,17 +6,18 @@
* ----------------------------------------------------------------- **/
#ifndef session_h_included
#define session_h_included
+#include "argparser.h"
+
+#include <map>
#include <string>
#include <vector>
-#include <map>
-#include <sys/types.h>
-#include "argparser.h"
+#include <sys/types.h>
namespace Binc {
class Depot;
-
+
//--------------------------------------------------------------------
class Session {
public:
@@ -32,12 +33,7 @@ namespace Binc {
bool mailboxchanges;
- enum State {
- NONAUTHENTICATED = 0x01,
- AUTHENTICATED = 0x02,
- SELECTED = 0x04,
- LOGOUT = 0x00
- };
+ enum State { NONAUTHENTICATED = 0x01, AUTHENTICATED = 0x02, SELECTED = 0x04, LOGOUT = 0x00 };
CommandLineArgs args;
@@ -49,7 +45,7 @@ namespace Binc {
const int getState(void) const;
void setState(int n);
- bool parseCommandLine(int argc, char * argv[]);
+ bool parseCommandLine(int argc, char *argv[]);
void assignCommandLineArgs(void);
int getWriteBytes(void) const;
int getReadBytes(void) const;
diff --git a/src/include/status.h b/src/include/status.h
index f7f9e1f..9248505 100644
--- a/src/include/status.h
+++ b/src/include/status.h
@@ -11,7 +11,6 @@ namespace Binc {
//------------------------------------------------------------------------
class Status {
-
//--
int recent;
int messages;
@@ -23,23 +22,67 @@ namespace Binc {
int statusid;
public:
-
//--
- inline void setMessages(int i) { messages = i; }
- inline void setRecent(int i) { recent = i; }
- inline void setStatusID(int i) { statusid = i; }
- inline void setUnseen(int i) { unseen = i; }
- inline void setUidValidity(int i) { uidvalidity = i; }
- inline void setUidNext(int i) { uidnext = i; }
-
+ inline void setMessages(int i)
+ {
+ messages = i;
+ }
+
+ inline void setRecent(int i)
+ {
+ recent = i;
+ }
+
+ inline void setStatusID(int i)
+ {
+ statusid = i;
+ }
+
+ inline void setUnseen(int i)
+ {
+ unseen = i;
+ }
+
+ inline void setUidValidity(int i)
+ {
+ uidvalidity = i;
+ }
+
+ inline void setUidNext(int i)
+ {
+ uidnext = i;
+ }
+
//--
- inline int getMessages(void) const { return messages; }
- inline int getRecent(void) const { return recent; }
- inline int getStatusID(void) const { return statusid; }
- inline int getUnseen(void) const { return unseen; }
- inline int getUidValidity(void) const { return uidvalidity; }
- inline int getUidNext(void) const { return uidnext; }
+ inline int getMessages(void) const
+ {
+ return messages;
+ }
+
+ inline int getRecent(void) const
+ {
+ return recent;
+ }
+
+ inline int getStatusID(void) const
+ {
+ return statusid;
+ }
+
+ inline int getUnseen(void) const
+ {
+ return unseen;
+ }
+
+ inline int getUidValidity(void) const
+ {
+ return uidvalidity;
+ }
+ inline int getUidNext(void) const
+ {
+ return uidnext;
+ }
//--
Status(void);
diff --git a/src/include/stdiodevice.h b/src/include/stdiodevice.h
index 026386c..7b4f465 100644
--- a/src/include/stdiodevice.h
+++ b/src/include/stdiodevice.h
@@ -2,7 +2,7 @@
* @file stdiodevice.h
* @brief Declaration of the StdIODevice class.
* @author Andreas Aardal Hanssen
- * @date 2002, 2003
+ * @date 2002, 2003
* ----------------------------------------------------------------- **/
#ifndef stdiodevice_h_included
#define stdiodevice_h_included
@@ -24,7 +24,7 @@ namespace Binc {
bool waitForRead(void) const;
WriteResult write(void);
- bool fillInputBuffer(void);
+ bool fillInputBuffer(void);
};
}
diff --git a/src/include/syslogdevice.h b/src/include/syslogdevice.h
index 2269fb2..68d4112 100644
--- a/src/include/syslogdevice.h
+++ b/src/include/syslogdevice.h
@@ -8,13 +8,15 @@
#define syslogdevice_h_included
#include "iodevice.h"
+
#include <syslog.h>
namespace Binc {
class SyslogDevice : public IODevice {
public:
- SyslogDevice(int flags, const char *ident = "bincimap",
- int option = LOG_NDELAY | LOG_PID,
+ SyslogDevice(int flags,
+ const char *ident = "bincimap",
+ int option = LOG_NDELAY | LOG_PID,
int facility = LOG_USER);
~SyslogDevice();
@@ -27,7 +29,7 @@ namespace Binc {
bool waitForRead(void) const;
WriteResult write(void);
- bool fillInputBuffer(void);
+ bool fillInputBuffer(void);
private:
static std::string ident;
diff --git a/src/iodevice.cc b/src/iodevice.cc
index 7197354..c2bc9ee 100644
--- a/src/iodevice.cc
+++ b/src/iodevice.cc
@@ -5,38 +5,39 @@
* @date 2002, 2003
* ----------------------------------------------------------------- **/
#include "iodevice.h"
-#include "convert.h" // BincStream
-#include "session.h" // getEnv/hasEnv
+
+#include "convert.h" // BincStream
+#include "session.h" // getEnv/hasEnv
#include <stdlib.h>
+
#include <unistd.h>
using namespace ::std;
using namespace ::Binc;
//------------------------------------------------------------------------
-IODevice::IODevice(int f) : flags(f | IsEnabled),
- maxInputBufferSize(0),
- maxOutputBufferSize(0),
- timeout(0),
- readCount(0), writeCount(0),
- outputLevel(ErrorLevel),
- outputLevelLimit(ErrorLevel),
- error(Unknown), errorString("Unknown device error"),
- dumpfd(0)
-{
-}
+IODevice::IODevice(int f)
+ : flags(f | IsEnabled)
+ , maxInputBufferSize(0)
+ , maxOutputBufferSize(0)
+ , timeout(0)
+ , readCount(0)
+ , writeCount(0)
+ , outputLevel(ErrorLevel)
+ , outputLevelLimit(ErrorLevel)
+ , error(Unknown)
+ , errorString("Unknown device error")
+ , dumpfd(0)
+{}
//------------------------------------------------------------------------
-IODevice::~IODevice(void)
-{
-}
+IODevice::~IODevice(void) {}
//------------------------------------------------------------------------
-IODevice &IODevice::operator <<(ostream &(*source)(ostream &))
+IODevice &IODevice::operator<<(ostream &(*source)(ostream &))
{
- if (!(flags & IsEnabled) || outputLevel > outputLevelLimit)
- return *this;
+ if (!(flags & IsEnabled) || outputLevel > outputLevelLimit) return *this;
static std::ostream &(*endl_funcptr)(ostream &) = endl;
@@ -49,8 +50,7 @@ IODevice &IODevice::operator <<(ostream &(*source)(ostream &))
if (flags & FlushesOnEndl)
flush();
else if (flags & HasOutputLimit)
- if (outputBuffer.getSize() > maxOutputBufferSize)
- flush();
+ if (outputBuffer.getSize() > maxOutputBufferSize) flush();
return *this;
}
@@ -163,7 +163,7 @@ bool IODevice::readStr(string *dest, unsigned int max)
// If max is != 0, wait until we have max.
while (max && inputBuffer.getSize() < max) {
- if (!fillInputBuffer()) return false;
+ if (!fillInputBuffer()) return false;
}
unsigned int bytesToRead = max ? max : inputBuffer.getSize();
@@ -171,7 +171,7 @@ bool IODevice::readStr(string *dest, unsigned int max)
if (dumpfd) {
::write(dumpfd, inputBuffer.str().substr(0, bytesToRead).c_str(), bytesToRead);
}
-
+
inputBuffer.popString(bytesToRead);
readCount += bytesToRead;
@@ -274,8 +274,7 @@ unsigned int IODevice::getWriteCount(void) const
void IODevice::enableProtocolDumping(void)
{
BincStream ss;
- ss << "/tmp/bincimap-dump-" << (int) time(0) << "-"
- << Session::getInstance().getIP() << "-XXXXXX";
+ ss << "/tmp/bincimap-dump-" << (int)time(0) << "-" << Session::getInstance().getIP() << "-XXXXXX";
char *safename = strdup(ss.str().c_str());
dumpfd = mkstemp(safename);
if (dumpfd == -1) dumpfd = 0;
diff --git a/src/iofactory.cc b/src/iofactory.cc
index ced087c..abe71b4 100644
--- a/src/iofactory.cc
+++ b/src/iofactory.cc
@@ -5,20 +5,17 @@
* @date 2002, 2003
* ----------------------------------------------------------------- **/
#include "iofactory.h"
+
#include "iodevice.h"
using namespace ::Binc;
using namespace ::std;
//------------------------------------------------------------------------
-IOFactory::IOFactory(void)
-{
-}
+IOFactory::IOFactory(void) {}
//------------------------------------------------------------------------
-IOFactory::~IOFactory(void)
-{
-}
+IOFactory::~IOFactory(void) {}
//------------------------------------------------------------------------
IOFactory &IOFactory::getInstance(void)
@@ -34,8 +31,7 @@ void IOFactory::addDevice(IODevice *dev)
// FIXME: Delete correct object. Now, only IODevice's destructor is
// called, and only IODevice's memory is freed.
- if (ioDevice)
- delete ioDevice;
+ if (ioDevice) delete ioDevice;
IOFactory::getInstance().devices[dev->service()] = dev;
}
@@ -47,8 +43,7 @@ IODevice &IOFactory::getClient(void)
IOFactory &ioFactory = IOFactory::getInstance();
- if (ioFactory.devices.find("client") != ioFactory.devices.end())
- return *ioFactory.devices["client"];
+ if (ioFactory.devices.find("client") != ioFactory.devices.end()) return *ioFactory.devices["client"];
return nulDevice;
}
@@ -60,7 +55,6 @@ IODevice &IOFactory::getLogger(void)
IOFactory &ioFactory = IOFactory::getInstance();
- if (ioFactory.devices.find("log") != ioFactory.devices.end())
- return *ioFactory.devices["log"];
+ if (ioFactory.devices.find("log") != ioFactory.devices.end()) return *ioFactory.devices["log"];
return nulDevice;
}
diff --git a/src/mailbox.cc b/src/mailbox.cc
index 53c8606..fd83276 100644
--- a/src/mailbox.cc
+++ b/src/mailbox.cc
@@ -2,13 +2,14 @@
* @file mailbox.cc
* @brief Implementation of the Mailbox class.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
#include "mailbox.h"
+
#include "message.h"
+#include <string>
+
using namespace ::std;
using namespace Binc;
@@ -19,19 +20,13 @@ Mailbox::BaseIterator::BaseIterator(int sqn)
}
//------------------------------------------------------------------------
-Mailbox::BaseIterator::~BaseIterator(void)
-{
-}
+Mailbox::BaseIterator::~BaseIterator(void) {}
//------------------------------------------------------------------------
-Mailbox::Mailbox(void) : readOnly(false)
-{
-}
+Mailbox::Mailbox(void) : readOnly(false) {}
//------------------------------------------------------------------------
-Mailbox::~Mailbox(void)
-{
-}
+Mailbox::~Mailbox(void) {}
//------------------------------------------------------------------------
bool Mailbox::isReadOnly(void) const
@@ -46,31 +41,28 @@ void Mailbox::setReadOnly(bool readOnly)
}
//------------------------------------------------------------------------
-Mailbox::iterator::iterator(BaseIterator &i)
- : realIterator(i)
-{
-}
+Mailbox::iterator::iterator(BaseIterator &i) : realIterator(i) {}
//------------------------------------------------------------------------
-Message &Mailbox::iterator::operator *(void)
+Message &Mailbox::iterator::operator*(void)
{
return *realIterator;
}
//------------------------------------------------------------------------
-void Mailbox::iterator::operator ++(void)
+void Mailbox::iterator::operator++(void)
{
++realIterator;
}
//------------------------------------------------------------------------
-bool Mailbox::iterator::operator ==(const iterator &i) const
+bool Mailbox::iterator::operator==(const iterator &i) const
{
return realIterator == i.realIterator;
}
//------------------------------------------------------------------------
-bool Mailbox::iterator::operator !=(const iterator &i) const
+bool Mailbox::iterator::operator!=(const iterator &i) const
{
return realIterator != i.realIterator;
}
diff --git a/src/maildir-close.cc b/src/maildir-close.cc
index a886d97..c0e0dbd 100644
--- a/src/maildir-close.cc
+++ b/src/maildir-close.cc
@@ -15,11 +15,9 @@ using namespace Binc;
//------------------------------------------------------------------------
void Binc::Maildir::closeMailbox(void)
{
- if (!selected)
- return;
+ if (!selected) return;
- if (mailboxchanged && !readOnly)
- writeCache();
+ if (mailboxchanged && !readOnly) writeCache();
mailboxchanged = false;
@@ -37,9 +35,9 @@ void Binc::Maildir::closeMailbox(void)
selected = false;
path = "";
- old_bincimap_cache_st_mtime = 0;
+ old_bincimap_cache_st_mtime = 0;
old_bincimap_cache_st_ctime = 0;
- old_cur_st_mtime = 0;
+ old_cur_st_mtime = 0;
old_cur_st_ctime = 0;
old_new_st_mtime = 0;
old_new_st_ctime = 0;
diff --git a/src/maildir-create.cc b/src/maildir-create.cc
index 6bbd7d7..6e08b61 100644
--- a/src/maildir-create.cc
+++ b/src/maildir-create.cc
@@ -6,22 +6,21 @@
* ----------------------------------------------------------------- **/
#include "maildir.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
#include <errno.h>
+
+#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
using namespace ::std;
using namespace Binc;
//------------------------------------------------------------------------
-bool Binc::Maildir::createMailbox(const string &s_in, mode_t mode,
- uid_t owner, gid_t group, bool root)
+bool Binc::Maildir::createMailbox(const string &s_in, mode_t mode, uid_t owner, gid_t group, bool root)
{
if (s_in != "." && mkdir(s_in.c_str(), mode) == -1) {
- setLastError("unable to create " + s_in + ": "
- + string(strerror(errno)));
+ setLastError("unable to create " + s_in + ": " + string(strerror(errno)));
return false;
}
@@ -30,47 +29,39 @@ bool Binc::Maildir::createMailbox(const string &s_in, mode_t mode,
sleep(1);
if (mkdir((s_in + "/cur").c_str(), mode) == -1) {
- setLastError("unable to create " + s_in + "/cur: "
- + string(strerror(errno)));
+ setLastError("unable to create " + s_in + "/cur: " + string(strerror(errno)));
return false;
}
if (mkdir((s_in + "/new").c_str(), mode) == -1) {
- setLastError("unable to create " + s_in + "/new: "
- + string(strerror(errno)));
+ setLastError("unable to create " + s_in + "/new: " + string(strerror(errno)));
return false;
}
if (mkdir((s_in + "/tmp").c_str(), mode) == -1) {
- setLastError("unable to create " + s_in + "/tmp: "
- + string(strerror(errno)));
+ setLastError("unable to create " + s_in + "/tmp: " + string(strerror(errno)));
return false;
}
- if (owner == 0 && group == 0)
- return true;
+ if (owner == 0 && group == 0) return true;
if (chown(s_in.c_str(), owner, group) == -1) {
- setLastError("unable to chown " + s_in + ": "
- + string(strerror(errno)));
+ setLastError("unable to chown " + s_in + ": " + string(strerror(errno)));
return false;
}
if (chown((s_in + "/cur").c_str(), owner, group) == -1) {
- setLastError("unable to chown " + s_in + "/cur: "
- + string(strerror(errno)));
+ setLastError("unable to chown " + s_in + "/cur: " + string(strerror(errno)));
return false;
}
if (chown((s_in + "/new").c_str(), owner, group) == -1) {
- setLastError("unable to chown " + s_in + "/new: "
- + string(strerror(errno)));
+ setLastError("unable to chown " + s_in + "/new: " + string(strerror(errno)));
return false;
}
if (chown((s_in + "/tmp").c_str(), owner, group) == -1) {
- setLastError("unable to chown " + s_in + "/tmp: "
- + string(strerror(errno)));
+ setLastError("unable to chown " + s_in + "/tmp: " + string(strerror(errno)));
return false;
}
diff --git a/src/maildir-delete.cc b/src/maildir-delete.cc
index 9ed162b..b0abb2a 100644
--- a/src/maildir-delete.cc
+++ b/src/maildir-delete.cc
@@ -6,14 +6,12 @@
* ----------------------------------------------------------------- **/
#include "maildir.h"
-#include <fcntl.h>
-#include <unistd.h>
#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
#include <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
using namespace ::std;
@@ -24,21 +22,18 @@ namespace {
bool recursiveDelete(const string &path)
{
DIR *mydir = opendir(path.c_str());
- if (mydir == 0)
- return false;
+ if (mydir == 0) return false;
struct dirent *mydirent;
while ((mydirent = readdir(mydir)) != 0) {
string d = mydirent->d_name;
- if (d == "." || d == "..")
- continue;
+ if (d == "." || d == "..") continue;
string f = path + "/" + d;
struct stat mystat;
if (lstat(f.c_str(), &mystat) != 0) {
- if (errno == ENOENT)
- continue;
+ if (errno == ENOENT) continue;
return false;
}
@@ -78,9 +73,7 @@ bool Binc::Maildir::deleteMailbox(const string &s_in)
}
if (rmdir(s_in.c_str()) != 0) {
- setLastError("error deleting Maildir: "
- + string(strerror(errno))
- + " - status is undefined");
+ setLastError("error deleting Maildir: " + string(strerror(errno)) + " - status is undefined");
return false;
}
diff --git a/src/maildir-expunge.cc b/src/maildir-expunge.cc
index 3091d7f..75c8f3d 100644
--- a/src/maildir-expunge.cc
+++ b/src/maildir-expunge.cc
@@ -2,16 +2,17 @@
* @file maildir-expunge.cc
* @brief Implementation of the Maildir class.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <unistd.h>
-#include <errno.h>
-
#include "iodevice.h"
#include "iofactory.h"
#include "maildir.h"
#include "maildirmessage.h"
+#include <errno.h>
+
+#include <unistd.h>
+
using namespace ::std;
using namespace Binc;
@@ -20,14 +21,13 @@ void Maildir::expungeMailbox(void)
{
if (readOnly) return;
- Mailbox::iterator i = begin(SequenceSet::all(), SQNR_MODE|INCLUDE_EXPUNGED);
+ Mailbox::iterator i = begin(SequenceSet::all(), SQNR_MODE | INCLUDE_EXPUNGED);
bool success = true;
for (; success && i != end(); ++i) {
MaildirMessage &message = reinterpret_cast<MaildirMessage &>(*i);
- if ((message.getStdFlags() & Message::F_DELETED) == 0)
- continue;
+ if ((message.getStdFlags() & Message::F_DELETED) == 0) continue;
message.setExpunged();
@@ -35,15 +35,13 @@ void Maildir::expungeMailbox(void)
// The message might be gone already
MaildirIndexItem *item = index.find(id);
- if (!item)
- continue;
+ if (!item) continue;
string fpath = path + "/cur/" + item->fileName;
while (unlink(fpath.c_str()) != 0) {
if (errno != ENOENT) {
- bincWarning << "unable to remove " << fpath << ": "
- << strerror(errno) << endl;
+ bincWarning << "unable to remove " << fpath << ": " << strerror(errno) << endl;
break;
}
diff --git a/src/maildir-readcache.cc b/src/maildir-readcache.cc
index a108242..dbbf4ef 100644
--- a/src/maildir-readcache.cc
+++ b/src/maildir-readcache.cc
@@ -4,10 +4,11 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <algorithm>
-#include "maildir.h"
#include "convert.h"
#include "globals.h"
+#include "maildir.h"
+
+#include <algorithm>
using namespace ::std;
using namespace Binc;
@@ -47,7 +48,8 @@ Maildir::ReadCacheResult Maildir::readCache(void)
unsigned int readUidNext;
if (sscanf(inputBuffer, "%s %u %u", cacheFileVersionBuffer, &readUidValidity, &readUidNext) != 3
- || strcmp(cacheFileVersionBuffer, BINC_CACHE) != 0) {
+ || strcmp(cacheFileVersionBuffer, BINC_CACHE) != 0)
+ {
// bump cache
fclose(fp);
uidvalidity = time(0);
@@ -68,8 +70,7 @@ Maildir::ReadCacheResult Maildir::readCache(void)
while (fgets(inputBuffer, sizeof(inputBuffer), fp)) {
inputBuffer[sizeof(inputBuffer) - 1] = '\0';
- if (sscanf(inputBuffer, "%u %u %u %s", &readUID,
- &readInternalDate, &readSize, readUnique) != 4) {
+ if (sscanf(inputBuffer, "%u %u %u %s", &readUID, &readInternalDate, &readSize, readUnique) != 4) {
// error in input
fclose(fp);
uidvalidity = time(0);
@@ -88,7 +89,7 @@ Maildir::ReadCacheResult Maildir::readCache(void)
// skip consecutive white space
while (flagStart && *flagStart == ' ')
- ++flagStart;
+ ++flagStart;
}
// get flags
@@ -104,7 +105,7 @@ Maildir::ReadCacheResult Maildir::readCache(void)
// skip consecutive white space
while (flagStart && *flagStart != '\0' && *flagStart == ' ')
- ++flagStart;
+ ++flagStart;
}
MaildirMessage m(*this);
@@ -112,11 +113,10 @@ Maildir::ReadCacheResult Maildir::readCache(void)
m.setInternalDate(readInternalDate);
if (index.find(readUnique) == 0) {
- for (vector<string>::const_iterator it = customFlags.begin();
- it != customFlags.end(); ++it) {
- string tmpFlag = *it;
- trim(tmpFlag, " \n");
- m.setCustomFlag(tmpFlag);
+ for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) {
+ string tmpFlag = *it;
+ trim(tmpFlag, " \n");
+ m.setCustomFlag(tmpFlag);
}
m.setUID(readUID);
@@ -134,8 +134,7 @@ Maildir::ReadCacheResult Maildir::readCache(void)
sort(customFlags.begin(), customFlags.end());
if (oldCustomFlags != customFlags) {
existingMessage.resetCustomFlags();
- for (vector<string>::const_iterator it = customFlags.begin();
- it != customFlags.end(); ++it) {
+ for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) {
string tmpFlag = *it;
trim(tmpFlag, " \n");
existingMessage.setCustomFlag(tmpFlag);
@@ -148,4 +147,3 @@ Maildir::ReadCacheResult Maildir::readCache(void)
return Ok;
}
-
diff --git a/src/maildir-scan.cc b/src/maildir-scan.cc
index 4628d5b..2f3a9b4 100644
--- a/src/maildir-scan.cc
+++ b/src/maildir-scan.cc
@@ -4,16 +4,17 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <fcntl.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
#include "iodevice.h"
#include "iofactory.h"
#include "maildir.h"
+#include <errno.h>
+
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
using namespace Binc;
using namespace ::std;
@@ -22,11 +23,9 @@ Lock::Lock(const string &path)
lock = (path == "" ? "." : path) + "/bincimap-scan-lock";
int lockfd = -1;
- while ((lockfd = ::open(lock.c_str(),
- O_CREAT | O_WRONLY | O_EXCL, 0666)) == -1) {
+ while ((lockfd = ::open(lock.c_str(), O_CREAT | O_WRONLY | O_EXCL, 0666)) == -1) {
if (errno != EEXIST) {
- bincWarning << "unable to lock mailbox: " << lock
- << ", " << string(strerror(errno)) << endl;
+ bincWarning << "unable to lock mailbox: " << lock << ", " << string(strerror(errno)) << endl;
return;
}
@@ -34,14 +33,15 @@ Lock::Lock(const string &path)
bincWarning << "waiting for mailbox lock " << lock << "." << endl;
if (lstat(lock.c_str(), &mystat) == 0) {
if ((time(0) - mystat.st_ctime) > 300) {
- if (unlink(lock.c_str()) == 0) continue;
- else bincWarning << "failed to force mailbox lock: " << lock
- << ", " << string(strerror(errno)) << endl;
+ if (unlink(lock.c_str()) == 0)
+ continue;
+ else
+ bincWarning << "failed to force mailbox lock: " << lock << ", " << string(strerror(errno))
+ << endl;
}
} else {
if (errno != ENOENT) {
- string err = "invalid lock " + lock + ": "
- + strerror(errno);
+ string err = "invalid lock " + lock + ": " + strerror(errno);
bincWarning << err << endl;
return;
}
@@ -58,8 +58,7 @@ Lock::~Lock()
{
// remove the lock
if (unlink(lock.c_str()) != 0)
- bincWarning << "failed to unlock mailbox: " << lock << ", "
- << strerror(errno) << endl;
+ bincWarning << "failed to unlock mailbox: " << lock << ", " << strerror(errno) << endl;
}
//------------------------------------------------------------------------
@@ -77,8 +76,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
if (firstscan || forceScan) {
struct stat oldstat;
if (stat(newpath.c_str(), &oldstat) != 0) {
- setLastError("Invalid Mailbox, " + newpath + ": "
- + string(strerror(errno)));
+ setLastError("Invalid Mailbox, " + newpath + ": " + string(strerror(errno)));
return PermanentError;
}
@@ -86,8 +84,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
old_new_st_ctime = oldstat.st_ctime;
if (stat(curpath.c_str(), &oldstat) != 0) {
- setLastError("Invalid Mailbox, " + curpath + ": "
- + string(strerror(errno)));
+ setLastError("Invalid Mailbox, " + curpath + ": " + string(strerror(errno)));
return PermanentError;
}
@@ -106,14 +103,12 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
struct stat oldnewstat;
struct stat oldbincimapcachestat;
if (stat(newpath.c_str(), &oldnewstat) != 0) {
- setLastError("Invalid Mailbox, " + newpath + ": "
- + string(strerror(errno)));
+ setLastError("Invalid Mailbox, " + newpath + ": " + string(strerror(errno)));
return PermanentError;
}
if (stat(curpath.c_str(), &oldcurstat) != 0) {
- setLastError("Invalid Mailbox, " + curpath + ": "
- + string(strerror(errno)));
+ setLastError("Invalid Mailbox, " + curpath + ": " + string(strerror(errno)));
return PermanentError;
}
@@ -122,12 +117,11 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
oldbincimapcachestat.st_mtime = 0;
}
- if (oldnewstat.st_mtime == old_new_st_mtime
- && oldnewstat.st_ctime == old_new_st_ctime
- && oldcurstat.st_mtime == old_cur_st_mtime
- && oldcurstat.st_ctime == old_cur_st_ctime
+ if (oldnewstat.st_mtime == old_new_st_mtime && oldnewstat.st_ctime == old_new_st_ctime
+ && oldcurstat.st_mtime == old_cur_st_mtime && oldcurstat.st_ctime == old_cur_st_ctime
&& oldbincimapcachestat.st_mtime == old_bincimap_cache_st_mtime
- && oldbincimapcachestat.st_ctime == old_bincimap_cache_st_ctime) {
+ && oldbincimapcachestat.st_ctime == old_bincimap_cache_st_ctime)
+ {
return Success;
}
@@ -148,21 +142,21 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
// changes to the depot across Binc IMAP instances that can not be
// communicated via the depot itself.
switch (readCache()) {
- case NoCache:
- case Error:
+ case NoCache:
+ case Error:
// An error with reading the cache files when it's not the first
// time we scan the depot is treated as an error.
- if (!firstscan && !readOnly) {
- old_cur_st_mtime = (time_t) 0;
- old_cur_st_ctime = (time_t) 0;
- old_new_st_mtime = (time_t) 0;
- old_new_st_ctime = (time_t) 0;
- return TemporaryError;
- }
- mailboxchanged = true;
- break;
- default:
- break;
+ if (!firstscan && !readOnly) {
+ old_cur_st_mtime = (time_t)0;
+ old_cur_st_ctime = (time_t)0;
+ old_new_st_mtime = (time_t)0;
+ old_new_st_ctime = (time_t)0;
+ return TemporaryError;
+ }
+ mailboxchanged = true;
+ break;
+ default:
+ break;
}
// open new/ directory
@@ -185,9 +179,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
// start with a dot. Do not try to extract information from unique
// names." - The Maildir spec from cr.yp.to
string filename = pdirent->d_name;
- if (filename[0] == '.'
- || filename.find(':') != string::npos
- || filename.find('/') != string::npos)
+ if (filename[0] == '.' || filename.find(':') != string::npos || filename.find('/') != string::npos)
continue;
string fullfilename = newpath + filename;
@@ -201,24 +193,23 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
if (stat(fullfilename.c_str(), &mystat) != 0) {
if (errno == ENOENT) {
// prevent looping due to stale symlinks
- if (lstat(fullfilename.c_str(), &mystat) == 0) {
- bincWarning << "dangling symlink: " << fullfilename << endl;
+ if (lstat(fullfilename.c_str(), &mystat) == 0) {
+ bincWarning << "dangling symlink: " << fullfilename << endl;
continue;
}
- // a rare race between readdir and stat force us to restart the scan.
+ // a rare race between readdir and stat force us to restart the scan.
closedir(pdir);
if ((pdir = opendir(newpath.c_str())) == 0) {
string reason = "Warning: opendir(\"" + newpath + "\") == 0 (";
- reason += strerror(errno);
- reason += ")";
+ reason += strerror(errno);
+ reason += ")";
setLastError(reason);
return PermanentError;
}
} else
- bincWarning << "junk in Maildir: \"" << fullfilename << "\": "
- << strerror(errno);
+ bincWarning << "junk in Maildir: \"" << fullfilename << "\": " << strerror(errno);
continue;
}
@@ -233,27 +224,26 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
bool ours = false;
for (; newIt != newMessages.end(); ++newIt) {
if ((filename == (*newIt).getUnique())
- && ((*newIt).getInternalFlags() & MaildirMessage::Committed)) {
+ && ((*newIt).getInternalFlags() & MaildirMessage::Committed))
+ {
ours = true;
break;
}
}
if (!ours && ::time(0) <= mystat.st_mtime) {
- old_cur_st_mtime = (time_t) 0;
- old_cur_st_ctime = (time_t) 0;
- old_new_st_mtime = (time_t) 0;
- old_new_st_ctime = (time_t) 0;
+ old_cur_st_mtime = (time_t)0;
+ old_cur_st_ctime = (time_t)0;
+ old_new_st_mtime = (time_t)0;
+ old_new_st_ctime = (time_t)0;
continue;
}
// move files from new/ to cur/
string newName = curpath + pdirent->d_name;
- if (rename((newpath + pdirent->d_name).c_str(),
- (newName + ":2,").c_str()) != 0) {
- bincWarning << "error moving messages from new to cur: skipping "
- << newpath
- << pdirent->d_name << ": " << strerror(errno) << endl;
+ if (rename((newpath + pdirent->d_name).c_str(), (newName + ":2,").c_str()) != 0) {
+ bincWarning << "error moving messages from new to cur: skipping " << newpath << pdirent->d_name
+ << ": " << strerror(errno) << endl;
continue;
}
}
@@ -263,8 +253,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
// Now, assume all known messages were expunged and have them prove
// otherwise.
{
- Mailbox::iterator i = begin(SequenceSet::all(),
- INCLUDE_EXPUNGED | SQNR_MODE);
+ Mailbox::iterator i = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE);
for (; i != end(); ++i)
(*i).setExpunged();
}
@@ -274,8 +263,8 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
if ((pdir = opendir(curpath.c_str())) == 0) {
string reason = "Maildir::scan::opendir(\"" + curpath + "\") == 0 (";
- reason += strerror(errno);
- reason += ")";
+ reason += strerror(errno);
+ reason += ")";
setLastError(reason);
return PermanentError;
@@ -299,22 +288,33 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
if ((pos = filename.find(':')) != string::npos) {
uniquename = filename.substr(0, pos);
string tmp = filename.substr(pos);
- if ((pos = tmp.find("2,")) != string::npos)
- standard = tmp.substr(pos + 2);
+ if ((pos = tmp.find("2,")) != string::npos) standard = tmp.substr(pos + 2);
} else
uniquename = filename;
unsigned char mflags = Message::F_NONE;
- for (string::const_iterator i = standard.begin();
- i != standard.end(); ++i) {
+ for (string::const_iterator i = standard.begin(); i != standard.end(); ++i) {
switch (*i) {
- case 'R': mflags |= Message::F_ANSWERED; break;
- case 'S': mflags |= Message::F_SEEN; break;
- case 'T': mflags |= Message::F_DELETED; break;
- case 'D': mflags |= Message::F_DRAFT; break;
- case 'F': mflags |= Message::F_FLAGGED; break;
- case 'P': mflags |= Message::F_PASSED; break;
- default: break;
+ case 'R':
+ mflags |= Message::F_ANSWERED;
+ break;
+ case 'S':
+ mflags |= Message::F_SEEN;
+ break;
+ case 'T':
+ mflags |= Message::F_DELETED;
+ break;
+ case 'D':
+ mflags |= Message::F_DRAFT;
+ break;
+ case 'F':
+ mflags |= Message::F_FLAGGED;
+ break;
+ case 'P':
+ mflags |= Message::F_PASSED;
+ break;
+ default:
+ break;
}
}
@@ -325,31 +325,31 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
if (stat(fullfilename.c_str(), &mystat) != 0) {
if (errno == ENOENT) {
// prevent looping due to stale symlinks
- if (lstat(fullfilename.c_str(), &mystat) == 0) {
- bincWarning << "dangling symlink: " << fullfilename << endl;
+ if (lstat(fullfilename.c_str(), &mystat) == 0) {
+ bincWarning << "dangling symlink: " << fullfilename << endl;
continue;
}
- // a rare race between readdir and stat force us to restart
- // the scan.
+ // a rare race between readdir and stat force us to restart
+ // the scan.
index.clearFileNames();
closedir(pdir);
if ((pdir = opendir(newpath.c_str())) == 0) {
string reason = "Warning: opendir(\"" + newpath + "\") == 0 (";
- reason += strerror(errno);
- reason += ")";
+ reason += strerror(errno);
+ reason += ")";
setLastError(reason);
return PermanentError;
}
}
-
+
continue;
}
mailboxchanged = true;
}
-
+
index.insert(uniquename, 0, filename);
// If we have this message in memory already..
@@ -382,7 +382,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
m.setInternalDate(mystat.st_mtime);
m.setStdFlag((mflags | Message::F_RECENT) & ~Message::F_EXPUNGED);
m.setUnique(uniquename);
- tempMessageMap.insert(make_pair((unsigned int) mystat.st_mtime, m));
+ tempMessageMap.insert(make_pair((unsigned int)mystat.st_mtime, m));
mailboxchanged = true;
}
@@ -432,8 +432,7 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
if (firstscan) {
unsigned int lastuid = 0;
- Mailbox::iterator ii
- = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE);
+ Mailbox::iterator ii = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE);
for (; ii != end(); ++ii) {
MaildirMessage &message = (MaildirMessage &)*ii;
message.clearInternalFlag(MaildirMessage::JustArrived);
@@ -442,19 +441,19 @@ Maildir::ScanResult Maildir::scan(bool forceScan)
lastuid = message.getUID();
else {
bincWarning << "UID values are not strictly ascending in this"
- " mailbox: " << path << ". This is usually caused by "
- << "access from a broken accessor. Bumping UIDVALIDITY."
- << endl;
+ " mailbox: "
+ << path << ". This is usually caused by "
+ << "access from a broken accessor. Bumping UIDVALIDITY." << endl;
setLastError("An error occurred while scanning the mailbox. "
"Please contact your system administrator.");
if (!readOnly) {
bumpUidValidity(path);
- old_cur_st_mtime = (time_t) 0;
- old_cur_st_ctime = (time_t) 0;
- old_new_st_mtime = (time_t) 0;
- old_new_st_ctime = (time_t) 0;
+ old_cur_st_mtime = (time_t)0;
+ old_cur_st_ctime = (time_t)0;
+ old_new_st_mtime = (time_t)0;
+ old_new_st_ctime = (time_t)0;
return TemporaryError;
} else {
return PermanentError;
diff --git a/src/maildir-scanfilesnames.cc b/src/maildir-scanfilesnames.cc
index 643460b..0bde999 100644
--- a/src/maildir-scanfilesnames.cc
+++ b/src/maildir-scanfilesnames.cc
@@ -2,19 +2,19 @@
* @file maildir-scanfilesnames.cc
* @brief Implementation of the Maildir class.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
+#include "iodevice.h"
+#include "iofactory.h"
#include "maildir.h"
-#include <iostream>
#include <iomanip>
+#include <iostream>
-#include <dirent.h>
-#include <unistd.h>
#include <errno.h>
-#include "iodevice.h"
-#include "iofactory.h"
+#include <dirent.h>
+#include <unistd.h>
using namespace ::std;
@@ -24,8 +24,7 @@ bool Binc::Maildir::scanFileNames(void) const
string curpath = path + "/cur/";
DIR *pdir = opendir(curpath.c_str());
if (pdir == 0) {
- setLastError("when scanning mailbox \""
- + path + "\": " + string(strerror(errno)));
+ setLastError("when scanning mailbox \"" + path + "\": " + string(strerror(errno)));
bincWarning << getLastError() << endl;
return false;
}
diff --git a/src/maildir-select.cc b/src/maildir-select.cc
index 78daf9d..a779a4a 100644
--- a/src/maildir-select.cc
+++ b/src/maildir-select.cc
@@ -13,8 +13,7 @@ using namespace ::std;
using namespace Binc;
//------------------------------------------------------------------------
-bool Binc::Maildir::selectMailbox(const std::string &name,
- const std::string &s_in)
+bool Binc::Maildir::selectMailbox(const std::string &name, const std::string &s_in)
{
setName(name);
@@ -31,11 +30,10 @@ bool Binc::Maildir::selectMailbox(const std::string &name,
setPath(s_in);
switch (scan()) {
- case Success:
+ case Success:
break;
case TemporaryError:
- if (scan() == Success)
- break;
+ if (scan() == Success) break;
case PermanentError:
return false;
}
diff --git a/src/maildir-updateflags.cc b/src/maildir-updateflags.cc
index be37234..a3d2ab7 100644
--- a/src/maildir-updateflags.cc
+++ b/src/maildir-updateflags.cc
@@ -2,16 +2,16 @@
* @file maildir-updateflags.cc
* @brief Implementation of the Maildir class.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
+#include "iodevice.h"
+#include "iofactory.h"
#include "maildir.h"
-#include <dirent.h>
-#include <unistd.h>
#include <errno.h>
-#include "iodevice.h"
-#include "iofactory.h"
+#include <dirent.h>
+#include <unistd.h>
using namespace ::std;
@@ -25,18 +25,16 @@ void Binc::Maildir::updateFlags(void)
string curpath = path + "/cur/";
DIR *pdir = opendir(curpath.c_str());
if (pdir == 0) {
- bincError << "failed to open " << curpath << ": "
- << strerror(errno) << endl;
+ bincError << "failed to open " << curpath << ": " << strerror(errno) << endl;
return;
}
// read all entries in the directory
- vector<string> entries;
+ vector<string> entries;
struct dirent *pdirent;
while ((pdirent = readdir(pdir)) != 0) {
string filename = pdirent->d_name;
- if (filename[0] == '.')
- continue;
+ if (filename[0] == '.') continue;
entries.push_back(filename);
}
closedir(pdir);
@@ -55,17 +53,15 @@ void Binc::Maildir::updateFlags(void)
if ((pos = filename.find(":2,")) != string::npos)
uniquename = filename.substr(0, pos);
else
- uniquename = filename;
+ uniquename = filename;
// only update flags for messages that are known.
MaildirMessage *message = get(uniquename);
- if (!message)
- continue;
+ if (!message) continue;
// check if custom flags have changed; if so, we need to regenerate the
// cache file.
- if (message->internalFlags & MaildirMessage::CustomFlagsChanged)
- customFlagsChanged = true;
+ if (message->internalFlags & MaildirMessage::CustomFlagsChanged) customFlagsChanged = true;
// generate the flag string.
string flags;
@@ -81,29 +77,26 @@ void Binc::Maildir::updateFlags(void)
// message.
string srcname = curpath + filename;
string destname = curpath + uniquename + ":2," + flags;
- if (srcname == destname)
- continue;
+ if (srcname == destname) continue;
// rename the file
if (rename(srcname.c_str(), destname.c_str()) != 0) {
if (errno == ENOENT) {
closedir(pdir);
if ((pdir = opendir(curpath.c_str())) == 0) {
- bincError << "failed to open " << curpath << ": "
- << strerror(errno) << endl;
+ bincError << "failed to open " << curpath << ": " << strerror(errno) << endl;
return;
}
- // restart scan. this catches the race condition where concurrent
- // clients may have set a flag or removed the message.
+ // restart scan. this catches the race condition where concurrent
+ // clients may have set a flag or removed the message.
continue;
}
- bincError << "failed to rename " << srcname
- << " to " << destname << ": "
- << strerror(errno) << endl;
+ bincError << "failed to rename " << srcname << " to " << destname << ": " << strerror(errno)
+ << endl;
} else {
- index.insert(uniquename, 0, uniquename + ":2," + flags);
+ index.insert(uniquename, 0, uniquename + ":2," + flags);
}
}
diff --git a/src/maildir-writecache.cc b/src/maildir-writecache.cc
index feda4bd..2a51b49 100644
--- a/src/maildir-writecache.cc
+++ b/src/maildir-writecache.cc
@@ -2,22 +2,21 @@
* @file maildir-writecache.cc
* @brief Implementation of the Maildir class.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ------------------------------------------------------------------ **/
+#include "globals.h"
+#include "maildir.h"
+
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
-#include "globals.h"
-#include "maildir.h"
-
using namespace ::std;
//------------------------------------------------------------------------
bool Binc::Maildir::writeCache(void)
{
- if (readOnly)
- return true;
+ if (readOnly) return true;
char *safename = strdup((path + "/.bincimap-cache-tmp-XXXXXX").c_str());
int fd = mkstemp(safename);
@@ -44,12 +43,14 @@ bool Binc::Maildir::writeCache(void)
Mailbox::iterator i = begin(SequenceSet::all(), INCLUDE_EXPUNGED);
for (; i != end(); ++i) {
MaildirMessage &message = (MaildirMessage &)*i;
- fprintf(fp, "%u %u %u %s", message.getUID(),
- (unsigned int) message.getInternalDate(), message.getSize(),
- message.getUnique().c_str());
+ fprintf(fp,
+ "%u %u %u %s",
+ message.getUID(),
+ (unsigned int)message.getInternalDate(),
+ message.getSize(),
+ message.getUnique().c_str());
vector<string> cflags = message.getCustomFlags();
- for (vector<string>::const_iterator it = cflags.begin();
- it != cflags.end(); ++it) {
+ for (vector<string>::const_iterator it = cflags.begin(); it != cflags.end(); ++it) {
fprintf(fp, " %s", (*it).c_str());
}
fprintf(fp, "\n");
diff --git a/src/maildir.cc b/src/maildir.cc
index 11f472c..5071a1a 100644
--- a/src/maildir.cc
+++ b/src/maildir.cc
@@ -4,30 +4,32 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <iostream>
-#include <iomanip>
+#include "maildir.h"
+
+#include "convert.h"
+#include "globals.h"
+#include "iodevice.h"
+#include "iofactory.h"
+#include "maildirmessage.h"
+#include "pendingupdates.h"
+#include "session.h"
+#include "status.h"
+
#include <algorithm>
+#include <iomanip>
+#include <iostream>
#include <ctype.h>
-#include <dirent.h>
#include <errno.h>
-#include <fcntl.h>
#include <stdio.h>
+
+#include <dirent.h>
+#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
-#include "convert.h"
-#include "iodevice.h"
-#include "iofactory.h"
-#include "maildir.h"
-#include "maildirmessage.h"
-#include "pendingupdates.h"
-#include "session.h"
-#include "status.h"
-#include "globals.h"
-
using namespace ::std;
using namespace Binc;
@@ -35,16 +37,18 @@ using namespace Binc;
static int numDeliveries = 0;
//------------------------------------------------------------------------
-Maildir::iterator::iterator(void)
-{
-}
+Maildir::iterator::iterator(void) {}
//------------------------------------------------------------------------
Maildir::iterator::iterator(Maildir *home,
- MessageMap::iterator it,
- const SequenceSet &_bset,
- unsigned int _mod)
- : BaseIterator(1), mailbox(home), bset(_bset), mod(_mod), i(it)
+ MessageMap::iterator it,
+ const SequenceSet &_bset,
+ unsigned int _mod)
+ : BaseIterator(1)
+ , mailbox(home)
+ , bset(_bset)
+ , mod(_mod)
+ , i(it)
{
uidmax = home->getMaxUid();
sqnrmax = home->getMaxSqnr();
@@ -52,14 +56,17 @@ Maildir::iterator::iterator(Maildir *home,
//------------------------------------------------------------------------
Maildir::iterator::iterator(const iterator &copy)
- : BaseIterator(copy.sqnr), mailbox(copy.mailbox),
- bset(copy.bset), mod(copy.mod), i(copy.i), uidmax(copy.uidmax),
- sqnrmax(copy.sqnrmax)
-{
-}
+ : BaseIterator(copy.sqnr)
+ , mailbox(copy.mailbox)
+ , bset(copy.bset)
+ , mod(copy.mod)
+ , i(copy.i)
+ , uidmax(copy.uidmax)
+ , sqnrmax(copy.sqnrmax)
+{}
//------------------------------------------------------------------------
-Maildir::iterator &Maildir::iterator::operator =(const iterator &copy)
+Maildir::iterator &Maildir::iterator::operator=(const iterator &copy)
{
sqnr = copy.sqnr;
mailbox = copy.mailbox;
@@ -72,9 +79,7 @@ Maildir::iterator &Maildir::iterator::operator =(const iterator &copy)
}
//------------------------------------------------------------------------
-Maildir::iterator::~iterator(void)
-{
-}
+Maildir::iterator::~iterator(void) {}
//------------------------------------------------------------------------
MaildirMessage &Maildir::iterator::curMessage(void)
@@ -83,13 +88,13 @@ MaildirMessage &Maildir::iterator::curMessage(void)
}
//------------------------------------------------------------------------
-Message &Maildir::iterator::operator *(void)
+Message &Maildir::iterator::operator*(void)
{
return curMessage();
}
//------------------------------------------------------------------------
-void Maildir::iterator::operator ++(void)
+void Maildir::iterator::operator++(void)
{
++i;
++sqnr;
@@ -97,14 +102,14 @@ void Maildir::iterator::operator ++(void)
}
//------------------------------------------------------------------------
-bool Maildir::iterator::operator ==(const BaseIterator &a) const
+bool Maildir::iterator::operator==(const BaseIterator &a) const
{
const iterator *b = dynamic_cast<const iterator *>(&a);
return b ? (i == b->i) : false;
}
//------------------------------------------------------------------------
-bool Maildir::iterator::operator !=(const BaseIterator &a) const
+bool Maildir::iterator::operator!=(const BaseIterator &a) const
{
return !((*this) == a);
}
@@ -113,8 +118,7 @@ bool Maildir::iterator::operator !=(const BaseIterator &a) const
void Maildir::iterator::reposition(void)
{
for (;;) {
- if (i == mailbox->messages.end())
- break;
+ if (i == mailbox->messages.end()) break;
Message &message = curMessage();
if ((mod & SKIP_EXPUNGED) && message.isExpunged()) {
@@ -124,17 +128,15 @@ void Maildir::iterator::reposition(void)
bool inset = false;
if (mod & SQNR_MODE) {
- if (bset.isInSet(sqnr) || (!bset.isLimited() && sqnr == sqnrmax))
- inset = true;
+ if (bset.isInSet(sqnr) || (!bset.isLimited() && sqnr == sqnrmax)) inset = true;
} else {
if (bset.isInSet(message.getUID()) || (!bset.isLimited() && message.getUID() == uidmax))
- inset = true;
+ inset = true;
}
if (!inset) {
++i;
- if (!message.isExpunged())
- ++sqnr;
+ if (!message.isExpunged()) ++sqnr;
continue;
}
@@ -143,8 +145,7 @@ void Maildir::iterator::reposition(void)
}
//------------------------------------------------------------------------
-Mailbox::iterator Maildir::begin(const SequenceSet &bset,
- unsigned int mod) const
+Mailbox::iterator Maildir::begin(const SequenceSet &bset, unsigned int mod) const
{
beginIterator = iterator((Maildir *)this, messages.begin(), bset, mod);
beginIterator.reposition();
@@ -155,8 +156,7 @@ Mailbox::iterator Maildir::begin(const SequenceSet &bset,
//------------------------------------------------------------------------
Mailbox::iterator Maildir::end(void) const
{
- endIterator = iterator((Maildir *)this, messages.end(),
- endIterator.bset, endIterator.mod);
+ endIterator = iterator((Maildir *)this, messages.end(), endIterator.bset, endIterator.mod);
return Mailbox::iterator(endIterator);
}
@@ -165,7 +165,7 @@ void Maildir::iterator::erase(void)
{
MessageMap::iterator iter = i;
++iter;
-
+
MaildirMessageCache::getInstance().removeStatus(&curMessage());
mailbox->index.remove(i->second.getUnique());
mailbox->messages.erase(i);
@@ -187,9 +187,7 @@ Maildir::Maildir(void) : Mailbox()
}
//------------------------------------------------------------------------
-Maildir::~Maildir(void)
-{
-}
+Maildir::~Maildir(void) {}
//------------------------------------------------------------------------
void Maildir::setPath(const string &path_in)
@@ -198,63 +196,56 @@ void Maildir::setPath(const string &path_in)
}
//------------------------------------------------------------------------
-bool Maildir::getUpdates(bool doscan, unsigned int type,
- PendingUpdates &updates, bool forceScan)
+bool Maildir::getUpdates(bool doscan, unsigned int type, PendingUpdates &updates, bool forceScan)
{
- if (doscan && scan(forceScan) != Success)
- return false;
+ if (doscan && scan(forceScan) != Success) return false;
unsigned int exists = 0;
unsigned int recent = 0;
bool displayExists = false;
// count messages, find recent
- if (!readOnly && (type & PendingUpdates::EXPUNGE)) {
- Mailbox::iterator i = begin(SequenceSet::all(),
- INCLUDE_EXPUNGED | SQNR_MODE);
+ if (!readOnly && (type & PendingUpdates::EXPUNGE)) {
+ Mailbox::iterator i = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE);
while (i != end()) {
Message &message = *i;
if (message.isExpunged()) {
- updates.addExpunged(i.getSqnr());
- i.erase();
- mailboxchanged = true;
- displayExists = true;
+ updates.addExpunged(i.getSqnr());
+ i.erase();
+ mailboxchanged = true;
+ displayExists = true;
} else
- ++i;
+ ++i;
}
}
- Mailbox::iterator i = begin(SequenceSet::all(),
- INCLUDE_EXPUNGED | SQNR_MODE);
+ Mailbox::iterator i = begin(SequenceSet::all(), INCLUDE_EXPUNGED | SQNR_MODE);
for (; i != end(); ++i) {
- Message & message = *i;
+ Message &message = *i;
// at this point, there is a message that is not expunged
++exists;
if (message.getStdFlags() & Message::F_RECENT) ++recent;
}
- if (displayExists || exists != oldexists)
- updates.setExists(oldexists = exists);
+ if (displayExists || exists != oldexists) updates.setExists(oldexists = exists);
+
+ if (recent != oldrecent) updates.setRecent(oldrecent = recent);
- if (recent != oldrecent)
- updates.setRecent(oldrecent = recent);
-
- if (type & PendingUpdates::FLAGS) {
+ if (type & PendingUpdates::FLAGS) {
Mailbox::iterator i = begin(SequenceSet::all(), SQNR_MODE);
for (; i != end(); ++i) {
Message &message = *i;
if (message.hasFlagsChanged()) {
int flags = message.getStdFlags();
-
- updates.addFlagUpdates(i.getSqnr(), message.getUID(), flags,
- message.getCustomFlags());
+
+ updates.addFlagUpdates(i.getSqnr(), message.getUID(), flags, message.getCustomFlags());
message.setFlagsUnchanged();
}
}
- }
+ }
return true;
}
@@ -264,12 +255,9 @@ bool Maildir::isMailbox(const std::string &s_in) const
{
struct stat mystat;
- return ((stat((s_in + "/cur").c_str(), &mystat) == 0
- && S_ISDIR(mystat.st_mode))
- && (stat((s_in + "/new").c_str(), &mystat) == 0
- && S_ISDIR(mystat.st_mode))
- && (stat((s_in + "/tmp").c_str(), &mystat) == 0
- && S_ISDIR(mystat.st_mode)));
+ return ((stat((s_in + "/cur").c_str(), &mystat) == 0 && S_ISDIR(mystat.st_mode))
+ && (stat((s_in + "/new").c_str(), &mystat) == 0 && S_ISDIR(mystat.st_mode))
+ && (stat((s_in + "/tmp").c_str(), &mystat) == 0 && S_ISDIR(mystat.st_mode)));
}
//------------------------------------------------------------------------
@@ -291,12 +279,10 @@ bool Maildir::isMarked(const std::string &s_in) const
DIR *dirp = opendir((s_in + "/new").c_str());
if (dirp == 0) return false;
- struct dirent *direntp;
+ struct dirent *direntp;
while ((direntp = readdir(dirp)) != 0) {
string s = direntp->d_name;
- if (s[0] != '.'
- && s.find('/') == string::npos
- && s.find(':') == string::npos) {
+ if (s[0] != '.' && s.find('/') == string::npos && s.find(':') == string::npos) {
closedir(dirp);
return true;
}
@@ -307,24 +293,21 @@ bool Maildir::isMarked(const std::string &s_in) const
}
//------------------------------------------------------------------------
-unsigned int Maildir::getStatusID(const string &path) const
+unsigned int Maildir::getStatusID(const string &path) const
{
unsigned int statusid = 0;
struct stat mystat;
- if (stat((path + "/new/").c_str(), &mystat) == 0)
- statusid = mystat.st_ctime;
+ if (stat((path + "/new/").c_str(), &mystat) == 0) statusid = mystat.st_ctime;
- if (stat((path + "/cur/").c_str(), &mystat) == 0)
- statusid += mystat.st_ctime;
+ if (stat((path + "/cur/").c_str(), &mystat) == 0) statusid += mystat.st_ctime;
- if (stat((path + "/bincimap-cache").c_str(), &mystat) == 0)
- statusid += mystat.st_ctime;
+ if (stat((path + "/bincimap-cache").c_str(), &mystat) == 0) statusid += mystat.st_ctime;
return statusid;
}
//------------------------------------------------------------------------
-bool Maildir::getStatus(const string &path, Status &s) const
+bool Maildir::getStatus(const string &path, Status &s) const
{
unsigned int messages = 0;
unsigned int unseen = 0;
@@ -336,36 +319,22 @@ bool Maildir::getStatus(const string &path, Status &s) const
const string cachefilename = path + "/bincimap-cache";
FILE *fp = fopen(cachefilename.c_str(), "r");
- if (fp) do {
- char inputBuffer[512];
- if (!fgets(inputBuffer, sizeof(inputBuffer), fp)) {
- fclose(fp);
- return false;
- }
+ if (fp) do
+ {
+ char inputBuffer[512];
+ if (!fgets(inputBuffer, sizeof(inputBuffer), fp)) {
+ fclose(fp);
+ return false;
+ }
- // terminate the buffer
- inputBuffer[sizeof(inputBuffer) - 1] = '\0';
+ // terminate the buffer
+ inputBuffer[sizeof(inputBuffer) - 1] = '\0';
- char cacheFileVersionBuffer[512];
-
- if (sscanf(inputBuffer, "%s %u %u", cacheFileVersionBuffer,
- &readUidValidity, &readUidNext) != 3
- || strcmp(cacheFileVersionBuffer, BINC_CACHE) != 0) {
- fclose(fp);
- readUidValidity = 0;
- readUidNext = 1;
- mincache.clear();
- break;
- }
+ char cacheFileVersionBuffer[512];
- unsigned int readUID;
- unsigned int readSize;
- unsigned int readInternalDate;
- char readUnique[512];
- while (fgets(inputBuffer, sizeof(inputBuffer), fp)) {
- inputBuffer[sizeof(inputBuffer) - 1] = '\0';
- if (sscanf(inputBuffer, "%u %u %u %s", &readUID,
- &readInternalDate, &readSize, readUnique) != 4) {
+ if (sscanf(inputBuffer, "%s %u %u", cacheFileVersionBuffer, &readUidValidity, &readUidNext) != 3
+ || strcmp(cacheFileVersionBuffer, BINC_CACHE) != 0)
+ {
fclose(fp);
readUidValidity = 0;
readUidNext = 1;
@@ -373,13 +342,29 @@ bool Maildir::getStatus(const string &path, Status &s) const
break;
}
- mincache[readUnique] = true;
- }
-
- fclose(fp);
+ unsigned int readUID;
+ unsigned int readSize;
+ unsigned int readInternalDate;
+ char readUnique[512];
+ while (fgets(inputBuffer, sizeof(inputBuffer), fp)) {
+ inputBuffer[sizeof(inputBuffer) - 1] = '\0';
+ if (sscanf(inputBuffer, "%u %u %u %s", &readUID, &readInternalDate, &readSize, readUnique) != 4)
+ {
+ fclose(fp);
+ readUidValidity = 0;
+ readUidNext = 1;
+ mincache.clear();
+ break;
+ }
- s.setUidValidity(readUidValidity < 1 ? time(0) : readUidValidity);
- } while (0); else {
+ mincache[readUnique] = true;
+ }
+
+ fclose(fp);
+
+ s.setUidValidity(readUidValidity < 1 ? time(0) : readUidValidity);
+ } while (0);
+ else {
s.setUidValidity(time(0));
}
@@ -387,12 +372,10 @@ bool Maildir::getStatus(const string &path, Status &s) const
DIR *dirp = opendir((path + "/new").c_str());
if (dirp == 0) return false;
- struct dirent *direntp;
+ struct dirent *direntp;
while ((direntp = readdir(dirp)) != 0) {
const string filename = direntp->d_name;
- if (filename[0] == '.'
- || filename.find(':') != string::npos
- || filename.find('/') != string::npos)
+ if (filename[0] == '.' || filename.find(':') != string::npos || filename.find('/') != string::npos)
continue;
++recent;
@@ -404,13 +387,11 @@ bool Maildir::getStatus(const string &path, Status &s) const
closedir(dirp);
// Scan cur
- if ((dirp = opendir((path + "/cur").c_str())) == 0)
- return false;
+ if ((dirp = opendir((path + "/cur").c_str())) == 0) return false;
while ((direntp = readdir(dirp)) != 0) {
const string dname = direntp->d_name;
- if (dname[0] == '.')
- continue;
+ if (dname[0] == '.') continue;
++messages;
@@ -423,8 +404,7 @@ bool Maildir::getStatus(const string &path, Status &s) const
++readUidNext;
}
- if (dname.substr(pos).find('S') == string::npos)
- ++unseen;
+ if (dname.substr(pos).find('S') == string::npos) ++unseen;
} else {
if (mincache.find(dname) == mincache.end()) {
++recent;
@@ -436,7 +416,7 @@ bool Maildir::getStatus(const string &path, Status &s) const
}
closedir(dirp);
-
+
s.setRecent(recent);
s.setMessages(messages);
s.setUnseen(unseen);
@@ -449,15 +429,13 @@ bool Maildir::getStatus(const string &path, Status &s) const
unsigned int Maildir::getMaxUid(void) const
{
MessageMap::const_iterator i = messages.end();
- if (i == messages.begin())
- return 0;
+ if (i == messages.begin()) return 0;
--i;
for (;;) {
const MaildirMessage &message = i->second;
if (message.isExpunged()) {
- if (i == messages.begin())
- return 0;
+ if (i == messages.begin()) return 0;
--i;
} else {
return message.getUID();
@@ -472,15 +450,13 @@ unsigned int Maildir::getMaxSqnr(void) const
{
int sqnr = messages.size();
MessageMap::const_iterator i = messages.end();
- if (i == messages.begin())
- return 0;
+ if (i == messages.begin()) return 0;
--i;
for (;;) {
const MaildirMessage &message = i->second;
if (message.isExpunged()) {
- if (i == messages.begin())
- return 0;
+ if (i == messages.begin()) return 0;
--sqnr;
--i;
} else {
@@ -539,7 +515,7 @@ bool Maildir::commitNewMessages(const string &mbox)
map<MaildirMessage *, string> committedMessages;
struct timeval youngestFile = {0, 0};
-
+
bool abort = false;
while (!abort && i != newMessages.end()) {
MaildirMessage &m = *i;
@@ -560,13 +536,10 @@ bool Maildir::commitNewMessages(const string &mbox)
// Generate Maildir conformant file name
BincStream ssid;
- ssid << (int) tv.tv_sec << "."
- << "R" << (int) rand()
- << "M" << (int) tv.tv_usec
- << "P" << (int) session.getPid()
- << "Q" << numDeliveries++
- << "." << session.getEnv("TCPLOCALHOST");
-
+ ssid << (int)tv.tv_sec << "."
+ << "R" << (int)rand() << "M" << (int)tv.tv_usec << "P" << (int)session.getPid() << "Q"
+ << numDeliveries++ << "." << session.getEnv("TCPLOCALHOST");
+
BincStream ss;
ss << mbox << "/new/" << ssid.str();
@@ -581,12 +554,10 @@ bool Maildir::commitNewMessages(const string &mbox)
break;
}
- if (errno == EEXIST)
- continue;
+ if (errno == EEXIST) continue;
- bincWarning << "link(" << toImapString(safeName) << ", "
- << toImapString(fileName) << ") failed: "
- << strerror(errno) << endl;
+ bincWarning << "link(" << toImapString(safeName) << ", " << toImapString(fileName)
+ << ") failed: " << strerror(errno) << endl;
session.setResponseCode("TRYCREATE");
session.setLastError("failed, internal error.");
@@ -605,24 +576,21 @@ bool Maildir::commitNewMessages(const string &mbox)
for (i = newMessages.begin(); i != newMessages.end(); ++i)
unlink((*i).getSafeName().c_str());
- map<MaildirMessage *, string>::const_iterator j
- = committedMessages.begin();
+ map<MaildirMessage *, string>::const_iterator j = committedMessages.begin();
while (j != committedMessages.end()) {
if (unlink(j->second.c_str()) != 0) {
if (errno == ENOENT) {
- // FIXME: The message was probably moves away from new/ by
- // another IMAP session.
- bincWarning << "error rollbacking after failed commit to "
- << toImapString(mbox) << ", failed to unlink "
- << toImapString(j->second)
- << ": " << strerror(errno) << endl;
+ // FIXME: The message was probably moves away from new/ by
+ // another IMAP session.
+ bincWarning << "error rollbacking after failed commit to " << toImapString(mbox)
+ << ", failed to unlink " << toImapString(j->second) << ": " << strerror(errno)
+ << endl;
} else {
- bincWarning << "error rollbacking after failed commit to "
- << toImapString(mbox) << ", failed to unlink "
- << toImapString(j->second)
- << ": " << strerror(errno) << endl;
- newMessages.clear();
- return false;
+ bincWarning << "error rollbacking after failed commit to " << toImapString(mbox)
+ << ", failed to unlink " << toImapString(j->second) << ": " << strerror(errno)
+ << endl;
+ newMessages.clear();
+ return false;
}
}
@@ -639,14 +607,12 @@ bool Maildir::commitNewMessages(const string &mbox)
// moving the message into cur.
struct timeval tv;
gettimeofday(&tv, 0);
- while (tv.tv_sec == youngestFile.tv_sec
- && tv.tv_usec == youngestFile.tv_usec) {
+ while (tv.tv_sec == youngestFile.tv_sec && tv.tv_usec == youngestFile.tv_usec) {
gettimeofday(&tv, 0);
}
- map<MaildirMessage *, string>::const_iterator j
- = committedMessages.begin();
- for (;j != committedMessages.end(); ++j) {
+ map<MaildirMessage *, string>::const_iterator j = committedMessages.begin();
+ for (; j != committedMessages.end(); ++j) {
string basename = j->second.substr(j->second.rfind('/') + 1);
int flags = j->first->getStdFlags();
@@ -656,14 +622,12 @@ bool Maildir::commitNewMessages(const string &mbox)
if (flags & Message::F_ANSWERED) flagStr += "R";
if (flags & Message::F_SEEN) flagStr += "S";
if (flags & Message::F_DELETED) flagStr += "T";
-
+
string dest = mbox + "/cur/" + basename + ":2," + flagStr;
- if (rename(j->second.c_str(), dest.c_str()) == 0)
- continue;
+ if (rename(j->second.c_str(), dest.c_str()) == 0) continue;
if (errno != ENOENT)
- bincWarning << "when setting flags on: " << j->second
- << ": " << strerror(errno) << endl;
+ bincWarning << "when setting flags on: " << j->second << ": " << strerror(errno) << endl;
}
committedMessages.clear();
@@ -684,8 +648,7 @@ bool Maildir::rollBackNewMessages(void)
}
//------------------------------------------------------------------------
-bool Maildir::fastCopy(Message &m, Mailbox &desttype,
- const std::string &destname)
+bool Maildir::fastCopy(Message &m, Mailbox &desttype, const std::string &destname)
{
// At this point, fastCopy is broken because the creation time is
// equal for the two clones. The new clone must have a new creation
@@ -696,54 +659,44 @@ bool Maildir::fastCopy(Message &m, Mailbox &desttype,
Session &session = Session::getInstance();
MaildirMessage *message = dynamic_cast<MaildirMessage *>(&m);
- if (!message)
- return false;
+ if (!message) return false;
string mfilename = message->getFileName();
- if (mfilename == "")
- return false;
+ if (mfilename == "") return false;
Maildir *mailbox = dynamic_cast<Maildir *>(&desttype);
- if (!mailbox)
- return false;
+ if (!mailbox) return false;
for (int attempt = 0; attempt < 1000; ++attempt) {
-
struct timeval tv;
gettimeofday(&tv, 0);
// Generate Maildir conformant file name
BincStream ssid;
- ssid << (int) tv.tv_sec << "."
- << "R" << (int) rand()
- << "M" << (int) tv.tv_usec
- << "P" << (int) session.getPid()
- << "Q" << numDeliveries++
- << "." << session.getEnv("TCPLOCALHOST");
+ ssid << (int)tv.tv_sec << "."
+ << "R" << (int)rand() << "M" << (int)tv.tv_usec << "P" << (int)session.getPid() << "Q"
+ << numDeliveries++ << "." << session.getEnv("TCPLOCALHOST");
BincStream ss;
ss << destname << "/tmp/" << ssid.str();
-
+
string fileName = ss.str();
-
+
if (link((path + "/cur/" + mfilename).c_str(), fileName.c_str()) == 0) {
MaildirMessage newmess = *message;
newmess.setSafeName(fileName);
newmess.setUnique(ssid.str());
- newmess.setInternalDate((time_t) tv.tv_sec);
+ newmess.setInternalDate((time_t)tv.tv_sec);
newmess.setUID(0);
newMessages.push_back(newmess);
break;
}
-
- if (errno == EEXIST)
- continue;
-
- bincWarning << "Warning: link("
- << toImapString(path + "/cur/" + mfilename)
- << ", " << toImapString(fileName) << ") failed: "
- << strerror(errno) << endl;
-
+
+ if (errno == EEXIST) continue;
+
+ bincWarning << "Warning: link(" << toImapString(path + "/cur/" + mfilename) << ", "
+ << toImapString(fileName) << ") failed: " << strerror(errno) << endl;
+
session.setResponseCode("TRYCREATE");
session.setLastError("failed, internal error.");
return false;
@@ -756,12 +709,10 @@ bool Maildir::fastCopy(Message &m, Mailbox &desttype,
MaildirMessage *Maildir::get(const std::string &id)
{
MaildirIndexItem *item = index.find(id);
- if (!item)
- return 0;
+ if (!item) return 0;
unsigned int uid = item->uid;
- if (messages.find(uid) == messages.end())
- return 0;
+ if (messages.find(uid) == messages.end()) return 0;
return &messages.find(uid)->second;
}
@@ -770,8 +721,7 @@ MaildirMessage *Maildir::get(const std::string &id)
void Maildir::add(MaildirMessage &m)
{
MessageMap::iterator it = messages.find(m.getUID());
- if (it != messages.end())
- messages.erase(it);
+ if (it != messages.end()) messages.erase(it);
messages.insert(make_pair(m.getUID(), m));
index.insert(m.getUnique(), m.getUID());
}
@@ -783,8 +733,7 @@ unsigned int MaildirIndex::getSize(void) const
}
//------------------------------------------------------------------------
-void MaildirIndex::insert(const string &unique, unsigned int uid,
- const string &fileName)
+void MaildirIndex::insert(const string &unique, unsigned int uid, const string &fileName)
{
if (idx.find(unique) == idx.end()) {
MaildirIndexItem item;
@@ -802,16 +751,14 @@ void MaildirIndex::insert(const string &unique, unsigned int uid,
void MaildirIndex::remove(const string &unique)
{
map<string, MaildirIndexItem>::iterator it = idx.find(unique);
- if (it != idx.end())
- idx.erase(it);
+ if (it != idx.end()) idx.erase(it);
}
//------------------------------------------------------------------------
MaildirIndexItem *MaildirIndex::find(const string &unique)
{
map<string, MaildirIndexItem>::iterator it = idx.find(unique);
- if (it != idx.end())
- return &it->second;
+ if (it != idx.end()) return &it->second;
return 0;
}
diff --git a/src/maildirmessage.cc b/src/maildirmessage.cc
index a78a5b9..ee1d889 100644
--- a/src/maildirmessage.cc
+++ b/src/maildirmessage.cc
@@ -4,24 +4,26 @@
* @author Andreas Aardal Hanssen
* @date Copyright 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
-#include <stack>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <ctype.h>
-#include <time.h>
-#include <utime.h>
-
-#include "maildir.h"
#include "maildirmessage.h"
+
#include "convert.h"
-#include "mime.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "mime-utils.h"
+#include "maildir.h"
#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
+
+#include <stack>
+#include <string>
+
+#include <ctype.h>
+#include <errno.h>
+#include <time.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <utime.h>
using namespace ::std;
using namespace Binc;
@@ -31,8 +33,10 @@ string MaildirMessage::storage;
namespace {
//----------------------------------------------------------------------
- void printOneHeader(IODevice &io, const MimePart *message,
- const string &s_in, bool removecomments = true)
+ void printOneHeader(IODevice &io,
+ const MimePart *message,
+ const string &s_in,
+ bool removecomments = true)
{
string tmp = "";
HeaderItem hitem;
@@ -45,8 +49,10 @@ namespace {
}
//----------------------------------------------------------------------
- void printOneAddressList(IODevice &io, const MimePart *message,
- const string &s_in, bool removecomments = true)
+ void printOneAddressList(IODevice &io,
+ const MimePart *message,
+ const string &s_in,
+ bool removecomments = true)
{
string tmp = "";
HeaderItem hitem;
@@ -57,12 +63,12 @@ namespace {
splitAddr(unfold(tmp, removecomments), addr);
if (addr.size() != 0) {
io << "(";
- for (vector<string>::const_iterator i = addr.begin();
- i != addr.end(); ++i)
+ for (vector<string>::const_iterator i = addr.begin(); i != addr.end(); ++i)
- io << Address(*i).toParenList();
+ io << Address(*i).toParenList();
io << ")";
- } else io << "NIL";
+ } else
+ io << "NIL";
} else
io << "NIL";
}
@@ -78,13 +84,15 @@ namespace {
io << " ";
printOneAddressList(io, message, "from", false);
io << " ";
- printOneAddressList(io, message,
- message->h.getFirstHeader("sender", hitem)
- ? "sender" : "from", false);
+ printOneAddressList(io,
+ message,
+ message->h.getFirstHeader("sender", hitem) ? "sender" : "from",
+ false);
io << " ";
- printOneAddressList(io, message,
- message->h.getFirstHeader("reply-to", hitem)
- ? "reply-to" : "from", false);
+ printOneAddressList(io,
+ message,
+ message->h.getFirstHeader("reply-to", hitem) ? "reply-to" : "from",
+ false);
io << " ";
printOneAddressList(io, message, "to", false);
io << " ";
@@ -104,9 +112,9 @@ namespace {
HeaderItem hitem;
if (message->isMultipart() && message->members.size() > 0) {
io << "(";
-
- for (vector<MimePart>::const_iterator i = message->members.begin();
- i != message->members.end(); ++i)
+
+ for (vector<MimePart>::const_iterator i = message->members.begin(); i != message->members.end();
+ ++i)
bodyStructure(io, &(*i), extended);
io << " ";
@@ -128,7 +136,7 @@ namespace {
vector<string> v;
split(tmp, ";", v);
-
+
for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
string element = *i;
trim(element);
@@ -145,18 +153,17 @@ namespace {
if (parameters.size() != 0) {
io << "(";
- for (vector<string>::const_iterator i = parameters.begin();
- i != parameters.end(); ++i) {
+ for (vector<string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
if (i != parameters.begin()) io << " ";
io << toImapString(*i);
- }
+ }
io << ")";
} else
io << "NIL";
} else
io << "NIL";
- // CONTENT-DISPOSITION
+ // CONTENT-DISPOSITION
io << " ";
tmp = "";
if (message->h.getFirstHeader("content-disposition", hitem)) {
@@ -188,8 +195,10 @@ namespace {
trim(key, " \"");
trim(value, " \"");
- if (!wrote) wrote = true;
- else io << " ";
+ if (!wrote)
+ wrote = true;
+ else
+ io << " ";
io << toImapString(key);
io << " ";
@@ -198,15 +207,15 @@ namespace {
++i;
}
io << ")";
- } else
- io << "NIL";
- io << ")";
+ } else
+ io << "NIL";
+ io << ")";
} else
- io << "NIL";
+ io << "NIL";
} else
- io << "NIL";
+ io << "NIL";
- // CONTENT-LANGUAGE
+ // CONTENT-LANGUAGE
io << " ";
printOneHeader(io, message, "content-language");
}
@@ -224,38 +233,38 @@ namespace {
if (message->h.getFirstHeader("content-type", hitem)) {
tmp = unfold(hitem.getValue());
- vector<string> v;
- split(tmp, ";", v);
-
- if (v.size() > 0) {
- vector<string> b;
- split(v[0], "/", b);
-
- if (b.size() > 0)
- type = b[0];
- else
- type = "text";
-
- if (b.size() > 1)
- subtype = b[1];
- else
- subtype = "plain";
- }
-
- for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
- if (i == v.begin()) continue;
- string element = *i;
- trim(element);
- if (element.find('=') != string::npos) {
- string::size_type pos = element.find('=');
- string s = element.substr(0, pos);
- string t = element.substr(pos + 1);
- trim(s, " \"");
- trim(t, " \"");
- parameters.push_back(s);
- parameters.push_back(t);
+ vector<string> v;
+ split(tmp, ";", v);
+
+ if (v.size() > 0) {
+ vector<string> b;
+ split(v[0], "/", b);
+
+ if (b.size() > 0)
+ type = b[0];
+ else
+ type = "text";
+
+ if (b.size() > 1)
+ subtype = b[1];
+ else
+ subtype = "plain";
+ }
+
+ for (vector<string>::const_iterator i = v.begin(); i != v.end(); ++i) {
+ if (i == v.begin()) continue;
+ string element = *i;
+ trim(element);
+ if (element.find('=') != string::npos) {
+ string::size_type pos = element.find('=');
+ string s = element.substr(0, pos);
+ string t = element.substr(pos + 1);
+ trim(s, " \"");
+ trim(t, " \"");
+ parameters.push_back(s);
+ parameters.push_back(t);
+ }
}
- }
} else {
type = "text";
@@ -269,15 +278,13 @@ namespace {
io << " ";
if (parameters.size() != 0) {
io << "(";
- for (vector<string>::const_iterator i = parameters.begin();
- i != parameters.end(); ++i) {
- if (i != parameters.begin())
- io << " ";
+ for (vector<string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
+ if (i != parameters.begin()) io << " ";
io << toImapString(*i);
}
io << ")";
} else
- io << "NIL";
+ io << "NIL";
// CONTENT-ID
io << " ";
@@ -317,59 +324,61 @@ namespace {
// Extension data follows
if (extended) {
- // CONTENT-MD5
- io << " ";
- printOneHeader(io, message, "content-md5");
-
- // CONTENT-DISPOSITION
- io << " ";
- tmp = "";
- if (message->h.getFirstHeader("content-disposition", hitem)) {
- tmp = hitem.getValue();
- trim(tmp);
- vector<string> v;
- split(tmp, ";", v);
- if (v.size() > 0) {
- string disp = v[0];
- trim(disp);
- io << "(" << toImapString(disp);
- io << " ";
- if (v.size() > 1) {
- io << "(";
- vector<string>::const_iterator i = v.begin();
- ++i;
- bool wrote = false;
- while (i != v.end()) {
- string s = *i;
- trim(s);
- string::size_type pos = s.find('=');
- string key = s.substr(0, pos);
- string value = s.substr(pos + 1);
- trim(key);
- trim(value);
- trim(key, " \"");
- trim(value, " \"");
- if (!wrote) wrote = true;
- else io << " ";
- io << toImapString(key);
- io << " ";
- io << toImapString(value);
- ++i;
- }
- io << ")";
- } else
- io << "NIL";
- io << ")";
- } else
- io << "NIL";
- } else
- io << "NIL";
-
- // CONTENT-LANGUAGE
+ // CONTENT-MD5
+ io << " ";
+ printOneHeader(io, message, "content-md5");
+
+ // CONTENT-DISPOSITION
+ io << " ";
+ tmp = "";
+ if (message->h.getFirstHeader("content-disposition", hitem)) {
+ tmp = hitem.getValue();
+ trim(tmp);
+ vector<string> v;
+ split(tmp, ";", v);
+ if (v.size() > 0) {
+ string disp = v[0];
+ trim(disp);
+ io << "(" << toImapString(disp);
+ io << " ";
+ if (v.size() > 1) {
+ io << "(";
+ vector<string>::const_iterator i = v.begin();
+ ++i;
+ bool wrote = false;
+ while (i != v.end()) {
+ string s = *i;
+ trim(s);
+ string::size_type pos = s.find('=');
+ string key = s.substr(0, pos);
+ string value = s.substr(pos + 1);
+ trim(key);
+ trim(value);
+ trim(key, " \"");
+ trim(value, " \"");
+ if (!wrote)
+ wrote = true;
+ else
+ io << " ";
+ io << toImapString(key);
+ io << " ";
+ io << toImapString(value);
+ ++i;
+ }
+ io << ")";
+ } else
+ io << "NIL";
+ io << ")";
+ } else
+ io << "NIL";
+ } else
+ io << "NIL";
+
+ // CONTENT-LANGUAGE
io << " ";
printOneHeader(io, message, "content-language");
- // CONTENT-LOCATION
+ // CONTENT-LOCATION
io << " ";
printOneHeader(io, message, "content-location");
}
@@ -380,19 +389,32 @@ namespace {
}
//------------------------------------------------------------------------
-MaildirMessage::MaildirMessage(Maildir &hom)
- : fd(-1), doc(0), internalFlags(None), stdflags(F_NONE),
- uid(0), size(0), unique(""), safeName(""), internaldate(0),
- home(hom), customFlags(0)
-{
-}
+MaildirMessage::MaildirMessage(Maildir &hom)
+ : fd(-1)
+ , doc(0)
+ , internalFlags(None)
+ , stdflags(F_NONE)
+ , uid(0)
+ , size(0)
+ , unique("")
+ , safeName("")
+ , internaldate(0)
+ , home(hom)
+ , customFlags(0)
+{}
//------------------------------------------------------------------------
-MaildirMessage::MaildirMessage(const MaildirMessage &copy)
- : fd(copy.fd), doc(copy.doc), internalFlags(copy.internalFlags),
- stdflags(copy.stdflags), uid(copy.uid), size(copy.size),
- unique(copy.unique), safeName(copy.safeName),
- internaldate(copy.internaldate), home(copy.home)
+MaildirMessage::MaildirMessage(const MaildirMessage &copy)
+ : fd(copy.fd)
+ , doc(copy.doc)
+ , internalFlags(copy.internalFlags)
+ , stdflags(copy.stdflags)
+ , uid(copy.uid)
+ , size(copy.size)
+ , unique(copy.unique)
+ , safeName(copy.safeName)
+ , internaldate(copy.internaldate)
+ , home(copy.home)
{
if (copy.customFlags) {
customFlags = new vector<string>;
@@ -409,15 +431,15 @@ MaildirMessage::~MaildirMessage(void)
}
//------------------------------------------------------------------------
-MaildirMessage &MaildirMessage::operator =(const MaildirMessage &copy)
+MaildirMessage &MaildirMessage::operator=(const MaildirMessage &copy)
{
fd = copy.fd;
- doc = copy.doc;
+ doc = copy.doc;
internalFlags = copy.internalFlags;
stdflags = copy.stdflags;
uid = copy.uid;
size = copy.size;
- unique = copy.unique;
+ unique = copy.unique;
safeName = copy.safeName;
internaldate = copy.internaldate;
home = copy.home;
@@ -433,16 +455,16 @@ MaildirMessage &MaildirMessage::operator =(const MaildirMessage &copy)
}
//------------------------------------------------------------------------
-bool MaildirMessage::operator <(const MaildirMessage &a) const
+bool MaildirMessage::operator<(const MaildirMessage &a) const
{
return uid < a.uid;
}
+
//------------------------------------------------------------------------
void MaildirMessage::close(void)
{
if (fd != -1) {
- if ((internalFlags & WasWrittenTo) && fsync(fd) != 0
- && errno != EINVAL && errno != EROFS) {
+ if ((internalFlags & WasWrittenTo) && fsync(fd) != 0 && errno != EINVAL && errno != EROFS) {
// FIXME: report this error
}
@@ -582,14 +604,13 @@ void MaildirMessage::setUnique(const string &s_in)
//------------------------------------------------------------------------
int MaildirMessage::getFile(void) const
{
- if (fd != -1)
- return fd;
+ if (fd != -1) return fd;
const string &id = getUnique();
MaildirIndexItem *item = home.index.find(id);
if (item) {
string fpath = home.path + "/cur/" + item->fileName;
-
+
unsigned int oflags = O_RDONLY;
#ifdef HAVE_OLARGEFILE
oflags |= O_LARGEFILE;
@@ -598,20 +619,19 @@ int MaildirMessage::getFile(void) const
if (errno == ENOENT) {
struct stat st;
if (lstat(fpath.c_str(), &st) != -1) {
- bincWarning << "dangling symlink: " << fpath << endl;
- return -1;
+ bincWarning << "dangling symlink: " << fpath << endl;
+ return -1;
}
} else {
- bincWarning << "unable to open " << fpath << ": "
- << strerror(errno) << endl;
- return -1;
+ bincWarning << "unable to open " << fpath << ": " << strerror(errno) << endl;
+ return -1;
}
home.scanFileNames();
if ((item = home.index.find(id)) == 0)
- break;
+ break;
else
- fpath = home.path + "/cur/" + item->fileName;
+ fpath = home.path + "/cur/" + item->fileName;
}
MaildirMessageCache &cache = MaildirMessageCache::getInstance();
@@ -648,8 +668,7 @@ string MaildirMessage::getFileName(void) const
if (!item) {
home.scanFileNames();
- if ((item = home.index.find(getUnique())) == 0)
- return "";
+ if ((item = home.index.find(getUnique())) == 0) return "";
}
return item->fileName;
@@ -659,15 +678,13 @@ string MaildirMessage::getFileName(void) const
int MaildirMessage::readChunk(string &chunk)
{
if (fd == -1) {
- if ((fd = getFile()) == -1)
- return -1;
+ if ((fd = getFile()) == -1) return -1;
}
char buffer[1024];
- ssize_t readBytes = read(fd, buffer, (size_t) sizeof(buffer));
+ ssize_t readBytes = read(fd, buffer, (size_t)sizeof(buffer));
if (readBytes == -1) {
- setLastError("Error reading from " + getFileName()
- + ": " + string(strerror(errno)));
+ setLastError("Error reading from " + getFileName() + ": " + string(strerror(errno)));
return -1;
}
@@ -679,8 +696,7 @@ int MaildirMessage::readChunk(string &chunk)
bool MaildirMessage::appendChunk(const string &chunk)
{
if (fd == -1) {
- setLastError("Error writing to " + getSafeName()
- + ": File is not open");
+ setLastError("Error writing to " + getSafeName() + ": File is not open");
return false;
}
@@ -689,27 +705,23 @@ bool MaildirMessage::appendChunk(const string &chunk)
string out;
for (string::const_iterator i = chunk.begin(); i != chunk.end(); ++i) {
const char c = *i;
- if (c != '\r')
- out += c;
+ if (c != '\r') out += c;
}
ssize_t wroteBytes = 0;
for (;;) {
- wroteBytes = write(fd, out.c_str(), (size_t) out.length());
+ wroteBytes = write(fd, out.c_str(), (size_t)out.length());
if (wroteBytes == -1) {
- if (errno == EINTR)
- continue;
+ if (errno == EINTR) continue;
wroteBytes = 0;
}
break;
}
- if (wroteBytes == (ssize_t) out.length())
- return true;
+ if (wroteBytes == (ssize_t)out.length()) return true;
- setLastError("Error writing to " + getSafeName()
- + ": " + string(strerror(errno)));
+ setLastError("Error writing to " + getSafeName() + ": " + string(strerror(errno)));
return false;
}
@@ -718,16 +730,13 @@ bool MaildirMessage::parseFull(void) const
{
MaildirMessageCache &cache = MaildirMessageCache::getInstance();
MaildirMessageCache::ParseStatus ps = cache.getStatus(this);
- if (ps == MaildirMessageCache::AllParsed && doc)
- return true;
+ if (ps == MaildirMessageCache::AllParsed && doc) return true;
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
// FIXME: parse errors
- if (!doc)
- doc = new MimeDocument;
+ if (!doc) doc = new MimeDocument;
doc->parseFull(fd);
cache.addStatus(this, MaildirMessageCache::AllParsed);
@@ -740,17 +749,14 @@ bool MaildirMessage::parseHeaders(void) const
{
MaildirMessageCache &cache = MaildirMessageCache::getInstance();
MaildirMessageCache::ParseStatus ps = cache.getStatus(this);
- if ((ps == MaildirMessageCache::AllParsed
- || ps == MaildirMessageCache::HeaderParsed) && doc)
+ if ((ps == MaildirMessageCache::AllParsed || ps == MaildirMessageCache::HeaderParsed) && doc)
return true;
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
// FIXME: parse errors
- if (!doc)
- doc = new MimeDocument;
+ if (!doc) doc = new MimeDocument;
doc->parseOnlyHeader(fd);
cache.addStatus(this, MaildirMessageCache::HeaderParsed);
@@ -761,8 +767,7 @@ bool MaildirMessage::parseHeaders(void) const
//------------------------------------------------------------------------
bool MaildirMessage::printBodyStructure(bool extended) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
bodyStructure(bincClient, doc, extended);
return true;
@@ -771,8 +776,7 @@ bool MaildirMessage::printBodyStructure(bool extended) const
//------------------------------------------------------------------------
bool MaildirMessage::printEnvelope(void) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
envelope(bincClient, doc);
return true;
@@ -780,11 +784,11 @@ bool MaildirMessage::printEnvelope(void) const
//------------------------------------------------------------------------
bool MaildirMessage::printHeader(const std::string &section,
- std::vector<std::string> headers,
- bool includeHeaders,
- unsigned int startOffset,
- unsigned int length,
- bool mime) const
+ std::vector<std::string> headers,
+ bool includeHeaders,
+ unsigned int startOffset,
+ unsigned int length,
+ bool mime) const
{
bincClient << storage;
storage = "";
@@ -793,44 +797,38 @@ bool MaildirMessage::printHeader(const std::string &section,
//------------------------------------------------------------------------
unsigned int MaildirMessage::getHeaderSize(const std::string &section,
- std::vector<std::string> headers,
- bool includeHeaders,
- unsigned int startOffset,
- unsigned int length,
- bool mime) const
+ std::vector<std::string> headers,
+ bool includeHeaders,
+ unsigned int startOffset,
+ unsigned int length,
+ bool mime) const
{
if (section == "") {
- if (!parseHeaders())
- return 0;
+ if (!parseHeaders()) return 0;
} else if (!parseFull())
return 0;
- const MimePart *part = doc->getPart(section, "", mime ? MimePart::FetchMime
- : MimePart::FetchHeader);
+ const MimePart *part = doc->getPart(section, "", mime ? MimePart::FetchMime : MimePart::FetchHeader);
if (!part) {
storage = "";
return 0;
}
int fd = getFile();
- if (fd == -1)
- return 0;
+ if (fd == -1) return 0;
storage = "";
- part->printHeader(fd, bincClient, headers,
- includeHeaders, startOffset,
- length, storage);
+ part->printHeader(fd, bincClient, headers, includeHeaders, startOffset, length, storage);
return storage.size();
}
//------------------------------------------------------------------------
bool MaildirMessage::printBody(const std::string &section,
- unsigned int startOffset,
- unsigned int length) const
+ unsigned int startOffset,
+ unsigned int length) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
const MimePart *part = doc->getPart(section, "");
if (!part) {
@@ -839,8 +837,7 @@ bool MaildirMessage::printBody(const std::string &section,
}
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
storage = "";
part->printBody(fd, bincClient, startOffset, length);
@@ -849,11 +846,10 @@ bool MaildirMessage::printBody(const std::string &section,
//------------------------------------------------------------------------
unsigned int MaildirMessage::getBodySize(const std::string &section,
- unsigned int startOffset,
- unsigned int length) const
+ unsigned int startOffset,
+ unsigned int length) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
const MimePart *part = doc->getPart(section, "");
if (!part) {
@@ -861,26 +857,21 @@ unsigned int MaildirMessage::getBodySize(const std::string &section,
return 0;
}
- if (startOffset > part->bodylength)
- return 0;
-
+ if (startOffset > part->bodylength) return 0;
+
unsigned int s = part->bodylength - startOffset;
return s < length ? s : length;
}
//------------------------------------------------------------------------
-bool MaildirMessage::printDoc(unsigned int startOffset,
- unsigned int length, bool onlyText) const
+bool MaildirMessage::printDoc(unsigned int startOffset, unsigned int length, bool onlyText) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
- if (onlyText)
- startOffset += doc->bodystartoffsetcrlf;
+ if (onlyText) startOffset += doc->bodystartoffsetcrlf;
storage = "";
doc->printDoc(fd, bincClient, startOffset, length);
@@ -889,32 +880,27 @@ bool MaildirMessage::printDoc(unsigned int startOffset,
//------------------------------------------------------------------------
unsigned int MaildirMessage::getDocSize(unsigned int startOffset,
- unsigned int length,
- bool onlyText) const
+ unsigned int length,
+ bool onlyText) const
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
unsigned int s = doc->size;
if (onlyText) s -= doc->bodystartoffsetcrlf;
- if (startOffset > s)
- return 0;
+ if (startOffset > s) return 0;
s -= startOffset;
return s < length ? s : length;
}
//------------------------------------------------------------------------
-bool MaildirMessage::headerContains(const std::string &header,
- const std::string &text)
+bool MaildirMessage::headerContains(const std::string &header, const std::string &text)
{
- if (!parseHeaders())
- return false;
+ if (!parseHeaders()) return false;
HeaderItem hitem;
- if (!doc->h.getFirstHeader(header, hitem))
- return false;
+ if (!doc->h.getFirstHeader(header, hitem)) return false;
string tmp = hitem.getValue();
uppercase(tmp);
@@ -926,21 +912,18 @@ bool MaildirMessage::headerContains(const std::string &header,
//------------------------------------------------------------------------
bool MaildirMessage::bodyContains(const std::string &text)
{
- if (!parseFull())
- return false;
+ if (!parseFull()) return false;
// search the body part of the message..
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
MimeInputSource mimeSource(fd);
char c;
for (unsigned int i = 0; i < doc->getBodyStartOffset(); ++i)
- if (!mimeSource.getChar(&c))
- break;
-
+ if (!mimeSource.getChar(&c)) break;
+
char *ring = new char[text.length()];
int pos = 0;
int length = doc->getBodyLength();
@@ -948,15 +931,15 @@ bool MaildirMessage::bodyContains(const std::string &text)
unsigned int textLength = text.length();
while (mimeSource.getChar(&c) && length--) {
ring[pos % textLength] = toupper(c);
-
+
if (compareStringToQueue(textStr, ring, pos + 1, textLength)) {
delete[] ring;
return true;
}
-
+
++pos;
}
-
+
delete[] ring;
return false;
}
@@ -966,8 +949,7 @@ bool MaildirMessage::textContains(const std::string &text)
{
// search the body part of the message..
int fd = getFile();
- if (fd == -1)
- return false;
+ if (fd == -1) return false;
MimeInputSource mimeSource(fd);
@@ -978,15 +960,15 @@ bool MaildirMessage::textContains(const std::string &text)
unsigned int textLength = text.length();
while (mimeSource.getChar(&c)) {
ring[pos % textLength] = toupper(c);
-
+
if (compareStringToQueue(textStr, ring, pos + 1, textLength)) {
delete[] ring;
return true;
}
-
+
++pos;
}
-
+
delete[] ring;
return false;
}
@@ -996,20 +978,16 @@ const std::string &MaildirMessage::getHeader(const std::string &header)
{
static string NIL = "";
- if (!parseHeaders())
- return NIL;
+ if (!parseHeaders()) return NIL;
HeaderItem hitem;
- if (!doc->h.getFirstHeader(header, hitem))
- return NIL;
-
- return hitem.getValue();
+ if (!doc->h.getFirstHeader(header, hitem)) return NIL;
+
+ return hitem.getValue();
}
//------------------------------------------------------------------------
-MaildirMessageCache::MaildirMessageCache(void)
-{
-}
+MaildirMessageCache::MaildirMessageCache(void) {}
//------------------------------------------------------------------------
MaildirMessageCache::~MaildirMessageCache(void)
@@ -1025,8 +1003,7 @@ MaildirMessageCache &MaildirMessageCache::getInstance(void)
}
//------------------------------------------------------------------------
-void MaildirMessageCache::addStatus(const MaildirMessage *m,
- ParseStatus s)
+void MaildirMessageCache::addStatus(const MaildirMessage *m, ParseStatus s)
{
if (statuses.find(m) == statuses.end()) {
// Insert status. Perhaps remove oldest status.
@@ -1043,11 +1020,9 @@ void MaildirMessageCache::addStatus(const MaildirMessage *m,
}
//------------------------------------------------------------------------
-MaildirMessageCache::ParseStatus
-MaildirMessageCache::getStatus(const MaildirMessage *m) const
+MaildirMessageCache::ParseStatus MaildirMessageCache::getStatus(const MaildirMessage *m) const
{
- if (statuses.find(m) == statuses.end())
- return NotParsed;
+ if (statuses.find(m) == statuses.end()) return NotParsed;
return statuses[m];
}
@@ -1055,8 +1030,7 @@ MaildirMessageCache::getStatus(const MaildirMessage *m) const
//------------------------------------------------------------------------
void MaildirMessageCache::clear(void)
{
- for (deque<const MaildirMessage *>::iterator i = parsed.begin();
- i != parsed.end(); ++i)
+ for (deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i)
const_cast<MaildirMessage *>(*i)->close();
parsed.clear();
@@ -1066,13 +1040,11 @@ void MaildirMessageCache::clear(void)
//------------------------------------------------------------------------
void MaildirMessageCache::removeStatus(const MaildirMessage *m)
{
- if (statuses.find(m) == statuses.end())
- return;
+ if (statuses.find(m) == statuses.end()) return;
statuses.erase(statuses.find(m));
- for (deque<const MaildirMessage *>::iterator i = parsed.begin();
- i != parsed.end(); ++i) {
+ for (deque<const MaildirMessage *>::iterator i = parsed.begin(); i != parsed.end(); ++i) {
if (*i == m) {
const_cast<MaildirMessage *>(*i)->close();
parsed.erase(i);
@@ -1107,10 +1079,8 @@ void MaildirMessage::setCustomFlag(const string &flag)
customFlags = new vector<string>;
}
- for (vector<string>::const_iterator it = customFlags->begin();
- it != customFlags->end(); ++it) {
- if (*it == flag)
- return;
+ for (vector<string>::const_iterator it = customFlags->begin(); it != customFlags->end(); ++it) {
+ if (*it == flag) return;
}
internalFlags |= FlagsChanged | CustomFlagsChanged;
@@ -1122,11 +1092,9 @@ void MaildirMessage::removeCustomFlag(const string &flag)
{
internalFlags |= FlagsChanged | CustomFlagsChanged;
- if (!customFlags)
- return;
+ if (!customFlags) return;
- for (vector<string>::iterator it = customFlags->begin();
- it != customFlags->end(); ++it) {
+ for (vector<string>::iterator it = customFlags->begin(); it != customFlags->end(); ++it) {
if (*it == flag) {
customFlags->erase(it);
return;
@@ -1146,8 +1114,7 @@ void MaildirMessage::resetCustomFlags(void)
//------------------------------------------------------------------------
vector<string> MaildirMessage::getCustomFlags(void) const
{
- if (!customFlags)
- return vector<string>();
+ if (!customFlags) return vector<string>();
return *customFlags;
}
diff --git a/src/mime-getpart.cc b/src/mime-getpart.cc
index 7ce84fd..02a1ec5 100644
--- a/src/mime-getpart.cc
+++ b/src/mime-getpart.cc
@@ -4,27 +4,28 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "mime.h"
#include "convert.h"
-#include <string>
-#include <vector>
-#include <map>
+#include "mime.h"
+
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
//------------------------------------------------------------------------
const Binc::MimePart *Binc::MimePart::getPart(const string &findpart,
- string genpart, FetchType fetchType) const
+ string genpart,
+ FetchType fetchType) const
{
- if (findpart == genpart)
- return this;
+ if (findpart == genpart) return this;
if (isMultipart()) {
if (members.size() != 0) {
@@ -33,14 +34,12 @@ const Binc::MimePart *Binc::MimePart::getPart(const string &findpart,
while (i != members.end()) {
BincStream ss;
ss << genpart;
- if (genpart != "")
- ss << ".";
+ if (genpart != "") ss << ".";
ss << part;
const MimePart *m;
if ((m = (*i).getPart(findpart, ss.str())) != 0) {
- if (fetchType == FetchHeader && m->isMessageRFC822())
- m = &m->members[0];
+ if (fetchType == FetchHeader && m->isMessageRFC822()) m = &m->members[0];
return m;
}
@@ -57,12 +56,10 @@ const Binc::MimePart *Binc::MimePart::getPart(const string &findpart,
}
} else {
// Singlepart
- if (genpart != "")
- genpart += ".";
+ if (genpart != "") genpart += ".";
genpart += "1";
- if (findpart == genpart)
- return this;
+ if (findpart == genpart) return this;
}
return 0;
diff --git a/src/mime-parsefull.cc b/src/mime-parsefull.cc
index 53d07db..50d3157 100644
--- a/src/mime-parsefull.cc
+++ b/src/mime-parsefull.cc
@@ -4,20 +4,21 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "mime.h"
-#include "mime-utils.h"
-#include "mime-inputsource.h"
#include "convert.h"
-#include <string>
-#include <vector>
-#include <map>
+#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
+
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
Binc::MimeInputSource *mimeSource = 0;
@@ -26,8 +27,7 @@ using namespace ::std;
//------------------------------------------------------------------------
void Binc::MimeDocument::parseFull(int fd) const
{
- if (allIsParsed)
- return;
+ if (allIsParsed) return;
allIsParsed = true;
@@ -52,7 +52,8 @@ void Binc::MimeDocument::parseFull(int fd) const
// eat any trailing junk to get the correct size
char c;
- while (mimeSource->getChar(&c));
+ while (mimeSource->getChar(&c))
+ ;
size = mimeSource->getOffset();
}
@@ -72,7 +73,7 @@ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines)
// rewind back to the start of the line and assume we're at the
// start of the body.
if (c == '\r') {
- for (int i = 0; i < (int) name.length() + 1; ++i)
+ for (int i = 0; i < (int)name.length() + 1; ++i)
mimeSource->ungetChar();
return false;
}
@@ -112,8 +113,7 @@ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines)
// whitespace, then rewind one character and store the current
// key,value pair.
if (cqueue[2] == '\n' && c != ' ' && c != '\t') {
- if (content.length() > 2)
- content.resize(content.length() - 2);
+ if (content.length() > 2) content.resize(content.length() - 2);
trim(content);
header->add(name, content);
@@ -132,8 +132,7 @@ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines)
}
if (name != "") {
- if (content.length() > 2)
- content.resize(content.length() - 2);
+ if (content.length() > 2) content.resize(content.length() - 2);
header->add(name, content);
}
@@ -143,13 +142,16 @@ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines)
//------------------------------------------------------------------------
static void parseHeader(Binc::Header *header, unsigned int *nlines)
{
- while (parseOneHeaderLine(header, nlines))
- { }
+ while (parseOneHeaderLine(header, nlines)) {
+ }
}
//------------------------------------------------------------------------
-static void analyzeHeader(Binc::Header *header, bool *multipart,
- bool *messagerfc822, string *subtype, string *boundary)
+static void analyzeHeader(Binc::Header *header,
+ bool *multipart,
+ bool *messagerfc822,
+ string *subtype,
+ string *boundary)
{
using namespace ::Binc;
@@ -178,13 +180,11 @@ static void analyzeHeader(Binc::Header *header, bool *multipart,
*subtype = value;
} else if (key == "message") {
lowercase(value);
- if (value == "rfc822")
- *messagerfc822 = true;
+ if (value == "rfc822") *messagerfc822 = true;
}
}
- for (vector<string>::const_iterator i = types.begin();
- i != types.end(); ++i) {
+ for (vector<string>::const_iterator i = types.begin(); i != types.end(); ++i) {
string element = *i;
trim(element);
@@ -220,19 +220,18 @@ static void parseMessageRFC822(vector<Binc::MimePart> *members,
MimePart m;
unsigned int bodystartoffsetcrlf = mimeSource->getOffset();
-
+
// parsefull returns the number of bytes that need to be removed
// from the body because of the terminating boundary string.
int bsize = 0;
- if (m.parseFull(toboundary, bsize))
- *foundendofpart = true;
+ if (m.parseFull(toboundary, bsize)) *foundendofpart = true;
- // make sure bodylength doesn't overflow
+ // make sure bodylength doesn't overflow
*bodylength = mimeSource->getOffset();
if (*bodylength >= bodystartoffsetcrlf) {
*bodylength -= bodystartoffsetcrlf;
- if (*bodylength >= (unsigned int) bsize) {
- *bodylength -= (unsigned int) bsize;
+ if (*bodylength >= (unsigned int)bsize) {
+ *bodylength -= (unsigned int)bsize;
} else {
*bodylength = 0;
}
@@ -245,8 +244,7 @@ static void parseMessageRFC822(vector<Binc::MimePart> *members,
members->push_back(m);
}
-static bool skipUntilBoundary(const string &delimiter,
- unsigned int *nlines, bool *eof)
+static bool skipUntilBoundary(const string &delimiter, unsigned int *nlines, bool *eof)
{
int endpos = delimiter.length();
char *delimiterqueue = 0;
@@ -263,7 +261,7 @@ static bool skipUntilBoundary(const string &delimiter,
char c;
bool foundBoundary = false;
- for (;;) {
+ for (;;) {
if (!mimeSource->getChar(&c)) {
*eof = true;
break;
@@ -277,8 +275,7 @@ static bool skipUntilBoundary(const string &delimiter,
delimiterqueue[delimiterpos++ % endpos] = c;
- if (compareStringToQueue(delimiterStr, delimiterqueue,
- delimiterpos, endpos)) {
+ if (compareStringToQueue(delimiterStr, delimiterqueue, delimiterpos, endpos)) {
foundBoundary = true;
break;
}
@@ -290,7 +287,6 @@ static bool skipUntilBoundary(const string &delimiter,
return foundBoundary;
}
-
static void parseMultipart(const string &boundary,
const string &toboundary,
bool *eof,
@@ -319,7 +315,7 @@ static void parseMultipart(const string &boundary,
char a;
if (!mimeSource->getChar(&a)) *eof = true;
- if (a == '\n') ++*nlines;
+ if (a == '\n') ++*nlines;
char b;
if (!mimeSource->getChar(&b)) *eof = true;
@@ -333,7 +329,7 @@ static void parseMultipart(const string &boundary,
*boundarysize += 2;
if (!mimeSource->getChar(&a)) *eof = true;
- if (a == '\n') ++*nlines;
+ if (a == '\n') ++*nlines;
if (!mimeSource->getChar(&b)) *eof = true;
if (b == '\n') ++*nlines;
}
@@ -343,7 +339,7 @@ static void parseMultipart(const string &boundary,
// delimiter of one part is not followed by CRLF, but
// immediately followed by a CRLF prefixed delimiter.
if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b))
- *eof = true;
+ *eof = true;
else if (a == '-' && b == '-') {
mimeSource->ungetChar();
mimeSource->ungetChar();
@@ -397,7 +393,7 @@ static void parseMultipart(const string &boundary,
char a = '\0';
if (!mimeSource->getChar(&a)) *eof = true;
- if (a == '\n') ++*nlines;
+ if (a == '\n') ++*nlines;
char b = '\0';
if (!mimeSource->getChar(&b)) *eof = true;
@@ -409,22 +405,18 @@ static void parseMultipart(const string &boundary,
if (a == '-' && b == '-') {
*foundendofpart = true;
*boundarysize += 2;
- if (!mimeSource->getChar(&a))
- *eof = true;
- if (a == '\n')
- ++*nlines;
- if (!mimeSource->getChar(&b))
- *eof = true;
- if (b == '\n')
- ++*nlines;
+ if (!mimeSource->getChar(&a)) *eof = true;
+ if (a == '\n') ++*nlines;
+ if (!mimeSource->getChar(&b)) *eof = true;
+ if (b == '\n') ++*nlines;
}
if (a == '\r' && b == '\n') {
- // This exception is to handle a special case where the
- // delimiter of one part is not followed by CRLF, but
- // immediately followed by a CRLF prefixed delimiter.
+ // This exception is to handle a special case where the
+ // delimiter of one part is not followed by CRLF, but
+ // immediately followed by a CRLF prefixed delimiter.
if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b))
- *eof = true;
+ *eof = true;
else if (a == '-' && b == '-') {
mimeSource->ungetChar();
mimeSource->ungetChar();
@@ -443,12 +435,12 @@ static void parseMultipart(const string &boundary,
}
}
- // make sure bodylength doesn't overflow
+ // make sure bodylength doesn't overflow
*bodylength = mimeSource->getOffset();
if (*bodylength >= bodystartoffsetcrlf) {
*bodylength -= bodystartoffsetcrlf;
- if (*bodylength >= (unsigned int) *boundarysize) {
- *bodylength -= (unsigned int) *boundarysize;
+ if (*bodylength >= (unsigned int)*boundarysize) {
+ *bodylength -= (unsigned int)*boundarysize;
} else {
*bodylength = 0;
}
@@ -458,18 +450,19 @@ static void parseMultipart(const string &boundary,
}
static void parseSinglePart(const string &toboundary,
- int *boundarysize,
- unsigned int *nbodylines,
- unsigned int *nlines,
- bool *eof, bool *foundendofpart,
- unsigned int *bodylength)
+ int *boundarysize,
+ unsigned int *nbodylines,
+ unsigned int *nlines,
+ bool *eof,
+ bool *foundendofpart,
+ unsigned int *bodylength)
{
using namespace ::Binc;
unsigned int bodystartoffsetcrlf = mimeSource->getOffset();
// If toboundary is empty, then we read until the end of the
// file. Otherwise we will read until we encounter toboundary.
- string _toboundary;
+ string _toboundary;
if (toboundary != "") {
_toboundary = "\r\n--";
_toboundary += toboundary;
@@ -493,14 +486,16 @@ static void parseSinglePart(const string &toboundary,
bool toboundaryIsEmpty = (toboundary == "");
char c;
while (mimeSource->getChar(&c)) {
- if (c == '\n') { ++*nbodylines; ++*nlines; }
+ if (c == '\n') {
+ ++*nbodylines;
+ ++*nlines;
+ }
if (toboundaryIsEmpty) continue;
// find boundary
boundaryqueue[boundarypos++ % endpos] = c;
- if (compareStringToQueue(_toboundaryStr, boundaryqueue,
- boundarypos, endpos)) {
+ if (compareStringToQueue(_toboundaryStr, boundaryqueue, boundarypos, endpos)) {
*boundarysize = _toboundary.length();
break;
}
@@ -509,7 +504,6 @@ static void parseSinglePart(const string &toboundary,
delete[] boundaryqueue;
if (toboundary != "") {
-
char a;
if (!mimeSource->getChar(&a)) *eof = true;
if (a == '\n') ++*nlines;
@@ -532,12 +526,12 @@ static void parseSinglePart(const string &toboundary,
// delimiter of one part is not followed by CRLF, but
// immediately followed by a CRLF prefixed delimiter.
if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b))
- *eof = true;
+ *eof = true;
else if (a == '-' && b == '-') {
- mimeSource->ungetChar();
- mimeSource->ungetChar();
- mimeSource->ungetChar();
- mimeSource->ungetChar();
+ mimeSource->ungetChar();
+ mimeSource->ungetChar();
+ mimeSource->ungetChar();
+ mimeSource->ungetChar();
} else {
mimeSource->ungetChar();
mimeSource->ungetChar();
@@ -550,24 +544,22 @@ static void parseSinglePart(const string &toboundary,
}
}
- // make sure bodylength doesn't overflow
+ // make sure bodylength doesn't overflow
*bodylength = mimeSource->getOffset();
if (*bodylength >= bodystartoffsetcrlf) {
*bodylength -= bodystartoffsetcrlf;
- if (*bodylength >= (unsigned int) *boundarysize) {
- *bodylength -= (unsigned int) *boundarysize;
+ if (*bodylength >= (unsigned int)*boundarysize) {
+ *bodylength -= (unsigned int)*boundarysize;
} else {
*bodylength = 0;
}
} else {
*bodylength = 0;
}
-
}
//------------------------------------------------------------------------
-int Binc::MimePart::parseFull(const string &toboundary,
- int &boundarysize) const
+int Binc::MimePart::parseFull(const string &toboundary, int &boundarysize) const
{
headerstartoffsetcrlf = mimeSource->getOffset();
@@ -588,15 +580,19 @@ int Binc::MimePart::parseFull(const string &toboundary,
bool foundendofpart = false;
if (messagerfc822) {
- parseMessageRFC822(&members, &foundendofpart, &bodylength,
- &nbodylines, toboundary);
+ parseMessageRFC822(&members, &foundendofpart, &bodylength, &nbodylines, toboundary);
} else if (multipart) {
- parseMultipart(boundary, toboundary, &eof, &nlines, &boundarysize,
- &foundendofpart, &bodylength, &members);
+ parseMultipart(boundary,
+ toboundary,
+ &eof,
+ &nlines,
+ &boundarysize,
+ &foundendofpart,
+ &bodylength,
+ &members);
} else {
- parseSinglePart(toboundary, &boundarysize, &nbodylines, &nlines,
- &eof, &foundendofpart, &bodylength);
+ parseSinglePart(toboundary, &boundarysize, &nbodylines, &nlines, &eof, &foundendofpart, &bodylength);
}
return (eof || foundendofpart) ? 1 : 0;
diff --git a/src/mime-parseonlyheader.cc b/src/mime-parseonlyheader.cc
index d36efbf..5245aa5 100644
--- a/src/mime-parseonlyheader.cc
+++ b/src/mime-parseonlyheader.cc
@@ -4,28 +4,28 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "mime.h"
-#include "mime-utils.h"
-#include "mime-inputsource.h"
#include "convert.h"
-#include <string>
-#include <vector>
-#include <map>
+#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
+
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
//------------------------------------------------------------------------
void Binc::MimeDocument::parseOnlyHeader(int fd) const
{
- if (allIsParsed || headerIsParsed)
- return;
+ if (allIsParsed || headerIsParsed) return;
headerIsParsed = true;
@@ -75,7 +75,7 @@ int Binc::MimePart::parseOnlyHeader(const string &toboundary) const
if (c == ':') break;
if (c == '\n') {
for (int i = name.length() - 1; i >= 0; --i)
- mimeSource->ungetChar();
+ mimeSource->ungetChar();
quit = true;
name = "";
@@ -116,11 +116,10 @@ int Binc::MimePart::parseOnlyHeader(const string &toboundary) const
}
if (cqueue[2] == '\n') {
- // guess the mime rfc says what can not appear on the beginning
- // of a line.
- if (!isspace(cqueue[3])) {
- if (content.length() > 2)
- content.resize(content.length() - 2);
+ // guess the mime rfc says what can not appear on the beginning
+ // of a line.
+ if (!isspace(cqueue[3])) {
+ if (content.length() > 2) content.resize(content.length() - 2);
trim(content);
h.add(name, content);
@@ -135,8 +134,7 @@ int Binc::MimePart::parseOnlyHeader(const string &toboundary) const
}
if (name != "") {
- if (content.length() > 2)
- content.resize(content.length() - 2);
+ if (content.length() > 2) content.resize(content.length() - 2);
h.add(name, content);
}
diff --git a/src/mime-printbody.cc b/src/mime-printbody.cc
index 0c053d3..0c9e0b8 100644
--- a/src/mime-printbody.cc
+++ b/src/mime-printbody.cc
@@ -2,31 +2,31 @@
* @file mime-printbody.cc
* @brief Implementation of main mime parser components
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "mime.h"
-#include "mime-utils.h"
-#include "mime-inputsource.h"
-
#include "convert.h"
#include "iodevice.h"
#include "iofactory.h"
+#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
-#include <string>
-#include <vector>
-#include <map>
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
//------------------------------------------------------------------------
-void Binc::MimePart::printBody(int fd, IODevice &output,
+void Binc::MimePart::printBody(int fd,
+ IODevice &output,
unsigned int startoffset,
unsigned int length) const
{
@@ -38,13 +38,11 @@ void Binc::MimePart::printBody(int fd, IODevice &output,
mimeSource->reset();
mimeSource->seek(bodystartoffsetcrlf + startoffset);
- if (startoffset + length > bodylength)
- length = bodylength - startoffset;
+ if (startoffset + length > bodylength) length = bodylength - startoffset;
char c = '\0';
for (unsigned int i = 0; i < length; ++i) {
- if (!mimeSource->getChar(&c))
- break;
+ if (!mimeSource->getChar(&c)) break;
output << (char)c;
}
diff --git a/src/mime-printdoc.cc b/src/mime-printdoc.cc
index bef673b..37ec356 100644
--- a/src/mime-printdoc.cc
+++ b/src/mime-printdoc.cc
@@ -4,28 +4,29 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "mime.h"
-#include "mime-utils.h"
-#include "mime-inputsource.h"
#include "convert.h"
#include "iodevice.h"
#include "iofactory.h"
+#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
-#include <string>
-#include <vector>
-#include <map>
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
//------------------------------------------------------------------------
-void Binc::MimePart::printDoc(int fd, IODevice &output,
+void Binc::MimePart::printDoc(int fd,
+ IODevice &output,
unsigned int startoffset,
unsigned int length) const
{
@@ -39,8 +40,7 @@ void Binc::MimePart::printDoc(int fd, IODevice &output,
char c;
for (unsigned int i = 0; i < length; ++i) {
- if (!mimeSource->getChar(&c))
- break;
+ if (!mimeSource->getChar(&c)) break;
output << (char)c;
}
diff --git a/src/mime-printheader.cc b/src/mime-printheader.cc
index 84dca1e..9fb168e 100644
--- a/src/mime-printheader.cc
+++ b/src/mime-printheader.cc
@@ -4,31 +4,34 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "mime.h"
-#include "mime-utils.h"
-#include "mime-inputsource.h"
#include "convert.h"
#include "iodevice.h"
#include "iofactory.h"
+#include "mime-inputsource.h"
+#include "mime-utils.h"
+#include "mime.h"
-#include <string>
-#include <vector>
-#include <map>
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
//------------------------------------------------------------------------
-void Binc::MimePart::printHeader(int fd, IODevice &output,
- vector<string> headers, bool includeheaders,
+void Binc::MimePart::printHeader(int fd,
+ IODevice &output,
+ vector<string> headers,
+ bool includeheaders,
unsigned int startoffset,
- unsigned int length, string &store) const
+ unsigned int length,
+ string &store) const
{
if (!mimeSource || mimeSource->getFileDescriptor() != fd) {
delete mimeSource;
@@ -66,11 +69,11 @@ void Binc::MimePart::printHeader(int fd, IODevice &output,
// break if a '\n' turned up.
if (c == '\n') {
- // end of headers detected
+ // end of headers detected
if (name == "\r\n") {
- hasHeaderSeparator = true;
- quit = true;
- break;
+ hasHeaderSeparator = true;
+ quit = true;
+ break;
}
// put all data back in the buffer to the beginning of this
@@ -113,13 +116,12 @@ void Binc::MimePart::printHeader(int fd, IODevice &output,
trim(lowername, ": \t");
bool foundMatch = false;
- for (vector<string>::const_iterator i = headers.begin();
- i != headers.end(); ++i) {
+ for (vector<string>::const_iterator i = headers.begin(); i != headers.end(); ++i) {
string nametmp = *i;
lowercase(nametmp);
if (nametmp == lowername) {
foundMatch = true;
- break;
+ break;
}
}
@@ -149,8 +151,7 @@ void Binc::MimePart::printHeader(int fd, IODevice &output,
lowercase(lowername);
trim(lowername, ": \t");
bool foundMatch = false;
- for (vector<string>::const_iterator i = headers.begin();
- i != headers.end(); ++i) {
+ for (vector<string>::const_iterator i = headers.begin(); i != headers.end(); ++i) {
string nametmp = *i;
lowercase(nametmp);
if (nametmp == lowername) {
@@ -158,7 +159,7 @@ void Binc::MimePart::printHeader(int fd, IODevice &output,
break;
}
}
-
+
if (hasHeaderSeparator || foundMatch == includeheaders || headers.size() == 0) {
string out = name + content;
for (string::const_iterator i = out.begin(); i != out.end(); ++i)
diff --git a/src/mime.cc b/src/mime.cc
index 972d5e5..fa2e2ea 100644
--- a/src/mime.cc
+++ b/src/mime.cc
@@ -5,17 +5,19 @@
* @date 2002-2005
* ----------------------------------------------------------------- **/
#include "mime.h"
+
#include "convert.h"
-#include <string>
-#include <vector>
-#include <map>
+
#include <exception>
#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
-#include <string.h>
#include <ctype.h>
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
using namespace ::std;
@@ -27,9 +29,7 @@ Binc::MimeDocument::MimeDocument(void) : MimePart()
}
//------------------------------------------------------------------------
-Binc::MimeDocument::~MimeDocument(void)
-{
-}
+Binc::MimeDocument::~MimeDocument(void) {}
//------------------------------------------------------------------------
void Binc::MimeDocument::clear(void) const
@@ -59,14 +59,10 @@ Binc::MimePart::MimePart(void)
}
//------------------------------------------------------------------------
-Binc::MimePart::~MimePart(void)
-{
-}
+Binc::MimePart::~MimePart(void) {}
//------------------------------------------------------------------------
-Binc::HeaderItem::HeaderItem(void)
-{
-}
+Binc::HeaderItem::HeaderItem(void) {}
//------------------------------------------------------------------------
Binc::HeaderItem::HeaderItem(const string &key, const string &value)
@@ -76,14 +72,10 @@ Binc::HeaderItem::HeaderItem(const string &key, const string &value)
}
//------------------------------------------------------------------------
-Binc::Header::Header(void)
-{
-}
+Binc::Header::Header(void) {}
//------------------------------------------------------------------------
-Binc::Header::~Header(void)
-{
-}
+Binc::Header::~Header(void) {}
//------------------------------------------------------------------------
bool Binc::Header::getFirstHeader(const string &key, HeaderItem &dest) const
@@ -91,8 +83,7 @@ bool Binc::Header::getFirstHeader(const string &key, HeaderItem &dest) const
string k = key;
lowercase(k);
- for (vector<HeaderItem>::const_iterator i = content.begin();
- i != content.end(); ++i) {
+ for (vector<HeaderItem>::const_iterator i = content.begin(); i != content.end(); ++i) {
string tmp = (*i).getKey();
lowercase(tmp);
@@ -110,12 +101,10 @@ bool Binc::Header::getAllHeaders(const string &key, vector<HeaderItem> &dest) co
string k = key;
lowercase(k);
- for (vector<HeaderItem>::const_iterator i = content.begin();
- i != content.end(); ++i) {
+ for (vector<HeaderItem>::const_iterator i = content.begin(); i != content.end(); ++i) {
string tmp = (*i).getKey();
lowercase(tmp);
- if (tmp == k)
- dest.push_back(*i);
+ if (tmp == k) dest.push_back(*i);
}
return (dest.size() != 0);
diff --git a/src/multilogdevice.cc b/src/multilogdevice.cc
index 612bb33..7452432 100644
--- a/src/multilogdevice.cc
+++ b/src/multilogdevice.cc
@@ -5,26 +5,24 @@
* @date 2003/2023
* --------------------------------------------------------------- **/
#include "multilogdevice.h"
+
#include <string>
-#include <sys/types.h>
+#include <errno.h>
+
#include <sys/select.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
using namespace ::std;
using namespace ::Binc;
//------------------------------------------------------------------------
-MultilogDevice::MultilogDevice(int f) : IODevice(f)
-{
-}
+MultilogDevice::MultilogDevice(int f) : IODevice(f) {}
//------------------------------------------------------------------------
-MultilogDevice::~MultilogDevice(void)
-{
-}
+MultilogDevice::~MultilogDevice(void) {}
//------------------------------------------------------------------------
string MultilogDevice::service(void) const
@@ -43,8 +41,7 @@ bool MultilogDevice::waitForWrite(void) const
tv.tv_sec = getTimeout();
tv.tv_usec = 0;
- int result = select(fileno(stderr) + 1, 0, &writeMask,
- 0, tv.tv_sec ? &tv : 0);
+ int result = select(fileno(stderr) + 1, 0, &writeMask, 0, tv.tv_sec ? &tv : 0);
return result > 0;
}
@@ -59,17 +56,16 @@ bool MultilogDevice::waitForRead(void) const
IODevice::WriteResult MultilogDevice::write(void)
{
for (;;) {
- ssize_t wrote = ::write(fileno(stderr), outputBuffer.str().c_str(),
- outputBuffer.getSize());
+ ssize_t wrote = ::write(fileno(stderr), outputBuffer.str().c_str(), outputBuffer.getSize());
if (wrote == -1) {
- if (errno == EINTR)
+ if (errno == EINTR)
continue;
else
return WriteError;
}
- if ((unsigned int) wrote == outputBuffer.getSize()) {
+ if ((unsigned int)wrote == outputBuffer.getSize()) {
outputBuffer.clear();
return WriteDone;
}
diff --git a/src/operator-append.cc b/src/operator-append.cc
index d4650ee..f4eaaa9 100644
--- a/src/operator-append.cc
+++ b/src/operator-append.cc
@@ -2,34 +2,30 @@
* @file operator-append.cc
* @brief Implementation of the APPEND command.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <algorithm>
-#include <string>
-
-#include <fcntl.h>
-
#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
#include "mailbox.h"
#include "operators.h"
-#include "recursivedescent.h"
#include "pendingupdates.h"
+#include "recursivedescent.h"
#include "session.h"
+#include <algorithm>
+#include <string>
+
+#include <fcntl.h>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-AppendOperator::AppendOperator(void)
-{
-}
+AppendOperator::AppendOperator(void) {}
//----------------------------------------------------------------------
-AppendOperator::~AppendOperator(void)
-{
-}
+AppendOperator::~AppendOperator(void) {}
//----------------------------------------------------------------------
const string AppendOperator::getName(void) const
@@ -44,8 +40,7 @@ int AppendOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult AppendOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult AppendOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -55,13 +50,12 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
if ((mailbox = depot.get(canonmailbox)) == 0) {
session.setResponseCode("TRYCREATE");
- session.setLastError("invalid destination mailbox "
- + toImapString(srcmailbox));
+ session.setLastError("invalid destination mailbox " + toImapString(srcmailbox));
return NO;
}
// mask all passed flags together
- unsigned int newflags = (unsigned int) Message::F_NONE;
+ unsigned int newflags = (unsigned int)Message::F_NONE;
vector<string>::const_iterator f_i = command.flags.begin();
while (f_i != command.flags.end()) {
if (*f_i == "\\Deleted") newflags |= Message::F_DELETED;
@@ -71,14 +65,20 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
if (*f_i == "\\Flagged") newflags |= Message::F_FLAGGED;
++f_i;
}
-
+
int mday, year, hour, minute, second;
char month[4];
struct tm mytm;
- if (command.getDate() != "") {
- sscanf(command.getDate().c_str(), "%2i-%3s-%4i %2i:%2i:%2i",
- &mday, month, &year, &hour, &minute, &second);
+ if (command.getDate() != "") {
+ sscanf(command.getDate().c_str(),
+ "%2i-%3s-%4i %2i:%2i:%2i",
+ &mday,
+ month,
+ &year,
+ &hour,
+ &minute,
+ &second);
month[3] = '\0';
string monthstr = month;
@@ -88,18 +88,30 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
mytm.tm_hour = hour;
mytm.tm_year = year - 1900;
mytm.tm_mday = mday;
- if (monthstr == "jan") mytm.tm_mon = 0;
- else if (monthstr == "feb") mytm.tm_mon = 1;
- else if (monthstr == "mar") mytm.tm_mon = 2;
- else if (monthstr == "apr") mytm.tm_mon = 3;
- else if (monthstr == "may") mytm.tm_mon = 4;
- else if (monthstr == "jun") mytm.tm_mon = 5;
- else if (monthstr == "jul") mytm.tm_mon = 6;
- else if (monthstr == "aug") mytm.tm_mon = 7;
- else if (monthstr == "sep") mytm.tm_mon = 8;
- else if (monthstr == "oct") mytm.tm_mon = 9;
- else if (monthstr == "nov") mytm.tm_mon = 10;
- else if (monthstr == "dec") mytm.tm_mon = 11;
+ if (monthstr == "jan")
+ mytm.tm_mon = 0;
+ else if (monthstr == "feb")
+ mytm.tm_mon = 1;
+ else if (monthstr == "mar")
+ mytm.tm_mon = 2;
+ else if (monthstr == "apr")
+ mytm.tm_mon = 3;
+ else if (monthstr == "may")
+ mytm.tm_mon = 4;
+ else if (monthstr == "jun")
+ mytm.tm_mon = 5;
+ else if (monthstr == "jul")
+ mytm.tm_mon = 6;
+ else if (monthstr == "aug")
+ mytm.tm_mon = 7;
+ else if (monthstr == "sep")
+ mytm.tm_mon = 8;
+ else if (monthstr == "oct")
+ mytm.tm_mon = 9;
+ else if (monthstr == "nov")
+ mytm.tm_mon = 10;
+ else if (monthstr == "dec")
+ mytm.tm_mon = 11;
mytm.tm_isdst = -1;
}
@@ -111,7 +123,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
session.setLastError("expected literal");
return BAD;
}
-
+
string nr;
bool literalPlus = false;
while (1) {
@@ -138,7 +150,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
return BAD;
}
- nr += (char) c;
+ nr += (char)c;
}
int nchars = atoi(nr.c_str());
@@ -163,8 +175,7 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
time_t newtime = (command.getDate() != "") ? mktime(&mytm) : time(0);
if (newtime == -1) newtime = time(0);
- Message *dest = mailbox->createMessage(depot.mailboxToFilename(canonmailbox),
- newtime);
+ Message *dest = mailbox->createMessage(depot.mailboxToFilename(canonmailbox), newtime);
if (!dest) {
session.setLastError(mailbox->getLastError());
return NO;
@@ -222,15 +233,16 @@ Operator::ProcessResult AppendOperator::process(Depot &depot,
dest->setInternalDate(mktime(&mytm));
if (!mailbox->commitNewMessages(depot.mailboxToFilename(canonmailbox))) {
- session.setLastError("failed to commit after successful APPEND: "
- + mailbox->getLastError());
+ session.setLastError("failed to commit after successful APPEND: " + mailbox->getLastError());
return NO;
}
if (mailbox == depot.getSelected()) {
- pendingUpdates(mailbox, PendingUpdates::EXISTS
- | PendingUpdates::RECENT
- | PendingUpdates::FLAGS, true, false, true);
+ pendingUpdates(mailbox,
+ PendingUpdates::EXISTS | PendingUpdates::RECENT | PendingUpdates::FLAGS,
+ true,
+ false,
+ true);
}
return OK;
@@ -242,8 +254,7 @@ Operator::ParseResult AppendOperator::parse(Request &c_in) const
Session &session = Session::getInstance();
Operator::ParseResult res;
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after APPEND");
diff --git a/src/operator-authenticate.cc b/src/operator-authenticate.cc
index 03f994c..7802c47 100644
--- a/src/operator-authenticate.cc
+++ b/src/operator-authenticate.cc
@@ -4,32 +4,28 @@
* @author Andreas Aardal Hanssen, Erwin Hoffmann
* @date 2002-2005, 2023
* ----------------------------------------------------------------- **/
-#include <string>
-
#include "authenticate.h"
#include "base64.h"
#include "convert.h"
#include "depot.h"
+#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "globals.h"
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
+
#include <cstring>
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-AuthenticateOperator::AuthenticateOperator(void)
-{
-}
+AuthenticateOperator::AuthenticateOperator(void) {}
//----------------------------------------------------------------------
-AuthenticateOperator::~AuthenticateOperator(void)
-{
-}
+AuthenticateOperator::~AuthenticateOperator(void) {}
//----------------------------------------------------------------------
const string AuthenticateOperator::getName(void) const
@@ -44,7 +40,7 @@ int AuthenticateOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult AuthenticateOperator::Login(string& username, string& password)
+Operator::ProcessResult AuthenticateOperator::Login(string &username, string &password)
{
Session &session = Session::getInstance();
@@ -71,7 +67,7 @@ Operator::ProcessResult AuthenticateOperator::Login(string& username, string& pa
bincClient << "+ " << base64encode("Password") << endl;
bincClient.flush();
- // Read password
+ // Read password
string b64pwd;
for (;;) {
char c;
@@ -87,14 +83,15 @@ Operator::ProcessResult AuthenticateOperator::Login(string& username, string& pa
session.setLastError("Authentication cancelled by user");
return NO;
}
-
+
username = base64decode(b64usr);
password = base64decode(b64pwd);
return OK;
}
+
//------------------------------------------------------------------------
-Operator::ProcessResult AuthenticateOperator::Plain(string& username, string& password)
+Operator::ProcessResult AuthenticateOperator::Plain(string &username, string &password)
{
Session &session = Session::getInstance();
@@ -122,17 +119,17 @@ Operator::ProcessResult AuthenticateOperator::Plain(string& username, string& pa
string::size_type pos = 0;
if ((pos = plain.find('\0')) == string::npos) {
- session.setLastError("Authentication failed. In PLAIN mode, "
- "there must be at least two null characters "
- "in the input string, but none were found");
+ session.setLastError("Authentication failed. In PLAIN mode, "
+ "there must be at least two null characters "
+ "in the input string, but none were found");
return NO;
}
plain = plain.substr(pos + 1);
if ((pos = plain.find('\0')) == string::npos) {
- session.setLastError("Authentication failed. In PLAIN mode, "
- "there must be at least two null characters "
- "in the input string, but only one was found");
+ session.setLastError("Authentication failed. In PLAIN mode, "
+ "there must be at least two null characters "
+ "in the input string, but only one was found");
return NO;
}
@@ -141,9 +138,9 @@ Operator::ProcessResult AuthenticateOperator::Plain(string& username, string& pa
return OK;
}
+
//------------------------------------------------------------------------
-Operator::ProcessResult AuthenticateOperator::Cram(string& username, string& password,
- string& challenge)
+Operator::ProcessResult AuthenticateOperator::Cram(string &username, string &password, string &challenge)
{
Session &session = Session::getInstance();
@@ -151,11 +148,15 @@ Operator::ProcessResult AuthenticateOperator::Cram(string& username, string& pas
time_t timer;
struct tm y2k = {0};
int timestamp;
- y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0;
- y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
+ y2k.tm_hour = 0;
+ y2k.tm_min = 0;
+ y2k.tm_sec = 0;
+ y2k.tm_year = 100;
+ y2k.tm_mon = 0;
+ y2k.tm_mday = 1;
- time(&timer); /* get current time; same as: timer = time(NULL) */
- timestamp = difftime(timer,mktime(&y2k));
+ time(&timer); /* get current time; same as: timer = time(NULL) */
+ timestamp = difftime(timer, mktime(&y2k));
challenge += "<";
challenge += to_string(session.getPid());
@@ -171,7 +172,7 @@ Operator::ProcessResult AuthenticateOperator::Cram(string& username, string& pas
// Read response
string b64;
for (;;) {
- char c;
+ char c;
if (!bincClient.readChar(&c)) return BAD;
if (c == '\n') break;
b64 += c;
@@ -183,8 +184,8 @@ Operator::ProcessResult AuthenticateOperator::Cram(string& username, string& pas
if ((pos = response.find(' ')) == string::npos) {
session.setLastError("Authentication failed. In CRAM-MD5 mode, "
- "there must be a white space in the "
- "input string between username and digest");
+ "there must be a white space in the "
+ "input string between username and digest");
return NO;
}
@@ -193,9 +194,9 @@ Operator::ProcessResult AuthenticateOperator::Cram(string& username, string& pas
return OK;
}
+
//------------------------------------------------------------------------
-Operator::ProcessResult AuthenticateOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult AuthenticateOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -204,14 +205,13 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot,
string username;
string password;
- string challenge;
+ string challenge;
ProcessResult r = NOTHING;
if (authtype == "LOGIN") {
- // we only allow this type of authentication over an unencryted connection
+ // we only allow this type of authentication over an unencryted connection
// if it is explicitely commanded
- if (!session.command.ssl
- && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
+ if (!session.command.ssl && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
session.setLastError("Plain text password authentication is disallowd. "
"Please enable StartTLS or TLS in your mail client.");
return NO;
@@ -220,25 +220,24 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot,
} else if (authtype == "PLAIN") {
// we only allow this type of authentication over an TLS encrypted connection.
- if (!session.command.ssl
- && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
+ if (!session.command.ssl && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
session.setLastError("Plain text password authentication is disallowd. "
"Please enable StartTLS or TLS in your mail client.");
return NO;
}
if ((r = Plain(username, password)) != OK) return r;
- } else if (authtype == "CRAM-MD5" ) {
+ } else if (authtype == "CRAM-MD5") {
// this type can be used even over unencrypted connections
if ((r = Cram(username, password, challenge)) != OK) return r;
- } else { // Any other disallowed
- session.setLastError("The authentication method "
- + toImapString(authtype) + " is not supported. "
- "Please try again with a different method. "
- "There is built in support for \"PLAIN\" "
- "and \"LOGIN\".");
+ } else { // Any other disallowed
+ session.setLastError("The authentication method " + toImapString(authtype)
+ + " is not supported. "
+ "Please try again with a different method. "
+ "There is built in support for \"PLAIN\" "
+ "and \"LOGIN\".");
return NO;
}
@@ -253,28 +252,28 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot,
// error) or 2 (failed)
switch (authenticate(depot, username, password, challenge)) {
- case 1:
- session.setLastError("An internal error occurred when you attempted "
- "to log in to the IMAP server. Please contact "
- "your system administrator.");
- return NO;
- case 2:
- session.setLastError("Login failed. Either your user name "
- "or your password was wrong. Please try again, "
- "and if the problem persists, please contact "
- "your system administrator.");
- return NO;
- case 3:
- bincClient << "* BYE Timeout after " << IDLE_TIMEOUT
- << " seconds of inactivity." << endl;
- break;
- case -1:
- bincClient << "* BYE The server died unexpectedly. Please contact "
- "your system administrator for more information." << endl;
- break;
- default:
-// bincLog << "<" << username.c_str() << "> authenticated" << endl;
- break;
+ case 1:
+ session.setLastError("An internal error occurred when you attempted "
+ "to log in to the IMAP server. Please contact "
+ "your system administrator.");
+ return NO;
+ case 2:
+ session.setLastError("Login failed. Either your user name "
+ "or your password was wrong. Please try again, "
+ "and if the problem persists, please contact "
+ "your system administrator.");
+ return NO;
+ case 3:
+ bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << endl;
+ break;
+ case -1:
+ bincClient << "* BYE The server died unexpectedly. Please contact "
+ "your system administrator for more information."
+ << endl;
+ break;
+ default:
+ // bincLog << "<" << username.c_str() << "> authenticated" << endl;
+ break;
}
// auth was ok. go to logout state
@@ -282,7 +281,6 @@ Operator::ProcessResult AuthenticateOperator::process(Depot &depot,
return NOTHING;
}
-
//----------------------------------------------------------------------
Operator::ParseResult AuthenticateOperator::parse(Request &c_in) const
{
diff --git a/src/operator-capability.cc b/src/operator-capability.cc
index bdead58..73f5a26 100644
--- a/src/operator-capability.cc
+++ b/src/operator-capability.cc
@@ -4,28 +4,24 @@
* @author Andreas Aardal Hanssen, Erwin Hoffmann
* @date 2002-2005, 2023
* ----------------------------------------------------------------- **/
-#include <string>
-
#include "depot.h"
+#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
-#include "globals.h"
+
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-CapabilityOperator::CapabilityOperator(void)
-{
-}
+CapabilityOperator::CapabilityOperator(void) {}
//----------------------------------------------------------------------
-CapabilityOperator::~CapabilityOperator(void)
-{
-}
+CapabilityOperator::~CapabilityOperator(void) {}
//----------------------------------------------------------------------
const string CapabilityOperator::getName(void) const
@@ -36,9 +32,7 @@ const string CapabilityOperator::getName(void) const
//----------------------------------------------------------------------
int CapabilityOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//----------------------------------------------------------------------
@@ -48,23 +42,24 @@ void CapabilityOperator::addCapability(const string &cap)
}
//----------------------------------------------------------------------
-Operator::ProcessResult CapabilityOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult CapabilityOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
- bincClient << "* CAPABILITY " << IMAP_VERSION ;
+ bincClient << "* CAPABILITY " << IMAP_VERSION;
if (session.getState() == Session::NONAUTHENTICATED) {
- if (getenv("UCSPITLS"))
+ if (getenv("UCSPITLS"))
if (!session.command.ssl) bincClient << " STARTTLS";
- const string authmethods = session.getEnv("BINCIMAP_LOGIN");
- auto cram = authmethods.find("+CRAM-MD5");
+ const string authmethods = session.getEnv("BINCIMAP_LOGIN");
+ auto cram = authmethods.find("+CRAM-MD5");
if (session.command.ssl || session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
- if (cram != string::npos) bincClient << " AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5";
- else bincClient << " AUTH=LOGIN AUTH=PLAIN";
+ if (cram != string::npos)
+ bincClient << " AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5";
+ else
+ bincClient << " AUTH=LOGIN AUTH=PLAIN";
} else
bincClient << " LOGINDISABLED";
}
diff --git a/src/operator-check.cc b/src/operator-check.cc
index ee58d8f..045f8b0 100644
--- a/src/operator-check.cc
+++ b/src/operator-check.cc
@@ -2,30 +2,25 @@
* @file operator-check.cc
* @author Implementation of the CHECK command.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
#include "depot.h"
#include "mailbox.h"
#include "operators.h"
-#include "recursivedescent.h"
#include "pendingupdates.h"
+#include "recursivedescent.h"
#include "session.h"
+#include <string>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-CheckOperator::CheckOperator(void)
-{
-}
-
+CheckOperator::CheckOperator(void) {}
//----------------------------------------------------------------------
-CheckOperator::~CheckOperator(void)
-{
-}
+CheckOperator::~CheckOperator(void) {}
//----------------------------------------------------------------------
const string CheckOperator::getName(void) const
@@ -40,14 +35,13 @@ int CheckOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult CheckOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult CheckOperator::process(Depot &depot, Request &command)
{
Mailbox *mailbox = depot.getSelected();
if (mailbox != 0)
- pendingUpdates(mailbox, PendingUpdates::FLAGS
- | PendingUpdates::EXISTS
- | PendingUpdates::RECENT, true);
+ pendingUpdates(mailbox,
+ PendingUpdates::FLAGS | PendingUpdates::EXISTS | PendingUpdates::RECENT,
+ true);
return OK;
}
@@ -68,4 +62,3 @@ Operator::ParseResult CheckOperator::parse(Request &c_in) const
c_in.setName("CHECK");
return ACCEPT;
}
-
diff --git a/src/operator-close.cc b/src/operator-close.cc
index d67dcc7..686f668 100644
--- a/src/operator-close.cc
+++ b/src/operator-close.cc
@@ -4,26 +4,22 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
#include "depot.h"
#include "mailbox.h"
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
+#include <string>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-CloseOperator::CloseOperator(void)
-{
-}
+CloseOperator::CloseOperator(void) {}
//----------------------------------------------------------------------
-CloseOperator::~CloseOperator(void)
-{
-}
+CloseOperator::~CloseOperator(void) {}
//------------------------------------------------------------------------
const string CloseOperator::getName(void) const
@@ -38,8 +34,7 @@ int CloseOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult CloseOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult CloseOperator::process(Depot &depot, Request &command)
{
Mailbox *mailbox = depot.getSelected();
mailbox->expungeMailbox();
@@ -57,8 +52,7 @@ Operator::ParseResult CloseOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectCRLF()) != ACCEPT) {
diff --git a/src/operator-copy.cc b/src/operator-copy.cc
index cbe8767..50afe77 100644
--- a/src/operator-copy.cc
+++ b/src/operator-copy.cc
@@ -4,8 +4,7 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
+#include "convert.h"
#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
@@ -13,20 +12,17 @@
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
-#include "convert.h"
+
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-CopyOperator::CopyOperator(void)
-{
-}
+CopyOperator::CopyOperator(void) {}
//----------------------------------------------------------------------
-CopyOperator::~CopyOperator(void)
-{
-}
+CopyOperator::~CopyOperator(void) {}
//----------------------------------------------------------------------
const string CopyOperator::getName(void) const
@@ -41,8 +37,7 @@ int CopyOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult CopyOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult CopyOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -67,14 +62,12 @@ Operator::ProcessResult CopyOperator::process(Depot &depot,
for (; success && i != srcMailbox->end(); ++i) {
Message &source = *i;
- if (srcMailbox->fastCopy(source, *destMailbox,
- depot.mailboxToFilename(toCanonMailbox(dmailbox))))
+ if (srcMailbox->fastCopy(source, *destMailbox, depot.mailboxToFilename(toCanonMailbox(dmailbox))))
continue;
// Have the destination mailbox create a message for us.
- Message *dest
- = destMailbox->createMessage(depot.mailboxToFilename(toCanonMailbox(dmailbox)),
- source.getInternalDate());
+ Message *dest = destMailbox->createMessage(depot.mailboxToFilename(toCanonMailbox(dmailbox)),
+ source.getInternalDate());
if (!dest) {
session.setLastError(destMailbox->getLastError());
success = false;
@@ -91,18 +84,15 @@ Operator::ProcessResult CopyOperator::process(Depot &depot,
do {
int readSize = source.readChunk(chunk);
- if (readSize == 0) break;
+ if (readSize == 0)
+ break;
else if (readSize == -1) {
- bincWarning << "when reading from message "
- << i.getSqnr() << "/" << source.getUID()
- << " in \"" << srcMailbox->getName() << "\": "
- << source.getLastError() << endl;
+ bincWarning << "when reading from message " << i.getSqnr() << "/" << source.getUID() << " in \""
+ << srcMailbox->getName() << "\": " << source.getLastError() << endl;
success = false;
} else if (!dest->appendChunk(chunk)) {
- bincWarning << "when writing to \""
- << dmailbox << "\": "
- << dest->getLastError() << endl;
- success = false;
+ bincWarning << "when writing to \"" << dmailbox << "\": " << dest->getLastError() << endl;
+ success = false;
}
} while (success);
@@ -110,16 +100,14 @@ Operator::ProcessResult CopyOperator::process(Depot &depot,
}
if (!success && !destMailbox->rollBackNewMessages()) {
- session.setLastError("Failed to rollback after unsuccessful copy: "
- + destMailbox->getLastError());
+ session.setLastError("Failed to rollback after unsuccessful copy: " + destMailbox->getLastError());
return NO;
}
if (success)
if (!destMailbox->commitNewMessages(depot.mailboxToFilename(toCanonMailbox(dmailbox)))) {
- session.setLastError("Failed to commit after successful copy: "
- + destMailbox->getLastError());
- return NO;
+ session.setLastError("Failed to commit after successful copy: " + destMailbox->getLastError());
+ return NO;
}
if (!success)
diff --git a/src/operator-create.cc b/src/operator-create.cc
index 409b73f..83c5e1d 100644
--- a/src/operator-create.cc
+++ b/src/operator-create.cc
@@ -2,30 +2,26 @@
* @file bincimapd-create.cc
* @brief Implementation of the CREATE command.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
+#include "convert.h"
#include "depot.h"
+#include "imapparser.h"
#include "mailbox.h"
#include "operators.h"
-#include "imapparser.h"
#include "recursivedescent.h"
#include "session.h"
-#include "convert.h"
+
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-CreateOperator::CreateOperator(void)
-{
-}
+CreateOperator::CreateOperator(void) {}
//----------------------------------------------------------------------
-CreateOperator::~CreateOperator(void)
-{
-}
+CreateOperator::~CreateOperator(void) {}
//----------------------------------------------------------------------
const string CreateOperator::getName(void) const
@@ -40,8 +36,7 @@ int CreateOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult CreateOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult CreateOperator::process(Depot &depot, Request &command)
{
if (depot.createMailbox(command.getMailbox()))
return OK;
diff --git a/src/operator-delete.cc b/src/operator-delete.cc
index 0365927..350e572 100644
--- a/src/operator-delete.cc
+++ b/src/operator-delete.cc
@@ -2,30 +2,26 @@
* @file operator-delete.cc
* @briefe Implementation of the DELETE command.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
+#include "convert.h"
#include "depot.h"
+#include "imapparser.h"
#include "mailbox.h"
#include "operators.h"
-#include "imapparser.h"
#include "recursivedescent.h"
#include "session.h"
-#include "convert.h"
+
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-DeleteOperator::DeleteOperator(void)
-{
-}
+DeleteOperator::DeleteOperator(void) {}
//----------------------------------------------------------------------
-DeleteOperator::~DeleteOperator(void)
-{
-}
+DeleteOperator::~DeleteOperator(void) {}
//----------------------------------------------------------------------
const string DeleteOperator::getName(void) const
@@ -40,8 +36,7 @@ int DeleteOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult DeleteOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult DeleteOperator::process(Depot &depot, Request &command)
{
if (depot.deleteMailbox(command.getMailbox()))
return OK;
@@ -75,9 +70,9 @@ Operator::ParseResult DeleteOperator::parse(Request &c_in) const
session.setLastError("Expected CRLF after DELETE SPACE mailbox");
return res;
}
-
+
session.mailboxchanges = true;
-
+
c_in.setName("DELETE");
c_in.setMailbox(mailbox);
return ACCEPT;
diff --git a/src/operator-examine.cc b/src/operator-examine.cc
index 314641c..9f64ce6 100644
--- a/src/operator-examine.cc
+++ b/src/operator-examine.cc
@@ -16,11 +16,7 @@ const std::string ExamineOperator::getName(void) const
}
//----------------------------------------------------------------------
-ExamineOperator::ExamineOperator(void)
-{
-}
+ExamineOperator::ExamineOperator(void) {}
//----------------------------------------------------------------------
-ExamineOperator::~ExamineOperator(void)
-{
-}
+ExamineOperator::~ExamineOperator(void) {}
diff --git a/src/operator-expunge.cc b/src/operator-expunge.cc
index 24904d5..03fd655 100644
--- a/src/operator-expunge.cc
+++ b/src/operator-expunge.cc
@@ -2,30 +2,26 @@
* @file operator-expunge.cc
* @brief Implementation of the EXPUNGE command
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
#include "depot.h"
+#include "imapparser.h"
#include "mailbox.h"
#include "operators.h"
-#include "imapparser.h"
-#include "recursivedescent.h"
#include "pendingupdates.h"
+#include "recursivedescent.h"
#include "session.h"
+#include <string>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-ExpungeOperator::ExpungeOperator(void)
-{
-}
+ExpungeOperator::ExpungeOperator(void) {}
//----------------------------------------------------------------------
-ExpungeOperator::~ExpungeOperator(void)
-{
-}
+ExpungeOperator::~ExpungeOperator(void) {}
//----------------------------------------------------------------------
const string ExpungeOperator::getName(void) const
@@ -40,16 +36,15 @@ int ExpungeOperator::getState(void) const
}
//----------------------------------------------------------------------
-Operator::ProcessResult ExpungeOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult ExpungeOperator::process(Depot &depot, Request &command)
{
Mailbox *mailbox = depot.getSelected();
mailbox->expungeMailbox();
- pendingUpdates(mailbox, PendingUpdates::EXPUNGE
- | PendingUpdates::EXISTS
- | PendingUpdates::RECENT
- | PendingUpdates::FLAGS, true);
+ pendingUpdates(mailbox,
+ PendingUpdates::EXPUNGE | PendingUpdates::EXISTS | PendingUpdates::RECENT
+ | PendingUpdates::FLAGS,
+ true);
return OK;
}
@@ -59,11 +54,10 @@ Operator::ParseResult ExpungeOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
- Operator::ParseResult res;
- if ((res = expectCRLF()) != ACCEPT) {
+ Operator::ParseResult res;
+ if ((res = expectCRLF()) != ACCEPT) {
session.setLastError("Expected CRLF");
return res;
}
diff --git a/src/operator-fetch.cc b/src/operator-fetch.cc
index 810afb5..8b33d79 100644
--- a/src/operator-fetch.cc
+++ b/src/operator-fetch.cc
@@ -4,24 +4,24 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
+#include "convert.h"
#include "depot.h"
+#include "imapparser.h"
#include "iodevice.h"
#include "iofactory.h"
#include "mailbox.h"
#include "operators.h"
-#include "imapparser.h"
#include "pendingupdates.h"
#include "recursivedescent.h"
#include "session.h"
-#include "convert.h"
+
+#include <string>
using namespace ::std;
using namespace Binc;
namespace {
- void outputFlags(const Message & message)
+ void outputFlags(const Message &message)
{
bincClient << "FLAGS ";
@@ -35,15 +35,13 @@ namespace {
if (flags & Message::F_RECENT) flagv.push_back("\\Recent");
if (flags & Message::F_FLAGGED) flagv.push_back("\\Flagged");
- for (vector<string>::const_iterator k
- = flagv.begin(); k != flagv.end(); ++k) {
+ for (vector<string>::const_iterator k = flagv.begin(); k != flagv.end(); ++k) {
if (k != flagv.begin()) bincClient << " ";
bincClient << *k;
}
vector<string> customFlags = message.getCustomFlags();
- for (vector<string>::const_iterator it = customFlags.begin();
- it != customFlags.end(); ++it) {
+ for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) {
if (flagv.size() > 0 || it != customFlags.begin()) bincClient << " ";
bincClient << *it;
}
@@ -54,14 +52,10 @@ namespace {
}
//----------------------------------------------------------------------
-FetchOperator::FetchOperator(void)
-{
-}
+FetchOperator::FetchOperator(void) {}
//----------------------------------------------------------------------
-FetchOperator::~FetchOperator(void)
-{
-}
+FetchOperator::~FetchOperator(void) {}
//----------------------------------------------------------------------
const string FetchOperator::getName(void) const
@@ -76,8 +70,7 @@ int FetchOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult FetchOperator::process(Depot &depot,
- Request &request)
+Operator::ProcessResult FetchOperator::process(Depot &depot, Request &request)
{
Session &session = Session::getInstance();
@@ -137,8 +130,7 @@ Operator::ProcessResult FetchOperator::process(Depot &depot,
else
mode = Mailbox::SQNR_MODE;
- Mailbox::iterator i
- = mailbox->begin(req.bset, Mailbox::SKIP_EXPUNGED | mode);
+ Mailbox::iterator i = mailbox->begin(req.bset, Mailbox::SKIP_EXPUNGED | mode);
for (; i != mailbox->end(); ++i) {
Message &message = *i;
@@ -191,8 +183,7 @@ Operator::ProcessResult FetchOperator::process(Depot &depot,
struct tm *_tm = gmtime(&iDate);
char internal[64];
string iDateStr;
- if (strftime(internal, sizeof(internal),
- "%d-%b-%Y %H:%M:%S %z", _tm) != 0) {
+ if (strftime(internal, sizeof(internal), "%d-%b-%Y %H:%M:%S %z", _tm) != 0) {
if (internal[0] == '0') internal[0] = ' ';
iDateStr = internal;
} else
@@ -212,19 +203,16 @@ Operator::ProcessResult FetchOperator::process(Depot &depot,
bool fullheader = false;
bool bodyfetch = false;
- if (fatt.section != "" || fatt.sectiontext == ""
- || fatt.sectiontext == "TEXT") {
- bodyfetch = true;
- fullheader = true;
+ if (fatt.section != "" || fatt.sectiontext == "" || fatt.sectiontext == "TEXT") {
+ bodyfetch = true;
+ fullheader = true;
}
- if (fatt.sectiontext == "HEADER.FIELDS.NOT")
- includeheaders = false;
+ if (fatt.sectiontext == "HEADER.FIELDS.NOT") includeheaders = false;
- if (fatt.sectiontext == "HEADER"
- || fatt.sectiontext == "HEADER.FIELDS"
- || fatt.sectiontext == "HEADER.FIELDS.NOT"
- || fatt.sectiontext == "MIME") {
+ if (fatt.sectiontext == "HEADER" || fatt.sectiontext == "HEADER.FIELDS"
+ || fatt.sectiontext == "HEADER.FIELDS.NOT" || fatt.sectiontext == "MIME")
+ {
vector<string> v;
if (fatt.sectiontext == "MIME") {
@@ -236,120 +224,105 @@ Operator::ProcessResult FetchOperator::process(Depot &depot,
v = fatt.headerlist;
string dummy;
- unsigned int size = fullheader
- ? message.getHeaderSize(fatt.section, v, true,
- fatt.offsetstart,
- fatt.offsetlength,
- fatt.sectiontext == "MIME")
- : message.getHeaderSize(fatt.section, fatt.headerlist,
- includeheaders,
- fatt.offsetstart,
- fatt.offsetlength,
- fatt.sectiontext == "MIME");
+ unsigned int size = fullheader ? message.getHeaderSize(fatt.section,
+ v,
+ true,
+ fatt.offsetstart,
+ fatt.offsetlength,
+ fatt.sectiontext == "MIME")
+ : message.getHeaderSize(fatt.section,
+ fatt.headerlist,
+ includeheaders,
+ fatt.offsetstart,
+ fatt.offsetlength,
+ fatt.sectiontext == "MIME");
bincClient << "{" << size << "}\r\n";
if (fullheader) {
- message.printHeader(fatt.section, v, true,
+ message.printHeader(fatt.section,
+ v,
+ true,
fatt.offsetstart,
- fatt.offsetlength,
+ fatt.offsetlength,
fatt.sectiontext == "MIME");
} else {
- message.printHeader(fatt.section, fatt.headerlist,
+ message.printHeader(fatt.section,
+ fatt.headerlist,
includeheaders,
- fatt.offsetstart,
+ fatt.offsetstart,
fatt.offsetlength,
fatt.sectiontext == "MIME");
}
} else {
unsigned int size;
- if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT")
- && fatt.section == "")
- size = message.getDocSize(fatt.offsetstart,
- fatt.offsetlength,
- fatt.sectiontext == "TEXT");
+ if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT") && fatt.section == "")
+ size = message.getDocSize(fatt.offsetstart, fatt.offsetlength, fatt.sectiontext == "TEXT");
else
- size = message.getBodySize(fatt.section,
- fatt.offsetstart,
- fatt.offsetlength);
+ size = message.getBodySize(fatt.section, fatt.offsetstart, fatt.offsetlength);
- bincClient << "{" << size << "}\r\n";
+ bincClient << "{" << size << "}\r\n";
- if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT")
- && fatt.section == "")
- message.printDoc(fatt.offsetstart,
- fatt.offsetlength,
- fatt.sectiontext == "TEXT");
+ if ((fatt.sectiontext == "" || fatt.sectiontext == "TEXT") && fatt.section == "")
+ message.printDoc(fatt.offsetstart, fatt.offsetlength, fatt.sectiontext == "TEXT");
else
- message.printBody(fatt.section, fatt.offsetstart,
- fatt.offsetlength);
- }
+ message.printBody(fatt.section, fatt.offsetstart, fatt.offsetlength);
+ }
- // set the \Seen flag if .PEEK is not used.
- if (!peek)
- if ((message.getStdFlags() & Message::F_SEEN) == 0)
- message.setStdFlag(Message::F_SEEN);
- } else if (fatt.type == "RFC822") {
- bincClient << prefix;
- hasprinted = true;
- session.addBody();
- bincClient << fatt.toString();
- unsigned int size = message.getDocSize(fatt.offsetstart,
- fatt.offsetlength);
- bincClient << " {" << size << "}\r\n";
- message.printDoc(fatt.offsetstart, fatt.offsetlength);
-
- // set the \Seen flag
- if ((message.getStdFlags() & Message::F_SEEN) == 0)
- message.setStdFlag(Message::F_SEEN);
-
- } else if (fatt.type == "RFC822.HEADER") {
- bincClient << prefix;
- hasprinted = true;
- bincClient << fatt.toString();
- vector<string> v;
- string dummy;
- unsigned int size = message.getHeaderSize("", v, true,
- fatt.offsetstart,
- fatt.offsetlength);
- bincClient << " {" << size << "}\r\n";
- message.printHeader("", v, true, fatt.offsetstart,
- fatt.offsetlength);
- } else if (fatt.type == "RFC822.TEXT") {
- // RFC822.TEXT
- bincClient << prefix;
- hasprinted = true;
- session.addBody();
-
- bincClient << fatt.toString();
-
- bool bodyfetch = false;
- bodyfetch = true;
+ // set the \Seen flag if .PEEK is not used.
+ if (!peek)
+ if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN);
+ } else if (fatt.type == "RFC822") {
+ bincClient << prefix;
+ hasprinted = true;
+ session.addBody();
+ bincClient << fatt.toString();
+ unsigned int size = message.getDocSize(fatt.offsetstart, fatt.offsetlength);
+ bincClient << " {" << size << "}\r\n";
+ message.printDoc(fatt.offsetstart, fatt.offsetlength);
- unsigned int size;
- if (fatt.sectiontext == "" && fatt.section == "")
- size = message.getDocSize(fatt.offsetstart,
- fatt.offsetlength, true);
- else
- size = message.getBodySize(fatt.section, fatt.offsetstart,
- fatt.offsetlength);
+ // set the \Seen flag
+ if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN);
+
+ } else if (fatt.type == "RFC822.HEADER") {
+ bincClient << prefix;
+ hasprinted = true;
+ bincClient << fatt.toString();
+ vector<string> v;
+ string dummy;
+ unsigned int size = message.getHeaderSize("", v, true, fatt.offsetstart, fatt.offsetlength);
+ bincClient << " {" << size << "}\r\n";
+ message.printHeader("", v, true, fatt.offsetstart, fatt.offsetlength);
+ } else if (fatt.type == "RFC822.TEXT") {
+ // RFC822.TEXT
+ bincClient << prefix;
+ hasprinted = true;
+ session.addBody();
+
+ bincClient << fatt.toString();
+
+ bool bodyfetch = false;
+ bodyfetch = true;
+
+ unsigned int size;
+ if (fatt.sectiontext == "" && fatt.section == "")
+ size = message.getDocSize(fatt.offsetstart, fatt.offsetlength, true);
+ else
+ size = message.getBodySize(fatt.section, fatt.offsetstart, fatt.offsetlength);
bincClient << " {" << size << "}\r\n";
if (fatt.sectiontext == "" && fatt.section == "")
- message.printDoc(fatt.offsetstart,
- fatt.offsetlength, true);
+ message.printDoc(fatt.offsetstart, fatt.offsetlength, true);
else
- message.printBody(fatt.section, fatt.offsetstart,
- fatt.offsetlength);
+ message.printBody(fatt.section, fatt.offsetstart, fatt.offsetlength);
// set the \Seen flag
- if ((message.getStdFlags() & Message::F_SEEN) == 0)
- message.setStdFlag(Message::F_SEEN);
+ if ((message.getStdFlags() & Message::F_SEEN) == 0) message.setStdFlag(Message::F_SEEN);
- } else {
- // Unrecognized fetch_att, this is stopped by the parser
- // so we never get here.
+ } else {
+ // Unrecognized fetch_att, this is stopped by the parser
+ // so we never get here.
}
f_i++;
@@ -367,14 +340,13 @@ Operator::ProcessResult FetchOperator::process(Depot &depot,
message.setFlagsUnchanged();
}
}
-
+
if (updateFlags) mailbox->updateFlags();
pendingUpdates(mailbox,
- PendingUpdates::FLAGS
- | PendingUpdates::EXISTS
- | PendingUpdates::EXPUNGE
- | PendingUpdates::RECENT, true);
+ PendingUpdates::FLAGS | PendingUpdates::EXISTS | PendingUpdates::EXPUNGE
+ | PendingUpdates::RECENT,
+ true);
return OK;
}
@@ -423,8 +395,10 @@ Operator::ParseResult FetchOperator::parse(Request &c_in) const
c_in.fatt.push_back(ftmp);
- if ((res = expectSPACE()) == REJECT) break;
- else if (res == ERROR) return ERROR;
+ if ((res = expectSPACE()) == REJECT)
+ break;
+ else if (res == ERROR)
+ return ERROR;
}
if ((res = expectThisString(")")) != ACCEPT) {
@@ -446,8 +420,7 @@ Operator::ParseResult FetchOperator::parse(Request &c_in) const
}
//----------------------------------------------------------------------
-Operator::ParseResult
-FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const
+Operator::ParseResult FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
@@ -458,8 +431,7 @@ FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const
if ((res = expectThisString(".FIELDS")) == ACCEPT) {
f_in.sectiontext += ".FIELDS";
- if ((res = expectThisString(".NOT")) == ACCEPT)
- f_in.sectiontext += ".NOT";
+ if ((res = expectThisString(".NOT")) == ACCEPT) f_in.sectiontext += ".NOT";
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("expected SPACE");
@@ -477,18 +449,15 @@ FetchOperator::expectSectionText(BincImapParserFetchAtt &f_in) const
return REJECT;
return ACCEPT;
-
}
//----------------------------------------------------------------------
-Operator::ParseResult
-FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const
+Operator::ParseResult FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
Operator::ParseResult res;
- if ((res = expectThisString("[")) != ACCEPT)
- return REJECT;
+ if ((res = expectThisString("[")) != ACCEPT) return REJECT;
if ((res = expectSectionText(f_in)) != ACCEPT) {
unsigned int n;
@@ -509,7 +478,7 @@ FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const
f_in.section += ".";
BincStream nstr;
nstr << n;
- f_in.section += nstr.str();
+ f_in.section += nstr.str();
}
if (gotadotalready || (res = expectThisString(".")) == ACCEPT) {
@@ -532,14 +501,12 @@ FetchOperator::expectSection(BincImapParserFetchAtt &f_in) const
}
//----------------------------------------------------------------------
-Operator::ParseResult
-FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const
+Operator::ParseResult FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
Operator::ParseResult res;
- if ((res = expectThisString("(")) != ACCEPT)
- return REJECT;
+ if ((res = expectThisString("(")) != ACCEPT) return REJECT;
string header_fld_name;
while (1) {
@@ -550,8 +517,10 @@ FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const
f_in.headerlist.push_back(header_fld_name);
- if ((res = expectSPACE()) == ACCEPT) continue;
- else break;
+ if ((res = expectSPACE()) == ACCEPT)
+ continue;
+ else
+ break;
}
if ((res = expectThisString(")")) != ACCEPT) {
@@ -563,8 +532,7 @@ FetchOperator::expectHeaderList(BincImapParserFetchAtt &f_in) const
}
//----------------------------------------------------------------------
-Operator::ParseResult
-FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const
+Operator::ParseResult FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const
{
Session &session = Session::getInstance();
Operator::ParseResult res;
@@ -599,23 +567,28 @@ FetchOperator::expectOffset(BincImapParserFetchAtt &f_in) const
}
//----------------------------------------------------------------------
-Operator::ParseResult
-FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const
+Operator::ParseResult FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const
{
Operator::ParseResult res;
Session &session = Session::getInstance();
- if ((res = expectThisString("ENVELOPE")) == ACCEPT) f_in.type = "ENVELOPE";
- else if ((res = expectThisString("FLAGS")) == ACCEPT) f_in.type = "FLAGS";
+ if ((res = expectThisString("ENVELOPE")) == ACCEPT)
+ f_in.type = "ENVELOPE";
+ else if ((res = expectThisString("FLAGS")) == ACCEPT)
+ f_in.type = "FLAGS";
else if ((res = expectThisString("INTERNALDATE")) == ACCEPT)
f_in.type = "INTERNALDATE";
- else if ((res = expectThisString("UID")) == ACCEPT) f_in.type = "UID";
+ else if ((res = expectThisString("UID")) == ACCEPT)
+ f_in.type = "UID";
else if ((res = expectThisString("RFC822")) == ACCEPT) {
f_in.type = "RFC822";
- if ((res = expectThisString(".HEADER")) == ACCEPT) f_in.type += ".HEADER";
- else if ((res = expectThisString(".SIZE")) == ACCEPT) f_in.type += ".SIZE";
- else if ((res = expectThisString(".TEXT")) == ACCEPT) f_in.type += ".TEXT";
+ if ((res = expectThisString(".HEADER")) == ACCEPT)
+ f_in.type += ".HEADER";
+ else if ((res = expectThisString(".SIZE")) == ACCEPT)
+ f_in.type += ".SIZE";
+ else if ((res = expectThisString(".TEXT")) == ACCEPT)
+ f_in.type += ".TEXT";
else if ((res = expectThisString(".")) == ACCEPT) {
session.setLastError("Expected RFC822, RFC822.HEADER,"
" RFC822.SIZE or RFC822.TEXT");
@@ -625,15 +598,17 @@ FetchOperator::expectFetchAtt(BincImapParserFetchAtt &f_in) const
} else if ((res = expectThisString("BODY")) == ACCEPT) {
f_in.type = "BODY";
- if ((res = expectThisString("STRUCTURE")) == ACCEPT) f_in.type += "STRUCTURE";
- else if ((res = expectThisString(".PEEK")) == ACCEPT) f_in.type += ".PEEK";
+ if ((res = expectThisString("STRUCTURE")) == ACCEPT)
+ f_in.type += "STRUCTURE";
+ else if ((res = expectThisString(".PEEK")) == ACCEPT)
+ f_in.type += ".PEEK";
if ((res = expectSection(f_in)) != ACCEPT)
f_in.hassection = false;
else {
f_in.hassection = true;
if ((res = expectOffset(f_in)) == ERROR) return ERROR;
- }
+ }
} else
return REJECT;
diff --git a/src/operator-id.cc b/src/operator-id.cc
index 842c0a3..de74909 100644
--- a/src/operator-id.cc
+++ b/src/operator-id.cc
@@ -4,29 +4,25 @@
* @author Erwin Hoffmann
* @date 22.09.2023
* ------------------------------------------------------------------ **/
-#include <string>
-#include <iostream>
-
#include "depot.h"
+#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
-#include "globals.h"
+
+#include <iostream>
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-IdOperator::IdOperator(void)
-{
-}
+IdOperator::IdOperator(void) {}
//----------------------------------------------------------------------
-IdOperator::~IdOperator(void)
-{
-}
+IdOperator::~IdOperator(void) {}
//----------------------------------------------------------------------
const string IdOperator::getName(void) const
@@ -37,14 +33,11 @@ const string IdOperator::getName(void) const
//----------------------------------------------------------------------
int IdOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//----------------------------------------------------------------------
-Operator::ProcessResult IdOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult IdOperator::process(Depot &depot, Request &command)
{
bincClient << "* ID (\"name\" \"Binc IMAP\""
<< " \"version\" \"" << BINC_VERSION "\")" << endl;
diff --git a/src/operator-idle.cc b/src/operator-idle.cc
index ccd70ea..369bcd9 100644
--- a/src/operator-idle.cc
+++ b/src/operator-idle.cc
@@ -2,32 +2,33 @@
* @file operator-idle.cc
* @brief Operator for the IDLE command. Described in RFC2177 / June 1997.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ------------------------------------------------------------------ **/
-#include <unistd.h>
-
-#include <string>
-#include <iostream>
-
-#include "iodevice.h"
-#include "iofactory.h"
#include "convert.h"
#include "depot.h"
#include "globals.h"
+#include "iodevice.h"
+#include "iofactory.h"
#include "mailbox.h"
#include "operators.h"
#include "pendingupdates.h"
#include "recursivedescent.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
+#include <unistd.h>
+
static bool directoryChangeNotification = false;
-#ifdef HAVE_FNOTIFY // GNU dependencies removed
-#include <sys/types.h>
-#include <sys/select.h>
-#include <stdio.h>
+#ifdef HAVE_FNOTIFY // GNU dependencies removed
#include <signal.h>
+#include <stdio.h>
+
#include <fcntl.h>
+#include <sys/select.h>
+#include <sys/types.h>
void fnotifyEventHandler(int sig)
{
@@ -47,14 +48,10 @@ static const int POLLTIMEOUT = 30;
#endif
//----------------------------------------------------------------------
-IdleOperator::IdleOperator(void)
-{
-}
+IdleOperator::IdleOperator(void) {}
//----------------------------------------------------------------------
-IdleOperator::~IdleOperator(void)
-{
-}
+IdleOperator::~IdleOperator(void) {}
//----------------------------------------------------------------------
const string IdleOperator::getName(void) const
@@ -69,8 +66,7 @@ int IdleOperator::getState(void) const
}
//----------------------------------------------------------------------
-Operator::ProcessResult IdleOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command)
{
Mailbox *mailbox = depot.getSelected();
string mailboxDir = depot.mailboxToFilename(mailbox->getName());
@@ -82,9 +78,9 @@ Operator::ProcessResult IdleOperator::process(Depot &depot,
int curfd = open((mailboxDir + "/cur").c_str(), O_RDONLY);
// Watch for notifications for renames, deletes or creates.
- if (newfd && curfd
- && !fcntl(newfd, F_NOTIFY, DN_RENAME|DN_DELETE|DN_CREATE)
- && !fcntl(curfd, F_NOTIFY, DN_RENAME|DN_DELETE|DN_CREATE)) {
+ if (newfd && curfd && !fcntl(newfd, F_NOTIFY, DN_RENAME | DN_DELETE | DN_CREATE)
+ && !fcntl(curfd, F_NOTIFY, DN_RENAME | DN_DELETE | DN_CREATE))
+ {
struct sigaction fnotifyAction;
fnotifyAction.sa_handler = fnotifyEventHandler;
sigemptyset(&fnotifyAction.sa_mask);
@@ -99,12 +95,12 @@ Operator::ProcessResult IdleOperator::process(Depot &depot,
// when not using FNOTIFY, we need to check the session timeout.
time_t startTime = time(0);
#ifdef HAVE_FNOTIFY
- (void)startTime; // removes a compile warning
+ (void)startTime; // removes a compile warning
#endif
bincClient << "+ idling" << endl;
bincClient.flush();
-
+
// loop until the session times out or the client submits DONE.
for (;;) {
int maxfd = 0;
@@ -123,17 +119,16 @@ Operator::ProcessResult IdleOperator::process(Depot &depot,
Session &session = Session::getInstance();
#ifdef HAVE_FNOTIFY
if (waitForNotification) {
- bincClient << "* BYE Timeout after " << session.timeout()
- << " seconds of inactivity." << endl;
+ bincClient << "* BYE Timeout after " << session.timeout() << " seconds of inactivity." << endl;
session.setState(Session::LOGOUT);
close(newfd);
close(curfd);
return NOTHING;
} else
#endif
- if (time(0) > startTime + IDLE_TIMEOUT) {
- bincClient << "* BYE Timeout after " << IDLE_TIMEOUT
- << " seconds of inactivity." << endl;
+ if (time(0) > startTime + IDLE_TIMEOUT)
+ {
+ bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << endl;
session.setState(Session::LOGOUT);
return NOTHING;
}
@@ -175,20 +170,21 @@ Operator::ProcessResult IdleOperator::process(Depot &depot,
}
// scan for changes in the mailbox and report to the client.
- if (pendingUpdates(mailbox, PendingUpdates::EXPUNGE
- | PendingUpdates::EXISTS
- | PendingUpdates::RECENT
- | PendingUpdates::FLAGS, true) == false) {
+ if (pendingUpdates(mailbox,
+ PendingUpdates::EXPUNGE | PendingUpdates::EXISTS | PendingUpdates::RECENT
+ | PendingUpdates::FLAGS,
+ true)
+ == false)
+ {
Session &session = Session::getInstance();
bincClient << "* NO " << session.getLastError() << endl;
- bincWarning << "when scanning mailbox: "
- << session.getLastError() << endl;
+ bincWarning << "when scanning mailbox: " << session.getLastError() << endl;
#ifdef HAVE_FNOTIFY
- close(newfd);
- close(curfd);
+ close(newfd);
+ close(curfd);
#endif
- return NO;
+ return NO;
}
#ifdef HAVE_FNOTIFY
@@ -197,15 +193,16 @@ Operator::ProcessResult IdleOperator::process(Depot &depot,
directoryChangeNotification = false;
// set up F_NOTIFY again.
- if (!fcntl(newfd, F_NOTIFY, DN_MODIFY|DN_RENAME|DN_DELETE|DN_CREATE)
- && !fcntl(curfd, F_NOTIFY, DN_MODIFY|DN_RENAME|DN_DELETE|DN_CREATE)) {
+ if (!fcntl(newfd, F_NOTIFY, DN_MODIFY | DN_RENAME | DN_DELETE | DN_CREATE)
+ && !fcntl(curfd, F_NOTIFY, DN_MODIFY | DN_RENAME | DN_DELETE | DN_CREATE))
+ {
struct sigaction fnotifyAction;
fnotifyAction.sa_handler = fnotifyEventHandler;
sigemptyset(&fnotifyAction.sa_mask);
fnotifyAction.sa_flags = SA_RESTART;
sigaction(SIGUSR1, &fnotifyAction, 0);
} else {
- waitForNotification = false;
+ waitForNotification = false;
}
}
#endif
@@ -225,8 +222,7 @@ Operator::ParseResult IdleOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectCRLF()) != ACCEPT) {
diff --git a/src/operator-list.cc b/src/operator-list.cc
index baa8107..7ee66f3 100644
--- a/src/operator-list.cc
+++ b/src/operator-list.cc
@@ -2,13 +2,6 @@
* @file operator-list.cc
* @brief Implementation of the LIST command.
* ----------------------------------------------------------------- **/
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-#include <string>
-#include <iostream>
-
#include "convert.h"
#include "depot.h"
#include "iodevice.h"
@@ -19,6 +12,13 @@
#include "regmatch.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
using namespace ::std;
using namespace Binc;
@@ -33,9 +33,7 @@ ListOperator::ListOperator(void)
}
//----------------------------------------------------------------------
-ListOperator::~ListOperator(void)
-{
-}
+ListOperator::~ListOperator(void) {}
//----------------------------------------------------------------------
const string ListOperator::getName(void) const
@@ -50,8 +48,7 @@ int ListOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult ListOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult ListOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
const char delim = depot.getDelimiter();
@@ -71,16 +68,14 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
string regex = toRegex(wildcard, depot.getDelimiter());
string wildcardLower = regex;
lowercase(wildcardLower);
- if (wildcardLower.substr(0, 6) == "^inbox")
- regex = "^[iI][nN][bB][oO][xX]" + regex.substr(6);
+ if (wildcardLower.substr(0, 6) == "^inbox") regex = "^[iI][nN][bB][oO][xX]" + regex.substr(6);
// remove leading or trailing delimiter in reference
string ref = command.getMailbox();
trim(ref, string(&delim, 1));
wildcardLower = ref;
lowercase(wildcardLower);
- if (wildcardLower.substr(0, 6) == "^inbox")
- ref = "^[iI][nN][bB][oO][xX]" + ref.substr(6);
+ if (wildcardLower.substr(0, 6) == "^inbox") ref = "^[iI][nN][bB][oO][xX]" + ref.substr(6);
if (wildcardLower.substr(0, 5) == "inbox"
&& (wildcardLower.length() == 5 || wildcardLower[5] == delim))
ref = "INBOX" + ref.substr(5);
@@ -88,8 +83,7 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
// a map from mailbox name to flags
map<string, unsigned int> mailboxes;
- if (cacheTimeout == 0 || cacheTimeout < time(0) - LIST_CACHE_TIMEOUT
- || session.mailboxchanges) {
+ if (cacheTimeout == 0 || cacheTimeout < time(0) - LIST_CACHE_TIMEOUT || session.mailboxchanges) {
session.mailboxchanges = false;
// read through all entries in depository.
@@ -99,16 +93,16 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
Mailbox *m = 0;
// skip entries that are not identified as mailboxes
- if ((m = depot.get(mpath)) == 0)
- continue;
+ if ((m = depot.get(mpath)) == 0) continue;
// convert file name to mailbox name. skip it if there is no
// corresponding mailbox name.
string tmp = toCanonMailbox(depot.filenameToMailbox(path));
trim(tmp, string(&delim, 1));
- if (tmp == "") continue;
+ if (tmp == "")
+ continue;
else {
- // inherit flags that were already set for this mailbox.
+ // inherit flags that were already set for this mailbox.
int flags = DIR_SELECT;
if (m->isMarked(path)) flags |= DIR_MARKED;
if (mailboxes.find(tmp) != mailboxes.end()) flags |= mailboxes[tmp];
@@ -119,13 +113,12 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
// added already.
string::size_type pos = tmp.rfind(delim);
while (pos != string::npos) {
- tmp = tmp.substr(0, pos);
- trim(tmp, string(&delim, 1));
+ tmp = tmp.substr(0, pos);
+ trim(tmp, string(&delim, 1));
- if (mailboxes.find(tmp) == mailboxes.end())
- mailboxes[tmp] = 0;
+ if (mailboxes.find(tmp) == mailboxes.end()) mailboxes[tmp] = 0;
- pos = tmp.rfind(delim);
+ pos = tmp.rfind(delim);
}
}
@@ -163,12 +156,11 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
cacheTimeout = time(0);
}
- // finally, print all mailbox entries with flags.
+ // finally, print all mailbox entries with flags.
map<string, unsigned int>::iterator i = mailboxes.begin();
for (; i != mailboxes.end(); ++i) {
- if (ref == "" || (ref.length() <= i->first.length()
- && ref == i->first.substr(0, ref.length())))
+ if (ref == "" || (ref.length() <= i->first.length() && ref == i->first.substr(0, ref.length())))
if (regexMatch(i->first.substr(ref.length()), regex) == 0) {
bincClient << "* LIST (";
string sep = "";
@@ -196,12 +188,10 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
bincClient << sep << "\\HasChildren";
sep = " ";
- if (flags & DIR_NOINFERIORS)
- bincClient << sep << "\\Noinferiors";
+ if (flags & DIR_NOINFERIORS) bincClient << sep << "\\Noinferiors";
- bincClient << ") \"" << depot.getDelimiter() << "\" "
- << toImapString(i->first) << endl;
- }
+ bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(i->first) << endl;
+ }
}
return OK;
diff --git a/src/operator-login.cc b/src/operator-login.cc
index a0ecacd..7b7ffc2 100644
--- a/src/operator-login.cc
+++ b/src/operator-login.cc
@@ -2,37 +2,34 @@
* @file operator-login.cc
* @brief Implementation of the rapid LOGIN command
* @author Andreas Aardal Hanssen, Erwin Hoffmann
- * @date 2002-2005, 2023
+ * @date 2002-2005, 2023
* ----------------------------------------------------------------- **/
-#include <unistd.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-
-#include <string>
-#include <iostream>
-
#include "authenticate.h"
#include "depot.h"
+#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "globals.h"
#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
+#include <errno.h>
+#include <signal.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-LoginOperator::LoginOperator(void)
-{
-}
+LoginOperator::LoginOperator(void) {}
//----------------------------------------------------------------------
-LoginOperator::~LoginOperator(void)
-{
-}
+LoginOperator::~LoginOperator(void) {}
//----------------------------------------------------------------------
const string LoginOperator::getName(void) const
@@ -47,13 +44,11 @@ int LoginOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult LoginOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult LoginOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
- if (!session.command.ssl
- && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
+ if (!session.command.ssl && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
session.setLastError("Plain text password authentication is disallowd. "
"Please enable StartTLS or TLS in your mail client.");
return NO;
@@ -63,7 +58,7 @@ Operator::ProcessResult LoginOperator::process(Depot &depot,
string challenge;
switch (authenticate(depot, command.getUserID(), command.getPassword(), challenge)) {
- case 1:
+ case 1:
session.setLastError("An internal error occurred when you attempted "
"to log in to the IMAP server. Please contact "
"your system administrator.");
@@ -75,12 +70,12 @@ Operator::ProcessResult LoginOperator::process(Depot &depot,
"your system administrator.");
return NO;
case 3:
- bincClient << "* BYE Timeout after " << IDLE_TIMEOUT
- << " seconds of inactivity." << endl;
+ bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << endl;
break;
case -1:
bincClient << "* BYE The server died unexpectedly. Please contact "
- "your system administrator for more information." << endl;
+ "your system administrator for more information."
+ << endl;
break;
}
diff --git a/src/operator-logout.cc b/src/operator-logout.cc
index 643d412..aabffdf 100644
--- a/src/operator-logout.cc
+++ b/src/operator-logout.cc
@@ -2,34 +2,28 @@
* @file operator-logout.cc
* @brief Implementation of the LOGOUT command
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-
+#include "convert.h"
+#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
-
#include "mailbox.h"
+#include "operators.h"
#include "recursivedescent.h"
#include "session.h"
-#include "convert.h"
-#include "depot.h"
-#include "operators.h"
+#include <iostream>
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-LogoutOperator::LogoutOperator(void)
-{
-}
+LogoutOperator::LogoutOperator(void) {}
//----------------------------------------------------------------------
-LogoutOperator::~LogoutOperator(void)
-{
-}
+LogoutOperator::~LogoutOperator(void) {}
//----------------------------------------------------------------------
const string LogoutOperator::getName(void) const
@@ -40,19 +34,16 @@ const string LogoutOperator::getName(void) const
//----------------------------------------------------------------------
int LogoutOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//------------------------------------------------------------------------
-Operator::ProcessResult LogoutOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult LogoutOperator::process(Depot &depot, Request &command)
{
bincClient << "* BYE Binc IMAP shutting down" << endl;
bincClient << command.getTag() << " OK LOGOUT completed" << endl;
bincClient.flush();
-
+
#ifdef BINCIMAPD
Mailbox *mailbox = 0;
if ((mailbox = depot.getSelected()) != 0) {
@@ -60,7 +51,7 @@ Operator::ProcessResult LogoutOperator::process(Depot &depot,
delete mailbox;
}
#endif
-
+
Session &session = Session::getInstance();
session.setState(Session::LOGOUT);
@@ -68,12 +59,11 @@ Operator::ProcessResult LogoutOperator::process(Depot &depot,
}
//----------------------------------------------------------------------
-Operator::ParseResult LogoutOperator::parse(Request & c_in) const
+Operator::ParseResult LogoutOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectCRLF()) != ACCEPT) {
diff --git a/src/operator-lsub.cc b/src/operator-lsub.cc
index f776503..e2bd07d 100644
--- a/src/operator-lsub.cc
+++ b/src/operator-lsub.cc
@@ -2,13 +2,8 @@
* @file operator-lsub.cc
* @brief Implementation of the LSUB command.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <algorithm>
-#include <string>
-#include <vector>
-#include <iostream>
-
#include "convert.h"
#include "depot.h"
#include "iodevice.h"
@@ -19,25 +14,26 @@
#include "regmatch.h"
#include "session.h"
+#include <algorithm>
+#include <iostream>
+#include <string>
+#include <vector>
+
namespace {
- const int DIR_SELECT = 0x01;
- const int DIR_MARKED = 0x02;
+ const int DIR_SELECT = 0x01;
+ const int DIR_MARKED = 0x02;
const int DIR_NOINFERIORS = 0x04;
- const int DIR_LEAF = 0x08;
+ const int DIR_LEAF = 0x08;
}
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-LsubOperator::LsubOperator(void)
-{
-}
+LsubOperator::LsubOperator(void) {}
//----------------------------------------------------------------------
-LsubOperator::~LsubOperator(void)
-{
-}
+LsubOperator::~LsubOperator(void) {}
//----------------------------------------------------------------------
const string LsubOperator::getName(void) const
@@ -52,8 +48,7 @@ int LsubOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult LsubOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult LsubOperator::process(Depot &depot, Request &command)
{
const char delim = depot.getDelimiter();
@@ -65,8 +60,7 @@ Operator::ProcessResult LsubOperator::process(Depot &depot,
string regex = toRegex(wildcard, depot.getDelimiter());
string wildcardLower = regex;
lowercase(wildcardLower);
- if (wildcardLower.substr(0, 6) == "^inbox")
- regex = "^[iI][nN][bB][oO][xX]" + regex.substr(6);
+ if (wildcardLower.substr(0, 6) == "^inbox") regex = "^[iI][nN][bB][oO][xX]" + regex.substr(6);
// remove leading or trailing delimiter in reference
string ref = command.getMailbox();
@@ -87,8 +81,7 @@ Operator::ProcessResult LsubOperator::process(Depot &depot,
Mailbox *m = 0;
// skip entries that are not identified as mailboxes
- if ((m = depot.get(mpath)) == 0)
- continue;
+ if ((m = depot.get(mpath)) == 0) continue;
// convert file name to mailbox name. skip it if there is no
// corresponding mailbox name.
@@ -149,9 +142,8 @@ Operator::ProcessResult LsubOperator::process(Depot &depot,
vector<string> subscribed = depot.getSubscriptions();
sort(subscribed.begin(), subscribed.end());
- // finally, print all mailbox entries with flags.
- for (vector<string>::const_iterator j = subscribed.begin();
- j != subscribed.end(); ++j) {
+ // finally, print all mailbox entries with flags.
+ for (vector<string>::const_iterator j = subscribed.begin(); j != subscribed.end(); ++j) {
if (ref == "" || (ref.length() <= (*j).length() && ref == (*j).substr(0, ref.length())))
if (regexMatch((*j).substr(ref.length()), regex) == 0) {
int flags = 0;
@@ -181,10 +173,8 @@ Operator::ProcessResult LsubOperator::process(Depot &depot,
else
bincClient << sep << "\\HasChildren";
sep = " ";
- if (flags & DIR_NOINFERIORS)
- bincClient << sep << "\\Noinferiors";
- bincClient << ") \"" << depot.getDelimiter() << "\" "
- << toImapString(*j) << endl;
+ if (flags & DIR_NOINFERIORS) bincClient << sep << "\\Noinferiors";
+ bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(*j) << endl;
}
}
@@ -196,8 +186,7 @@ Operator::ParseResult LsubOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
diff --git a/src/operator-namespace.cc b/src/operator-namespace.cc
index 8574f91..f03f0c7 100644
--- a/src/operator-namespace.cc
+++ b/src/operator-namespace.cc
@@ -4,9 +4,6 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-
#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
@@ -14,18 +11,17 @@
#include "recursivedescent.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-NamespaceOperator::NamespaceOperator(void)
-{
-}
+NamespaceOperator::NamespaceOperator(void) {}
//----------------------------------------------------------------------
-NamespaceOperator::~NamespaceOperator(void)
-{
-}
+NamespaceOperator::~NamespaceOperator(void) {}
//----------------------------------------------------------------------
const string NamespaceOperator::getName(void) const
@@ -40,20 +36,19 @@ int NamespaceOperator::getState(void) const
}
//----------------------------------------------------------------------
-Operator::ProcessResult NamespaceOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult NamespaceOperator::process(Depot &depot, Request &command)
{
bincClient << "* NAMESPACE ";
- bincClient << "(("; // personal namespace
+ bincClient << "(("; // personal namespace
bincClient << toImapString(depot.getPersonalNamespace());
bincClient << " ";
char c = depot.getDelimiter();
bincClient << toImapString(string(&c, 1));
bincClient << "))";
- bincClient << " NIL"; // others' namespaces
- bincClient << " NIL"; // shared namespaces
+ bincClient << " NIL"; // others' namespaces
+ bincClient << " NIL"; // shared namespaces
bincClient << endl;
return OK;
@@ -64,8 +59,7 @@ Operator::ParseResult NamespaceOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectCRLF()) != ACCEPT) {
diff --git a/src/operator-noop-pending.cc b/src/operator-noop-pending.cc
index f98405e..96b255a 100644
--- a/src/operator-noop-pending.cc
+++ b/src/operator-noop-pending.cc
@@ -4,40 +4,34 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-
+#include "depot.h"
#include "mailbox.h"
+#include "operators.h"
#include "pendingupdates.h"
-
#include "recursivedescent.h"
#include "session.h"
-#include "depot.h"
-#include "operators.h"
+
+#include <iostream>
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-NoopPendingOperator::NoopPendingOperator(void) : NoopOperator()
-{
-}
+NoopPendingOperator::NoopPendingOperator(void) : NoopOperator() {}
//----------------------------------------------------------------------
-NoopPendingOperator::~NoopPendingOperator(void)
-{
-}
+NoopPendingOperator::~NoopPendingOperator(void) {}
//----------------------------------------------------------------------
-Operator::ProcessResult NoopPendingOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult NoopPendingOperator::process(Depot &depot, Request &command)
{
Mailbox *mailbox = depot.getSelected();
if (mailbox) {
- pendingUpdates(mailbox, PendingUpdates::EXPUNGE
- | PendingUpdates::EXISTS
- | PendingUpdates::RECENT
- | PendingUpdates::FLAGS, true);
+ pendingUpdates(mailbox,
+ PendingUpdates::EXPUNGE | PendingUpdates::EXISTS | PendingUpdates::RECENT
+ | PendingUpdates::FLAGS,
+ true);
}
return OK;
diff --git a/src/operator-noop.cc b/src/operator-noop.cc
index d267513..a32214f 100644
--- a/src/operator-noop.cc
+++ b/src/operator-noop.cc
@@ -4,26 +4,22 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ------------------------------------------------------------------ **/
-#include <string>
-#include <iostream>
-
-#include "recursivedescent.h"
-#include "session.h"
#include "depot.h"
#include "operators.h"
+#include "recursivedescent.h"
+#include "session.h"
+
+#include <iostream>
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-NoopOperator::NoopOperator(void)
-{
-}
+NoopOperator::NoopOperator(void) {}
//----------------------------------------------------------------------
-NoopOperator::~NoopOperator(void)
-{
-}
+NoopOperator::~NoopOperator(void) {}
//----------------------------------------------------------------------
const string NoopOperator::getName(void) const
@@ -34,14 +30,11 @@ const string NoopOperator::getName(void) const
//----------------------------------------------------------------------
int NoopOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//----------------------------------------------------------------------
-Operator::ProcessResult NoopOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult NoopOperator::process(Depot &depot, Request &command)
{
return OK;
}
diff --git a/src/operator-rename.cc b/src/operator-rename.cc
index cc11d14..bfbe226 100644
--- a/src/operator-rename.cc
+++ b/src/operator-rename.cc
@@ -2,13 +2,6 @@
* @file operator-rename.cc
* @brief Implementation of the RENAME command.
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "convert.h"
#include "depot.h"
#include "mailbox.h"
@@ -16,18 +9,21 @@
#include "recursivedescent.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-RenameOperator::RenameOperator(void)
-{
-}
+RenameOperator::RenameOperator(void) {}
//----------------------------------------------------------------------
-RenameOperator::~RenameOperator(void)
-{
-}
+RenameOperator::~RenameOperator(void) {}
//----------------------------------------------------------------------
const string RenameOperator::getName(void) const
@@ -42,8 +38,7 @@ int RenameOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult RenameOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult RenameOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -75,9 +70,8 @@ Operator::ProcessResult RenameOperator::process(Depot &depot,
Operator::ParseResult RenameOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
-
- if (c_in.getUidMode())
- return REJECT;
+
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
@@ -99,13 +93,13 @@ Operator::ParseResult RenameOperator::parse(Request &c_in) const
string newmailbox;
if ((res = expectMailbox(newmailbox)) != ACCEPT) {
session.setLastError("Expected mailbox after RENAME SPACE"
- " mailbox SPACE");
+ " mailbox SPACE");
return res;
}
if ((res = expectCRLF()) != ACCEPT) {
session.setLastError("Expected CRLF after RENAME SPACE"
- " mailbox SPACE mailbox");
+ " mailbox SPACE mailbox");
return res;
}
diff --git a/src/operator-search.cc b/src/operator-search.cc
index 0470eb5..08f51c1 100644
--- a/src/operator-search.cc
+++ b/src/operator-search.cc
@@ -2,14 +2,8 @@
* @file operator-search.cc
* @brief Implementation of the SEARCH command.
* @author Andreas Aardal Hanssen
- * @date 2002-2005
+ * @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-#include <algorithm>
-
-#include <ctype.h>
-
#include "convert.h"
#include "depot.h"
#include "imapparser.h"
@@ -21,52 +15,67 @@
#include "recursivedescent.h"
#include "session.h"
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+#include <ctype.h>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-bool SearchOperator::SearchNode::convertDate(const string &date,
- time_t &t, const string &delim)
+bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, const string &delim)
{
vector<string> parts;
split(date, delim, parts);
if (parts.size() < 3) return false;
-
+
struct tm mold;
- memset((char *) &mold, 0, sizeof(struct tm));
+ memset((char *)&mold, 0, sizeof(struct tm));
mold.tm_mday = atoi(parts[0].c_str());
mold.tm_year = atoi(parts[2].c_str()) - 1900;
-
+
// accept mixed case months. this is more than the standard
// accepts.
string month = parts[1];
lowercase(month);
-
- if (month == "jan") mold.tm_mon = 0;
- else if (month == "feb") mold.tm_mon = 1;
- else if (month == "mar") mold.tm_mon = 2;
- else if (month == "apr") mold.tm_mon = 3;
- else if (month == "may") mold.tm_mon = 4;
- else if (month == "jun") mold.tm_mon = 5;
- else if (month == "jul") mold.tm_mon = 6;
- else if (month == "aug") mold.tm_mon = 7;
- else if (month == "sep") mold.tm_mon = 8;
- else if (month == "oct") mold.tm_mon = 9;
- else if (month == "nov") mold.tm_mon = 10;
- else if (month == "dec") mold.tm_mon = 11;
-
+
+ if (month == "jan")
+ mold.tm_mon = 0;
+ else if (month == "feb")
+ mold.tm_mon = 1;
+ else if (month == "mar")
+ mold.tm_mon = 2;
+ else if (month == "apr")
+ mold.tm_mon = 3;
+ else if (month == "may")
+ mold.tm_mon = 4;
+ else if (month == "jun")
+ mold.tm_mon = 5;
+ else if (month == "jul")
+ mold.tm_mon = 6;
+ else if (month == "aug")
+ mold.tm_mon = 7;
+ else if (month == "sep")
+ mold.tm_mon = 8;
+ else if (month == "oct")
+ mold.tm_mon = 9;
+ else if (month == "nov")
+ mold.tm_mon = 10;
+ else if (month == "dec")
+ mold.tm_mon = 11;
+
t = mktime(&mold);
return true;
}
//----------------------------------------------------------------------
-bool SearchOperator::SearchNode::convertDateHeader(const string &d_in,
- time_t &t)
+bool SearchOperator::SearchNode::convertDateHeader(const string &d_in, time_t &t)
{
string date = d_in;
string::size_type n = date.find(',');
- if (n != string::npos)
- date = date.substr(n + 1);
+ if (n != string::npos) date = date.substr(n + 1);
trim(date);
bool result = convertDate(date, t, " ");
@@ -74,9 +83,7 @@ bool SearchOperator::SearchNode::convertDateHeader(const string &d_in,
}
//----------------------------------------------------------------------
-SearchOperator::SearchNode::SearchNode(void)
-{
-}
+SearchOperator::SearchNode::SearchNode(void) {}
//----------------------------------------------------------------------
SearchOperator::SearchNode::SearchNode(const BincImapParserSearchKey &a)
@@ -92,7 +99,8 @@ int SearchOperator::SearchNode::getType(void) const
//----------------------------------------------------------------------
bool SearchOperator::SearchNode::match(Mailbox *mailbox,
- Message *m, unsigned int seqnr,
+ Message *m,
+ unsigned int seqnr,
unsigned int lastmessage,
unsigned int lastuid) const
{
@@ -101,10 +109,10 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
switch (type) {
//--------------------------------------------------------------------
- case S_ALL:
+ case S_ALL:
return true;
//--------------------------------------------------------------------
- case S_ANSWERED:
+ case S_ANSWERED:
return (m->getStdFlags() & Message::F_ANSWERED);
//--------------------------------------------------------------------
case S_BCC:
@@ -123,13 +131,12 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
time_t atime;
if (!convertDate(date, atime)) {
- bincWarning << "warning, unable to convert " << date <<
- " to a time_t" << endl;
+ bincWarning << "warning, unable to convert " << date << " to a time_t" << endl;
return false;
}
return mtime < atime;
- } //--------------------------------------------------------------------
+ } //--------------------------------------------------------------------
case S_BODY:
return m->bodyContains(astring);
//--------------------------------------------------------------------
@@ -145,13 +152,12 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
case S_FROM:
return m->headerContains("from", astring);
//--------------------------------------------------------------------
- case S_KEYWORD:
+ case S_KEYWORD:
// the server does not support keywords
return false;
//--------------------------------------------------------------------
case S_NEW:
- return (m->getStdFlags() & Message::F_RECENT)
- && !(m->getStdFlags() & Message::F_SEEN);
+ return (m->getStdFlags() & Message::F_RECENT) && !(m->getStdFlags() & Message::F_SEEN);
//--------------------------------------------------------------------
case S_OLD:
return !(m->getStdFlags() & Message::F_RECENT);
@@ -169,13 +175,12 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
time_t atime;
if (!convertDate(date, atime)) {
- bincWarning << "warning, unable to convert " << date <<
- " to a time_t" << endl;
+ bincWarning << "warning, unable to convert " << date << " to a time_t" << endl;
return false;
}
return mtime == atime;
- } //--------------------------------------------------------------------
+ } //--------------------------------------------------------------------
case S_RECENT:
return (m->getStdFlags() & Message::F_RECENT);
//--------------------------------------------------------------------
@@ -195,13 +200,12 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
time_t atime;
if (!convertDate(date, atime)) {
- bincWarning << "warning, unable to convert " << date <<
- " to a time_t" << endl;
+ bincWarning << "warning, unable to convert " << date << " to a time_t" << endl;
return false;
}
return mtime >= atime;
- } //--------------------------------------------------------------------
+ } //--------------------------------------------------------------------
case S_SUBJECT:
return m->headerContains("subject", astring);
//--------------------------------------------------------------------
@@ -238,38 +242,34 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
//--------------------------------------------------------------------
case S_NOT:
- for (vector<SearchNode>::const_iterator i = children.begin();
- i != children.end(); ++i)
+ for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i)
if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return false;
return true;
//--------------------------------------------------------------------
case S_OR:
- for (vector<SearchNode>::const_iterator i = children.begin();
- i != children.end(); ++i)
+ for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i)
if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return true;
return false;
//--------------------------------------------------------------------
case S_SENTBEFORE: {
string tmp = m->getHeader("date");
- if (tmp == "")
- return false;
+ if (tmp == "") return false;
lowercase(tmp);
time_t mtime;
if (!convertDateHeader(tmp, mtime)) return false;
- if (mtime == (time_t) -1) return false;
+ if (mtime == (time_t)-1) return false;
time_t atime;
if (!convertDate(date, atime)) {
- bincWarning << "warning, unable to convert " << date <<
- " to a time_t" << endl;
+ bincWarning << "warning, unable to convert " << date << " to a time_t" << endl;
return false;
}
return mtime < atime;
- } //--------------------------------------------------------------------
+ } //--------------------------------------------------------------------
case S_SENTON: {
string tmp = m->getHeader("date");
if (tmp == "") return false;
@@ -279,17 +279,16 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
time_t mtime;
if (!convertDateHeader(tmp, mtime)) return false;
- if (mtime == (time_t) -1) return false;
+ if (mtime == (time_t)-1) return false;
time_t atime;
if (!convertDate(date, atime)) {
- bincWarning << "warning, unable to convert " << date <<
- " to a time_t" << endl;
+ bincWarning << "warning, unable to convert " << date << " to a time_t" << endl;
return false;
}
return mtime == atime;
- } //--------------------------------------------------------------------
+ } //--------------------------------------------------------------------
case S_SENTSINCE: {
string tmp = m->getHeader("date");
if (tmp == "") return false;
@@ -299,17 +298,16 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
time_t mtime;
if (!convertDateHeader(tmp, mtime)) return false;
- if (mtime == (time_t) -1) return false;
+ if (mtime == (time_t)-1) return false;
time_t atime;
if (!convertDate(date, atime)) {
- bincWarning << "warning, unable to convert " << date
- << " to a time_t" << endl;
+ bincWarning << "warning, unable to convert " << date << " to a time_t" << endl;
return false;
}
return mtime >= atime;
- } //--------------------------------------------------------------------
+ } //--------------------------------------------------------------------
case S_SMALLER:
return (m->getSize(true) < number);
//--------------------------------------------------------------------
@@ -327,8 +325,7 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
return true;
//--------------------------------------------------------------------
case S_AND:
- for (vector<SearchNode>::const_iterator i = children.begin();
- i != children.end(); ++i)
+ for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i)
if (!(*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return false;
return true;
}
@@ -347,34 +344,88 @@ void SearchOperator::SearchNode::init(const BincImapParserSearchKey &a)
uppercase(bstring);
uppercase(date);
- if (a.name == "ALL") { type = S_ALL; weight = 1; }
- else if (a.name == "ANSWERED") { type = S_ANSWERED; weight = 1; }
- else if (a.name == "BCC") { type = S_BCC; weight = 2; }
- else if (a.name == "BEFORE") { type = S_BEFORE; weight = 2; }
- else if (a.name == "BODY") { type = S_BODY; weight = 1; }
- else if (a.name == "CC") { type = S_CC; weight = 2; }
- else if (a.name == "DELETED") { type = S_DELETED; weight = 1; }
- else if (a.name == "FLAGGED") { type = S_FLAGGED; weight = 1; }
- else if (a.name == "FROM") { type = S_FROM; weight = 2; }
- else if (a.name == "KEYWORD") { type = S_KEYWORD; weight = 3; }
- else if (a.name == "NEW") { type = S_NEW; weight = 1; }
- else if (a.name == "OLD") { type = S_OLD; weight = 1; }
- else if (a.name == "ON") { type = S_ON; weight = 1; }
- else if (a.name == "RECENT") { type = S_RECENT; weight = 1; }
- else if (a.name == "SEEN") { type = S_SEEN; weight = 1; }
- else if (a.name == "SINCE") { type = S_SINCE; weight = 1; }
- else if (a.name == "SUBJECT") { type = S_SUBJECT; weight = 2; }
- else if (a.name == "TEXT") { type = S_TEXT; weight = 4; }
- else if (a.name == "TO") { type = S_TO; weight = 2; }
- else if (a.name == "UNANSWERED") { type = S_UNANSWERED; weight = 1; }
- else if (a.name == "UNDELETED") { type = S_UNDELETED; weight = 1; }
- else if (a.name == "UNFLAGGED") { type = S_UNFLAGGED; weight = 1; }
- else if (a.name == "UNKEYWORD") { type = S_UNKEYWORD; weight = 1; }
- else if (a.name == "UNSEEN") { type = S_UNSEEN; weight = 1; }
- else if (a.name == "DRAFT") { type = S_DRAFT; weight = 1; }
- else if (a.name == "HEADER") { type = S_HEADER; weight = 3; }
- else if (a.name == "LARGER") { type = S_LARGER; weight = 4; }
- else if (a.name == "NOT") {
+ if (a.name == "ALL") {
+ type = S_ALL;
+ weight = 1;
+ } else if (a.name == "ANSWERED") {
+ type = S_ANSWERED;
+ weight = 1;
+ } else if (a.name == "BCC") {
+ type = S_BCC;
+ weight = 2;
+ } else if (a.name == "BEFORE") {
+ type = S_BEFORE;
+ weight = 2;
+ } else if (a.name == "BODY") {
+ type = S_BODY;
+ weight = 1;
+ } else if (a.name == "CC") {
+ type = S_CC;
+ weight = 2;
+ } else if (a.name == "DELETED") {
+ type = S_DELETED;
+ weight = 1;
+ } else if (a.name == "FLAGGED") {
+ type = S_FLAGGED;
+ weight = 1;
+ } else if (a.name == "FROM") {
+ type = S_FROM;
+ weight = 2;
+ } else if (a.name == "KEYWORD") {
+ type = S_KEYWORD;
+ weight = 3;
+ } else if (a.name == "NEW") {
+ type = S_NEW;
+ weight = 1;
+ } else if (a.name == "OLD") {
+ type = S_OLD;
+ weight = 1;
+ } else if (a.name == "ON") {
+ type = S_ON;
+ weight = 1;
+ } else if (a.name == "RECENT") {
+ type = S_RECENT;
+ weight = 1;
+ } else if (a.name == "SEEN") {
+ type = S_SEEN;
+ weight = 1;
+ } else if (a.name == "SINCE") {
+ type = S_SINCE;
+ weight = 1;
+ } else if (a.name == "SUBJECT") {
+ type = S_SUBJECT;
+ weight = 2;
+ } else if (a.name == "TEXT") {
+ type = S_TEXT;
+ weight = 4;
+ } else if (a.name == "TO") {
+ type = S_TO;
+ weight = 2;
+ } else if (a.name == "UNANSWERED") {
+ type = S_UNANSWERED;
+ weight = 1;
+ } else if (a.name == "UNDELETED") {
+ type = S_UNDELETED;
+ weight = 1;
+ } else if (a.name == "UNFLAGGED") {
+ type = S_UNFLAGGED;
+ weight = 1;
+ } else if (a.name == "UNKEYWORD") {
+ type = S_UNKEYWORD;
+ weight = 1;
+ } else if (a.name == "UNSEEN") {
+ type = S_UNSEEN;
+ weight = 1;
+ } else if (a.name == "DRAFT") {
+ type = S_DRAFT;
+ weight = 1;
+ } else if (a.name == "HEADER") {
+ type = S_HEADER;
+ weight = 3;
+ } else if (a.name == "LARGER") {
+ type = S_LARGER;
+ weight = 4;
+ } else if (a.name == "NOT") {
// ******* NOT
type = S_NOT;
weight = 1;
@@ -401,16 +452,26 @@ void SearchOperator::SearchNode::init(const BincImapParserSearchKey &a)
++i;
}
- } else if (a.name == "SENTBEFORE") { type = S_SENTBEFORE; weight = 1; }
- else if (a.name == "SENTON") { type = S_SENTON; weight = 1; }
- else if (a.name == "SENTSINCE") { type = S_SENTSINCE; weight = 1; }
- else if (a.name == "SMALLER") { type = S_SMALLER; weight = 4; }
- else if (a.name == "UID") {
+ } else if (a.name == "SENTBEFORE") {
+ type = S_SENTBEFORE;
+ weight = 1;
+ } else if (a.name == "SENTON") {
+ type = S_SENTON;
+ weight = 1;
+ } else if (a.name == "SENTSINCE") {
+ type = S_SENTSINCE;
+ weight = 1;
+ } else if (a.name == "SMALLER") {
+ type = S_SMALLER;
+ weight = 4;
+ } else if (a.name == "UID") {
bset = &a.getSet();
type = S_UID;
weight = 1;
- } else if (a.name == "UNDRAFT") { type = S_UNDRAFT; weight = 1; }
- else if (a.type == BincImapParserSearchKey::KEY_SET) {
+ } else if (a.name == "UNDRAFT") {
+ type = S_UNDRAFT;
+ weight = 1;
+ } else if (a.type == BincImapParserSearchKey::KEY_SET) {
bset = &a.getSet();
type = S_SET;
weight = 1;
@@ -444,21 +505,16 @@ void SearchOperator::SearchNode::setWeight(int i)
//----------------------------------------------------------------------
void SearchOperator::SearchNode::order(void)
{
- for (vector<SearchNode>::iterator i = children.begin();
- i != children.end(); ++i)
+ for (vector<SearchNode>::iterator i = children.begin(); i != children.end(); ++i)
(*i).order();
::stable_sort(children.begin(), children.end(), compareNodes);
}
//----------------------------------------------------------------------
-SearchOperator::SearchOperator(void)
-{
-}
+SearchOperator::SearchOperator(void) {}
//----------------------------------------------------------------------
-SearchOperator::~SearchOperator(void)
-{
-}
+SearchOperator::~SearchOperator(void) {}
//----------------------------------------------------------------------
const string SearchOperator::getName(void) const
@@ -473,16 +529,14 @@ int SearchOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult SearchOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
Mailbox *mailbox = depot.getSelected();
if (command.getCharSet() != "" && command.getCharSet() != "US-ASCII") {
- session.setLastError("The " + command.getCharSet()
- + " charset is not supported");
+ session.setLastError("The " + command.getCharSet() + " charset is not supported");
session.setResponseCode("[BADCHARSET (\"US-ASCII\")]");
return NO;
}
@@ -496,14 +550,12 @@ Operator::ProcessResult SearchOperator::process(Depot &depot,
const unsigned int maxsqnr = mailbox->getMaxSqnr();
const unsigned int maxuid = mailbox->getMaxUid();
- Mailbox::iterator i
- = mailbox->begin(SequenceSet::all(), Mailbox::SKIP_EXPUNGED);
+ Mailbox::iterator i = mailbox->begin(SequenceSet::all(), Mailbox::SKIP_EXPUNGED);
for (; i != mailbox->end(); ++i) {
Message &message = *i;
if (s.match(mailbox, &message, i.getSqnr(), maxsqnr, maxuid)) {
- bincClient << " "
- << (command.getUidMode() ? message.getUID() : i.getSqnr());
+ bincClient << " " << (command.getUidMode() ? message.getUID() : i.getSqnr());
bincClient.flush();
}
@@ -515,7 +567,7 @@ Operator::ProcessResult SearchOperator::process(Depot &depot,
}
//------------------------------------------------------------------------
-Operator::ParseResult SearchOperator::parse(Request & c_in) const
+Operator::ParseResult SearchOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
@@ -538,7 +590,7 @@ Operator::ParseResult SearchOperator::parse(Request & c_in) const
}
c_in.setCharSet(charset);
-
+
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE after CHARSET SPACE astring");
return res;
@@ -553,17 +605,16 @@ Operator::ParseResult SearchOperator::parse(Request & c_in) const
c_in.searchkey.type = BincImapParserSearchKey::KEY_AND;
c_in.searchkey.children.push_back(b);
-
+
while (1) {
- if ((res = expectSPACE()) != ACCEPT)
- break;
+ if ((res = expectSPACE()) != ACCEPT) break;
BincImapParserSearchKey c;
if ((res = expectSearchKey(c)) != ACCEPT) {
session.setLastError("Expected search_key after search_key SPACE");
return res;
}
-
+
c_in.searchkey.children.push_back(c);
}
@@ -571,21 +622,22 @@ Operator::ParseResult SearchOperator::parse(Request & c_in) const
session.setLastError("Expected CRLF after search_key");
return res;
}
-
+
c_in.setName("SEARCH");
return ACCEPT;
}
//----------------------------------------------------------------------
-Operator::ParseResult
-SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
+Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
{
Session &session = Session::getInstance();
Operator::ParseResult res;
s_in.type = BincImapParserSearchKey::KEY_OTHER;
- if ((res = expectThisString("ALL")) == ACCEPT) s_in.name = "ALL";
- else if ((res = expectThisString("ANSWERED")) == ACCEPT) s_in.name = "ANSWERED";
+ if ((res = expectThisString("ALL")) == ACCEPT)
+ s_in.name = "ALL";
+ else if ((res = expectThisString("ANSWERED")) == ACCEPT)
+ s_in.name = "ANSWERED";
else if ((res = expectThisString("BCC")) == ACCEPT) {
s_in.name = "BCC";
if ((res = expectSPACE()) != ACCEPT) {
@@ -599,7 +651,7 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
}
} else if ((res = expectThisString("BEFORE")) == ACCEPT) {
s_in.name = "BEFORE";
-
+
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
return res;
@@ -631,8 +683,10 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
session.setLastError("Expected astring");
return res;
}
- } else if ((res = expectThisString("DELETED")) == ACCEPT) s_in.name = "DELETED";
- else if ((res = expectThisString("FLAGGED")) == ACCEPT) s_in.name = "FLAGGED";
+ } else if ((res = expectThisString("DELETED")) == ACCEPT)
+ s_in.name = "DELETED";
+ else if ((res = expectThisString("FLAGGED")) == ACCEPT)
+ s_in.name = "FLAGGED";
else if ((res = expectThisString("FROM")) == ACCEPT) {
s_in.name = "FROM";
if ((res = expectSPACE()) != ACCEPT) {
@@ -655,8 +709,10 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
session.setLastError("Expected flag_keyword");
return res;
}
- } else if ((res = expectThisString("NEW")) == ACCEPT) s_in.name = "NEW";
- else if ((res = expectThisString("OLD")) == ACCEPT) s_in.name = "OLD";
+ } else if ((res = expectThisString("NEW")) == ACCEPT)
+ s_in.name = "NEW";
+ else if ((res = expectThisString("OLD")) == ACCEPT)
+ s_in.name = "OLD";
else if ((res = expectThisString("ON")) == ACCEPT) {
s_in.name = "ON";
@@ -669,8 +725,10 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
session.setLastError("Expected date");
return res;
}
- } else if ((res = expectThisString("RECENT")) == ACCEPT) s_in.name = "RECENT";
- else if ((res = expectThisString("SEEN")) == ACCEPT) s_in.name = "SEEN";
+ } else if ((res = expectThisString("RECENT")) == ACCEPT)
+ s_in.name = "RECENT";
+ else if ((res = expectThisString("SEEN")) == ACCEPT)
+ s_in.name = "SEEN";
else if ((res = expectThisString("SINCE")) == ACCEPT) {
s_in.name = "SINCE";
@@ -680,7 +738,7 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
}
if ((res = expectDate(s_in.date)) != ACCEPT) {
- session.setLastError("Expected date");
+ session.setLastError("Expected date");
return res;
}
} else if ((res = expectThisString("SUBJECT")) == ACCEPT) {
@@ -718,8 +776,10 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
}
} else if ((res = expectThisString("UNANSWERED")) == ACCEPT)
s_in.name = "UNANSWERED";
- else if ((res = expectThisString("UNDELETED")) == ACCEPT) s_in.name = "UNDELETED";
- else if ((res = expectThisString("UNFLAGGED")) == ACCEPT) s_in.name = "UNFLAGGED";
+ else if ((res = expectThisString("UNDELETED")) == ACCEPT)
+ s_in.name = "UNDELETED";
+ else if ((res = expectThisString("UNFLAGGED")) == ACCEPT)
+ s_in.name = "UNFLAGGED";
else if ((res = expectThisString("UNKEYWORD")) == ACCEPT) {
s_in.name = "UNKEYWORD";
if ((res = expectSPACE()) != ACCEPT) {
@@ -731,9 +791,11 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
session.setLastError("Expected flag_keyword");
return res;
}
- } else if ((res = expectThisString("UNSEEN")) == ACCEPT) s_in.name = "UNSEEN";
- else if ((res = expectThisString("DRAFT")) == ACCEPT) s_in.name = "DRAFT";
- else if ((res = expectThisString("HEADER")) == ACCEPT) {
+ } else if ((res = expectThisString("UNSEEN")) == ACCEPT)
+ s_in.name = "UNSEEN";
+ else if ((res = expectThisString("DRAFT")) == ACCEPT)
+ s_in.name = "DRAFT";
+ else if ((res = expectThisString("HEADER")) == ACCEPT) {
s_in.name = "HEADER";
if ((res = expectSPACE()) != ACCEPT) {
@@ -829,7 +891,7 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
}
if ((res = expectDate(s_in.date)) != ACCEPT) {
- session.setLastError("Expected date");
+ session.setLastError("Expected date");
return res;
}
@@ -867,7 +929,7 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
session.setLastError("Expected number");
return res;
}
- } else if ((res = expectThisString("UNDRAFT")) == ACCEPT)
+ } else if ((res = expectThisString("UNDRAFT")) == ACCEPT)
s_in.name = "UNDRAFT";
else if ((res = expectSet(s_in.bset)) == ACCEPT) {
s_in.name = "";
@@ -878,7 +940,7 @@ SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
while (1) {
BincImapParserSearchKey c;
if ((res = expectSearchKey(c)) != ACCEPT) {
- session.setLastError("Expected search_key");
+ session.setLastError("Expected search_key");
return res;
}
diff --git a/src/operator-select.cc b/src/operator-select.cc
index 854783a..64c4be6 100644
--- a/src/operator-select.cc
+++ b/src/operator-select.cc
@@ -4,30 +4,26 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-
+#include "convert.h"
#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
#include "mailbox.h"
#include "operators.h"
-#include "recursivedescent.h"
#include "pendingupdates.h"
+#include "recursivedescent.h"
#include "session.h"
-#include "convert.h"
+
+#include <string>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-SelectOperator::SelectOperator(void)
-{
-}
+SelectOperator::SelectOperator(void) {}
//----------------------------------------------------------------------
-SelectOperator::~SelectOperator(void)
-{
-}
+SelectOperator::~SelectOperator(void) {}
//----------------------------------------------------------------------
const string SelectOperator::getName(void) const
@@ -38,14 +34,11 @@ const string SelectOperator::getName(void) const
//----------------------------------------------------------------------
int SelectOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//------------------------------------------------------------------------
-Operator::ProcessResult SelectOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult SelectOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -68,18 +61,15 @@ Operator::ProcessResult SelectOperator::process(Depot &depot,
mailbox->setReadOnly(examine);
- if (!mailbox->selectMailbox(canonmailbox,
- depot.mailboxToFilename(canonmailbox))) {
- bincWarning << "selecting mailbox failed: "
- << mailbox->getLastError() << endl;
+ if (!mailbox->selectMailbox(canonmailbox, depot.mailboxToFilename(canonmailbox))) {
+ bincWarning << "selecting mailbox failed: " << mailbox->getLastError() << endl;
session.setLastError(mailbox->getLastError());
return NO;
}
// find first unseen
int unseen = -1;
- Mailbox::iterator i = mailbox->begin(SequenceSet::all(),
- Mailbox::SKIP_EXPUNGED | Mailbox::SQNR_MODE);
+ Mailbox::iterator i = mailbox->begin(SequenceSet::all(), Mailbox::SKIP_EXPUNGED | Mailbox::SQNR_MODE);
for (; i != mailbox->end(); ++i) {
Message &message = *i;
@@ -91,32 +81,30 @@ Operator::ProcessResult SelectOperator::process(Depot &depot,
// show pending updates with only exists and recent response. do not
// re-scan.
- pendingUpdates(mailbox, PendingUpdates::EXISTS
- | PendingUpdates::RECENT, false, true);
+ pendingUpdates(mailbox, PendingUpdates::EXISTS | PendingUpdates::RECENT, false, true);
// unseen
if (unseen != -1)
- bincClient << "*" << " OK [UNSEEN " << unseen << "] Message "
- << unseen << " is first unseen" << endl;
+ bincClient << "*"
+ << " OK [UNSEEN " << unseen << "] Message " << unseen << " is first unseen" << endl;
// uidvalidity
- bincClient << "*" << " OK [UIDVALIDITY " << mailbox->getUidValidity() << "]"
- << endl;
+ bincClient << "*"
+ << " OK [UIDVALIDITY " << mailbox->getUidValidity() << "]" << endl;
// uidnext
- bincClient << "*" << " OK [UIDNEXT " << toString(mailbox->getUidNext()) << "] "
- << toString(mailbox->getUidNext()) << " is the next UID" << endl;
+ bincClient << "*"
+ << " OK [UIDNEXT " << toString(mailbox->getUidNext()) << "] "
+ << toString(mailbox->getUidNext()) << " is the next UID" << endl;
// flags
- bincClient << "*"
- << " FLAGS (\\Answered \\Flagged \\Deleted \\Recent \\Seen \\Draft \\*)"
- << endl;
+ bincClient << "*"
+ << " FLAGS (\\Answered \\Flagged \\Deleted \\Recent \\Seen \\Draft \\*)" << endl;
// permanentflags
- bincClient << "*"
- << " OK [PERMANENTFLAGS (\\Answered \\Flagged \\Deleted "
- << "\\Seen \\Draft \\*)] Limited"
- << endl;
+ bincClient << "*"
+ << " OK [PERMANENTFLAGS (\\Answered \\Flagged \\Deleted "
+ << "\\Seen \\Draft \\*)] Limited" << endl;
session.setState(Session::SELECTED);
depot.setSelected(mailbox);
@@ -130,8 +118,7 @@ Operator::ParseResult SelectOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
@@ -139,16 +126,14 @@ Operator::ParseResult SelectOperator::parse(Request &c_in) const
return res;
}
- string mailbox;
+ string mailbox;
if ((res = expectMailbox(mailbox)) != ACCEPT) {
- session.setLastError("Expected mailbox after " + c_in.getName()
- + " SPACE");
+ session.setLastError("Expected mailbox after " + c_in.getName() + " SPACE");
return res;
}
if ((res = expectCRLF()) != ACCEPT) {
- session.setLastError("Expected CRLF after " + c_in.getName()
- + " SPACE mailbox");
+ session.setLastError("Expected CRLF after " + c_in.getName() + " SPACE mailbox");
return res;
}
diff --git a/src/operator-starttls.cc b/src/operator-starttls.cc
index fcc7b3b..3ba5dd0 100644
--- a/src/operator-starttls.cc
+++ b/src/operator-starttls.cc
@@ -1,33 +1,30 @@
/** --------------------------------------------------------------------
* @file operator-starttls.cc
- * @brief Implementation of the STARTTLS command - based on sslserver
+ * @brief Implementation of the STARTTLS command - based on sslserver
* @author Andreas Aardal Hanssen, Erwin Hoffmann
* @date 2002-2005, 2023
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "recursivedescent.h"
+#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "session.h"
-#include "depot.h"
#include "operators.h"
+#include "recursivedescent.h"
+#include "session.h"
+
+#include <iostream>
+#include <string>
+
+#include <fcntl.h>
+#include <unistd.h>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-StarttlsOperator::StarttlsOperator(void)
-{
-}
+StarttlsOperator::StarttlsOperator(void) {}
//----------------------------------------------------------------------
-StarttlsOperator::~StarttlsOperator(void)
-{
-}
+StarttlsOperator::~StarttlsOperator(void) {}
//----------------------------------------------------------------------
const string StarttlsOperator::getName(void) const
@@ -38,13 +35,11 @@ const string StarttlsOperator::getName(void) const
//----------------------------------------------------------------------
int StarttlsOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//----------------------------------------------------------------------
-int StarttlsOperator::goStartTLS (void) const
+int StarttlsOperator::goStartTLS(void) const
{
Session &session = Session::getInstance();
@@ -54,30 +49,29 @@ int StarttlsOperator::goStartTLS (void) const
fdstr = session.getEnv("SSLCTLFD");
fd = std::stoi(fdstr);
- if (write(fd,"Y",1) < 1) return NOTHING;
- bincClient.flush(); // flush all previous received data
+ if (write(fd, "Y", 1) < 1) return NOTHING;
+ bincClient.flush(); // flush all previous received data
fdstr = session.getEnv("SSLREADFD");
fd = std::stoi(fdstr);
- if (fcntl(fd,F_GETFL,0) == -1) return NOTHING;
- close (0);
- if (fcntl(fd,F_DUPFD,0) == -1) return NOTHING;
- close (fd);
+ if (fcntl(fd, F_GETFL, 0) == -1) return NOTHING;
+ close(0);
+ if (fcntl(fd, F_DUPFD, 0) == -1) return NOTHING;
+ close(fd);
fdstr = session.getEnv("SSLWRITEFD");
fd = std::stoi(fdstr);
- if (fcntl(fd,F_GETFL,0) == -1) return NOTHING;
- close (1);
- if (fcntl(fd,F_DUPFD,1) == -1) return NOTHING;
- close (fd);
+ if (fcntl(fd, F_GETFL, 0) == -1) return NOTHING;
+ close(1);
+ if (fcntl(fd, F_DUPFD, 1) == -1) return NOTHING;
+ close(fd);
}
return ACCEPT;
}
//------------------------------------------------------------------------
-Operator::ProcessResult StarttlsOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
if (session.command.ssl) {
@@ -88,9 +82,9 @@ Operator::ProcessResult StarttlsOperator::process(Depot &depot,
bincClient << "* ENABLED StartTLS - begin negotiation now" << endl;
bincClient << command.getTag() << " OK STARTTLS completed" << endl;
- if (goStartTLS() == ACCEPT)
+ if (goStartTLS() == ACCEPT)
session.command.ssl = true;
- else
+ else
return NO;
return NOTHING;
@@ -108,7 +102,7 @@ Operator::ParseResult StarttlsOperator::parse(Request &c_in) const
session.setLastError("Expected CRLF");
return res;
}
-
+
c_in.setName("STARTTLS");
return ACCEPT;
diff --git a/src/operator-status.cc b/src/operator-status.cc
index da74f16..82c3bcf 100644
--- a/src/operator-status.cc
+++ b/src/operator-status.cc
@@ -4,13 +4,6 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
#include "convert.h"
#include "depot.h"
#include "iodevice.h"
@@ -21,18 +14,21 @@
#include "session.h"
#include "status.h"
+#include <iostream>
+#include <string>
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-StatusOperator::StatusOperator(void)
-{
-}
+StatusOperator::StatusOperator(void) {}
//----------------------------------------------------------------------
-StatusOperator::~StatusOperator(void)
-{
-}
+StatusOperator::~StatusOperator(void) {}
//----------------------------------------------------------------------
const string StatusOperator::getName(void) const
@@ -47,8 +43,7 @@ int StatusOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult StatusOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult StatusOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -59,10 +54,9 @@ Operator::ProcessResult StatusOperator::process(Depot &depot,
}
bincClient << "* STATUS " << toImapString(command.getMailbox()) << " (";
-
+
string prefix;
- for (vector<string>::const_iterator i = command.statuses.begin();
- i != command.statuses.end(); ++i) {
+ for (vector<string>::const_iterator i = command.statuses.begin(); i != command.statuses.end(); ++i) {
string tmp = *i;
uppercase(tmp);
if (tmp == "UIDNEXT") {
@@ -72,13 +66,13 @@ Operator::ProcessResult StatusOperator::process(Depot &depot,
bincClient << prefix << "MESSAGES " << status.getMessages();
prefix = " ";
} else if (tmp == "RECENT") {
- bincClient << prefix << "RECENT " << status.getRecent();
+ bincClient << prefix << "RECENT " << status.getRecent();
prefix = " ";
} else if (tmp == "UIDVALIDITY") {
bincClient << prefix << "UIDVALIDITY " << status.getUidValidity();
prefix = " ";
} else if (tmp == "UNSEEN") {
- bincClient << prefix << "UNSEEN " << status.getUnseen();
+ bincClient << prefix << "UNSEEN " << status.getUnseen();
prefix = " ";
}
}
@@ -92,8 +86,7 @@ Operator::ParseResult StatusOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
diff --git a/src/operator-store.cc b/src/operator-store.cc
index efb5a48..b6e1b99 100644
--- a/src/operator-store.cc
+++ b/src/operator-store.cc
@@ -4,9 +4,6 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ------------------------------------------------------------------ **/
-#include <string>
-#include <iostream>
-
#include "depot.h"
#include "imapparser.h"
#include "mailbox.h"
@@ -15,18 +12,17 @@
#include "recursivedescent.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-StoreOperator::StoreOperator(void)
-{
-}
+StoreOperator::StoreOperator(void) {}
//----------------------------------------------------------------------
-StoreOperator::~StoreOperator(void)
-{
-}
+StoreOperator::~StoreOperator(void) {}
//----------------------------------------------------------------------
const string StoreOperator::getName(void) const
@@ -41,38 +37,41 @@ int StoreOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult StoreOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult StoreOperator::process(Depot &depot, Request &command)
{
Mailbox *mailbox = depot.getSelected();
// mask all passed flags together
- unsigned int newflags = (unsigned int) Message::F_NONE;
+ unsigned int newflags = (unsigned int)Message::F_NONE;
vector<string> newCustomFlags;
vector<string>::const_iterator f_i = command.flags.begin();
while (f_i != command.flags.end()) {
- if (*f_i == "\\Deleted") newflags |= Message::F_DELETED;
- else if (*f_i == "\\Answered") newflags |= Message::F_ANSWERED;
- else if (*f_i == "\\Seen") newflags |= Message::F_SEEN;
- else if (*f_i == "\\Draft") newflags |= Message::F_DRAFT;
- else if (*f_i == "\\Flagged") newflags |= Message::F_FLAGGED;
- else newCustomFlags.push_back(*f_i);
+ if (*f_i == "\\Deleted")
+ newflags |= Message::F_DELETED;
+ else if (*f_i == "\\Answered")
+ newflags |= Message::F_ANSWERED;
+ else if (*f_i == "\\Seen")
+ newflags |= Message::F_SEEN;
+ else if (*f_i == "\\Draft")
+ newflags |= Message::F_DRAFT;
+ else if (*f_i == "\\Flagged")
+ newflags |= Message::F_FLAGGED;
+ else
+ newCustomFlags.push_back(*f_i);
++f_i;
}
// pass through all messages
- unsigned int mode
- = command.getUidMode() ? Mailbox::UID_MODE : Mailbox::SQNR_MODE;
+ unsigned int mode = command.getUidMode() ? Mailbox::UID_MODE : Mailbox::SQNR_MODE;
- Mailbox::iterator i
- = mailbox->begin(command.bset, Mailbox::SKIP_EXPUNGED | mode);
+ Mailbox::iterator i = mailbox->begin(command.bset, Mailbox::SKIP_EXPUNGED | mode);
for (; i != mailbox->end(); ++i) {
Message &message = *i;
// get and reset the old flags
- unsigned int flags = (unsigned int) message.getStdFlags();
+ unsigned int flags = (unsigned int)message.getStdFlags();
bool recent = (flags & Message::F_RECENT) != 0;
flags &= (~Message::F_RECENT);
@@ -81,21 +80,18 @@ Operator::ProcessResult StoreOperator::process(Depot &depot,
switch (command.getMode()[0]) {
case '+':
flags |= newflags;
- for (vector<string>::const_iterator it = newCustomFlags.begin();
- it != newCustomFlags.end(); ++it)
- message.setCustomFlag(*it);
+ for (vector<string>::const_iterator it = newCustomFlags.begin(); it != newCustomFlags.end(); ++it)
+ message.setCustomFlag(*it);
break;
case '-':
flags &= ~newflags;
- for (vector<string>::const_iterator it = newCustomFlags.begin();
- it != newCustomFlags.end(); ++it)
+ for (vector<string>::const_iterator it = newCustomFlags.begin(); it != newCustomFlags.end(); ++it)
message.removeCustomFlag(*it);
break;
default:
flags = newflags;
message.resetCustomFlags();
- for (vector<string>::const_iterator it = newCustomFlags.begin();
- it != newCustomFlags.end(); ++it)
+ for (vector<string>::const_iterator it = newCustomFlags.begin(); it != newCustomFlags.end(); ++it)
message.setCustomFlag(*it);
break;
};
@@ -111,21 +107,26 @@ Operator::ProcessResult StoreOperator::process(Depot &depot,
// check mailbox for updates, and report them
if (command.getMode().find(".SILENT") != string::npos)
- pendingUpdates(mailbox, PendingUpdates::EXISTS
- | PendingUpdates::RECENT, false, false, false,
+ pendingUpdates(mailbox,
+ PendingUpdates::EXISTS | PendingUpdates::RECENT,
+ false,
+ false,
+ false,
command.getUidMode());
else
- pendingUpdates(mailbox, PendingUpdates::EXISTS
- | PendingUpdates::RECENT
- | PendingUpdates::EXPUNGE
- | PendingUpdates::FLAGS, false, false, false,
+ pendingUpdates(mailbox,
+ PendingUpdates::EXISTS | PendingUpdates::RECENT | PendingUpdates::EXPUNGE
+ | PendingUpdates::FLAGS,
+ false,
+ false,
+ false,
command.getUidMode());
return OK;
}
//----------------------------------------------------------------------
-Operator::ParseResult StoreOperator::parse(Request & c_in) const
+Operator::ParseResult StoreOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
diff --git a/src/operator-subscribe.cc b/src/operator-subscribe.cc
index a4e77df..7626844 100644
--- a/src/operator-subscribe.cc
+++ b/src/operator-subscribe.cc
@@ -4,29 +4,25 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
#include "convert.h"
-#include <sys/stat.h>
-
-#include "recursivedescent.h"
-
-#include "session.h"
#include "depot.h"
#include "operators.h"
+#include "recursivedescent.h"
+#include "session.h"
+
+#include <iostream>
+#include <string>
+
+#include <sys/stat.h>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-SubscribeOperator::SubscribeOperator(void)
-{
-}
+SubscribeOperator::SubscribeOperator(void) {}
//----------------------------------------------------------------------
-SubscribeOperator::~SubscribeOperator(void)
-{
-}
+SubscribeOperator::~SubscribeOperator(void) {}
//----------------------------------------------------------------------
const string SubscribeOperator::getName(void) const
@@ -41,8 +37,7 @@ int SubscribeOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult SubscribeOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult SubscribeOperator::process(Depot &depot, Request &command)
{
const string &srcmailbox = command.getMailbox();
const string &canonmailbox = toCanonMailbox(srcmailbox);
@@ -59,8 +54,7 @@ Operator::ParseResult SubscribeOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
diff --git a/src/operator-unsubscribe.cc b/src/operator-unsubscribe.cc
index 7ef2bf4..ae900a8 100644
--- a/src/operator-unsubscribe.cc
+++ b/src/operator-unsubscribe.cc
@@ -4,30 +4,26 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <string>
-#include <vector>
-#include <iostream>
#include "convert.h"
-#include <sys/stat.h>
-
-#include "recursivedescent.h"
-
-#include "session.h"
#include "depot.h"
#include "operators.h"
+#include "recursivedescent.h"
+#include "session.h"
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <sys/stat.h>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-UnsubscribeOperator::UnsubscribeOperator(void)
-{
-}
+UnsubscribeOperator::UnsubscribeOperator(void) {}
//----------------------------------------------------------------------
-UnsubscribeOperator::~UnsubscribeOperator(void)
-{
-}
+UnsubscribeOperator::~UnsubscribeOperator(void) {}
//----------------------------------------------------------------------
const string UnsubscribeOperator::getName(void) const
@@ -42,8 +38,7 @@ int UnsubscribeOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult UnsubscribeOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult UnsubscribeOperator::process(Depot &depot, Request &command)
{
const string &mailbox = command.getMailbox();
const string &canonmailbox = toCanonMailbox(mailbox);
@@ -65,8 +60,7 @@ Operator::ParseResult UnsubscribeOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
- if (c_in.getUidMode())
- return REJECT;
+ if (c_in.getUidMode()) return REJECT;
Operator::ParseResult res;
if ((res = expectSPACE()) != ACCEPT) {
diff --git a/src/pendingupdates.cc b/src/pendingupdates.cc
index 0f76526..1e4af8d 100644
--- a/src/pendingupdates.cc
+++ b/src/pendingupdates.cc
@@ -4,17 +4,18 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include <iostream>
-#include <string>
-#include <vector>
+#include "pendingupdates.h"
#include "iodevice.h"
#include "iofactory.h"
#include "mailbox.h"
#include "message.h"
-#include "pendingupdates.h"
#include "session.h"
+#include <iostream>
+#include <string>
+#include <vector>
+
using namespace ::std;
using namespace Binc;
@@ -29,9 +30,7 @@ PendingUpdates::PendingUpdates(void) : expunges(), flagupdates()
}
//------------------------------------------------------------------------
-PendingUpdates::~PendingUpdates(void)
-{
-}
+PendingUpdates::~PendingUpdates(void) {}
//------------------------------------------------------------------------
void PendingUpdates::addExpunged(unsigned int uid)
@@ -40,8 +39,10 @@ void PendingUpdates::addExpunged(unsigned int uid)
}
//------------------------------------------------------------------------
-void PendingUpdates::addFlagUpdates(unsigned int sqnr, unsigned int uid,
- unsigned int flags, const vector<string> &cflags)
+void PendingUpdates::addFlagUpdates(unsigned int sqnr,
+ unsigned int uid,
+ unsigned int flags,
+ const vector<string> &cflags)
{
flagupdates[sqnr] = flags;
sqnrtouid[sqnr] = uid;
@@ -87,35 +88,33 @@ bool PendingUpdates::newRecent(void) const
}
//------------------------------------------------------------------------
-PendingUpdates::expunged_const_iterator::expunged_const_iterator(void)
-{
-}
+PendingUpdates::expunged_const_iterator::expunged_const_iterator(void) {}
//------------------------------------------------------------------------
-PendingUpdates::expunged_const_iterator::expunged_const_iterator(vector<unsigned int>::iterator i) : internal(i)
-{
-}
+PendingUpdates::expunged_const_iterator::expunged_const_iterator(vector<unsigned int>::iterator i)
+ : internal(i)
+{}
//------------------------------------------------------------------------
-unsigned int PendingUpdates::expunged_const_iterator::operator * (void) const
+unsigned int PendingUpdates::expunged_const_iterator::operator*(void) const
{
return *internal;
}
//------------------------------------------------------------------------
-void PendingUpdates::expunged_const_iterator::operator ++ (void)
+void PendingUpdates::expunged_const_iterator::operator++(void)
{
++internal;
}
//------------------------------------------------------------------------
-bool PendingUpdates::expunged_const_iterator::operator == (expunged_const_iterator i) const
+bool PendingUpdates::expunged_const_iterator::operator==(expunged_const_iterator i) const
{
return internal == i.internal;
}
//------------------------------------------------------------------------
-bool PendingUpdates::expunged_const_iterator::operator != (expunged_const_iterator i) const
+bool PendingUpdates::expunged_const_iterator::operator!=(expunged_const_iterator i) const
{
return internal != i.internal;
}
@@ -133,27 +132,27 @@ PendingUpdates::expunged_const_iterator PendingUpdates::endExpunged(void)
}
//------------------------------------------------------------------------
-PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator(void)
-{
-}
+PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator(void) {}
//------------------------------------------------------------------------
PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator(
- map<unsigned int, unsigned int>::iterator i,
- map<unsigned int, vector<string> > *j,
- map<unsigned int, unsigned int> *sqnrmap) : internal(i), sqnrtocflags(j)
+ map<unsigned int, unsigned int>::iterator i,
+ map<unsigned int, vector<string>> *j,
+ map<unsigned int, unsigned int> *sqnrmap)
+ : internal(i)
+ , sqnrtocflags(j)
{
sqnrtouid = sqnrmap;
}
//------------------------------------------------------------------------
-void PendingUpdates::flagupdates_const_iterator::operator ++ (void)
+void PendingUpdates::flagupdates_const_iterator::operator++(void)
{
++internal;
}
//------------------------------------------------------------------------
-bool PendingUpdates::flagupdates_const_iterator::operator != (flagupdates_const_iterator i) const
+bool PendingUpdates::flagupdates_const_iterator::operator!=(flagupdates_const_iterator i) const
{
return internal != i.internal;
}
@@ -195,13 +194,16 @@ unsigned int PendingUpdates::flagupdates_const_iterator::getUID(void) const
}
//--------------------------------------------------------------------
-bool Binc::pendingUpdates(Mailbox *mailbox, int type, bool rescan, bool showAll,
- bool forceScan, bool uidfetchflags)
+bool Binc::pendingUpdates(Mailbox *mailbox,
+ int type,
+ bool rescan,
+ bool showAll,
+ bool forceScan,
+ bool uidfetchflags)
{
Session &session = Session::getInstance();
- if (mailbox == 0)
- return true;
+ if (mailbox == 0) return true;
PendingUpdates p;
if (!mailbox->getUpdates(rescan, type, p, forceScan)) {
@@ -241,15 +243,13 @@ bool Binc::pendingUpdates(Mailbox *mailbox, int type, bool rescan, bool showAll,
if (flags & Message::F_FLAGGED) flagv.push_back("\\Flagged");
bincClient << "* " << i.first() << " FETCH (FLAGS (";
- for (vector<string>::const_iterator k
- = flagv.begin(); k != flagv.end(); ++k) {
+ for (vector<string>::const_iterator k = flagv.begin(); k != flagv.end(); ++k) {
if (k != flagv.begin()) bincClient << " ";
bincClient << *k;
}
vector<string> customFlags = i.getCustomFlags();
- for (vector<string>::const_iterator it = customFlags.begin();
- it != customFlags.end(); ++it) {
+ for (vector<string>::const_iterator it = customFlags.begin(); it != customFlags.end(); ++it) {
if (flagv.size() > 0 || it != customFlags.begin()) bincClient << " ";
bincClient << *it;
}
diff --git a/src/recursivedescent.cc b/src/recursivedescent.cc
index be9c560..0f0cf8d 100644
--- a/src/recursivedescent.cc
+++ b/src/recursivedescent.cc
@@ -4,18 +4,20 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ----------------------------------------------------------------- **/
-#include "imapparser.h"
#include "recursivedescent.h"
+
+#include "convert.h"
+#include "imapparser.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "convert.h"
#include "session.h"
-#include <stdio.h>
-#include <ctype.h>
-#include <stack>
-#include <iostream>
#include <iomanip>
+#include <iostream>
+#include <stack>
+
+#include <ctype.h>
+#include <stdio.h>
using namespace ::std;
using namespace Binc;
@@ -23,7 +25,6 @@ using namespace Binc;
stack<int> Binc::inputBuffer;
int Binc::charnr = 0;
-
//----------------------------------------------------------------------
Operator::ParseResult Binc::expectThisString(const string &s_in)
{
@@ -33,7 +34,6 @@ Operator::ParseResult Binc::expectThisString(const string &s_in)
bool match = true;
for (string::const_iterator i = s_in.begin(); i != s_in.end(); ++i) {
-
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
@@ -49,7 +49,7 @@ Operator::ParseResult Binc::expectThisString(const string &s_in)
break;
}
}
-
+
if (!match) {
bincClient.unreadStr(tmp);
return Operator::REJECT;
@@ -62,8 +62,7 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
{
Session &session = Session::getInstance();
- if (expectThisString("\"") != Operator::ACCEPT)
- return Operator::REJECT;
+ if (expectThisString("\"") != Operator::ACCEPT) return Operator::REJECT;
unsigned int digit1, digit2;
if (expectSPACE() == Operator::ACCEPT) {
@@ -89,8 +88,7 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
BincStream daystr;
- if (day < 10)
- daystr << '0';
+ if (day < 10) daystr << '0';
daystr << day;
s_in += daystr.str();
@@ -104,18 +102,30 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
s_in += "-";
/* month */
- if ((res = expectThisString("Jan")) == Operator::ACCEPT) s_in += "Jan";
- else if ((res = expectThisString("Feb")) == Operator::ACCEPT) s_in += "Feb";
- else if ((res = expectThisString("Mar")) == Operator::ACCEPT) s_in += "Mar";
- else if ((res = expectThisString("Apr")) == Operator::ACCEPT) s_in += "Apr";
- else if ((res = expectThisString("May")) == Operator::ACCEPT) s_in += "May";
- else if ((res = expectThisString("Jun")) == Operator::ACCEPT) s_in += "Jun";
- else if ((res = expectThisString("Jul")) == Operator::ACCEPT) s_in += "Jul";
- else if ((res = expectThisString("Aug")) == Operator::ACCEPT) s_in += "Aug";
- else if ((res = expectThisString("Sep")) == Operator::ACCEPT) s_in += "Sep";
- else if ((res = expectThisString("Oct")) == Operator::ACCEPT) s_in += "Oct";
- else if ((res = expectThisString("Nov")) == Operator::ACCEPT) s_in += "Nov";
- else if ((res = expectThisString("Dec")) == Operator::ACCEPT) s_in += "Dec";
+ if ((res = expectThisString("Jan")) == Operator::ACCEPT)
+ s_in += "Jan";
+ else if ((res = expectThisString("Feb")) == Operator::ACCEPT)
+ s_in += "Feb";
+ else if ((res = expectThisString("Mar")) == Operator::ACCEPT)
+ s_in += "Mar";
+ else if ((res = expectThisString("Apr")) == Operator::ACCEPT)
+ s_in += "Apr";
+ else if ((res = expectThisString("May")) == Operator::ACCEPT)
+ s_in += "May";
+ else if ((res = expectThisString("Jun")) == Operator::ACCEPT)
+ s_in += "Jun";
+ else if ((res = expectThisString("Jul")) == Operator::ACCEPT)
+ s_in += "Jul";
+ else if ((res = expectThisString("Aug")) == Operator::ACCEPT)
+ s_in += "Aug";
+ else if ((res = expectThisString("Sep")) == Operator::ACCEPT)
+ s_in += "Sep";
+ else if ((res = expectThisString("Oct")) == Operator::ACCEPT)
+ s_in += "Oct";
+ else if ((res = expectThisString("Nov")) == Operator::ACCEPT)
+ s_in += "Nov";
+ else if ((res = expectThisString("Dec")) == Operator::ACCEPT)
+ s_in += "Dec";
else {
session.setLastError("expected month");
return res;
@@ -126,7 +136,7 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
return res;
}
- s_in += "-";
+ s_in += "-";
/* year */
unsigned int year, c;
@@ -157,7 +167,7 @@ Operator::ParseResult Binc::expectDateTime(string &s_in)
year = (year * 10) + c;
BincStream yearstr;
-
+
yearstr << year;
s_in += yearstr.str();
@@ -201,8 +211,7 @@ Operator::ParseResult Binc::expectTime(string &s_in)
unsigned int c, t;
Operator::ParseResult res;
- if ((res = expectDigit(t)) != Operator::ACCEPT)
- return res;
+ if ((res = expectDigit(t)) != Operator::ACCEPT) return res;
if ((res = expectDigit(c)) != Operator::ACCEPT) {
session.setLastError("expected digit");
@@ -315,7 +324,7 @@ Operator::ParseResult Binc::expectZone(string &s_in)
tstr << t;
s_in += tstr.str();
-
+
return Operator::ACCEPT;
}
@@ -337,15 +346,14 @@ Operator::ParseResult Binc::expectListWildcards(int &c_in)
Operator::ParseResult Binc::expectListMailbox(string &s_in)
{
Operator::ParseResult res;
- if ((res = expectString(s_in)) == Operator::ACCEPT)
- return Operator::ACCEPT;
-
+ if ((res = expectString(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
+
int c;
- if ((res = expectAtomChar(c)) == Operator::ACCEPT
- || (res = expectListWildcards(c)) == Operator::ACCEPT
- || (res = expectThisString("]")) == Operator::ACCEPT) {
+ if ((res = expectAtomChar(c)) == Operator::ACCEPT || (res = expectListWildcards(c)) == Operator::ACCEPT
+ || (res = expectThisString("]")) == Operator::ACCEPT)
+ {
do {
- s_in += (char) c;
+ s_in += (char)c;
if ((res = expectAtomChar(c)) != Operator::ACCEPT
&& (res = expectListWildcards(c)) != Operator::ACCEPT
&& (res = expectThisString("]")) != Operator::ACCEPT)
@@ -369,9 +377,9 @@ Operator::ParseResult Binc::expectFlag(vector<string> &v_in)
v_in.push_back("\\Answered");
else if ((res = expectThisString("\\Flagged")) == Operator::ACCEPT)
v_in.push_back("\\Flagged");
- else if ((res = expectThisString("\\Deleted")) == Operator::ACCEPT)
+ else if ((res = expectThisString("\\Deleted")) == Operator::ACCEPT)
v_in.push_back("\\Deleted");
- else if ((res = expectThisString("\\Seen")) == Operator::ACCEPT)
+ else if ((res = expectThisString("\\Seen")) == Operator::ACCEPT)
v_in.push_back("\\Seen");
else if ((res = expectThisString("\\Draft")) == Operator::ACCEPT)
v_in.push_back("\\Draft");
@@ -402,15 +410,13 @@ Operator::ParseResult Binc::expectDate(string &s_in)
Operator::ParseResult res;
bool quoted = false;
- if ((res = expectThisString("\"")) == Operator::ACCEPT)
- quoted = true;
+ if ((res = expectThisString("\"")) == Operator::ACCEPT) quoted = true;
/* day */
unsigned int day, c;
if ((res = expectDigit(c)) == Operator::ACCEPT) {
day = c;
- if ((res = expectDigit(c)) == Operator::ACCEPT)
- day = (day * 10) + c;
+ if ((res = expectDigit(c)) == Operator::ACCEPT) day = (day * 10) + c;
BincStream daystr;
@@ -431,23 +437,35 @@ Operator::ParseResult Binc::expectDate(string &s_in)
s_in += '-';
/* month */
- if ((res = expectThisString("Jan")) == Operator::ACCEPT) s_in += "Jan";
- else if ((res = expectThisString("Feb")) == Operator::ACCEPT) s_in += "Feb";
- else if ((res = expectThisString("Mar")) == Operator::ACCEPT) s_in += "Mar";
- else if ((res = expectThisString("Apr")) == Operator::ACCEPT) s_in += "Apr";
- else if ((res = expectThisString("May")) == Operator::ACCEPT) s_in += "May";
- else if ((res = expectThisString("Jun")) == Operator::ACCEPT) s_in += "Jun";
- else if ((res = expectThisString("Jul")) == Operator::ACCEPT) s_in += "Jul";
- else if ((res = expectThisString("Aug")) == Operator::ACCEPT) s_in += "Aug";
- else if ((res = expectThisString("Sep")) == Operator::ACCEPT) s_in += "Sep";
- else if ((res = expectThisString("Oct")) == Operator::ACCEPT) s_in += "Oct";
- else if ((res = expectThisString("Nov")) == Operator::ACCEPT) s_in += "Nov";
- else if ((res = expectThisString("Dec")) == Operator::ACCEPT) s_in += "Dec";
+ if ((res = expectThisString("Jan")) == Operator::ACCEPT)
+ s_in += "Jan";
+ else if ((res = expectThisString("Feb")) == Operator::ACCEPT)
+ s_in += "Feb";
+ else if ((res = expectThisString("Mar")) == Operator::ACCEPT)
+ s_in += "Mar";
+ else if ((res = expectThisString("Apr")) == Operator::ACCEPT)
+ s_in += "Apr";
+ else if ((res = expectThisString("May")) == Operator::ACCEPT)
+ s_in += "May";
+ else if ((res = expectThisString("Jun")) == Operator::ACCEPT)
+ s_in += "Jun";
+ else if ((res = expectThisString("Jul")) == Operator::ACCEPT)
+ s_in += "Jul";
+ else if ((res = expectThisString("Aug")) == Operator::ACCEPT)
+ s_in += "Aug";
+ else if ((res = expectThisString("Sep")) == Operator::ACCEPT)
+ s_in += "Sep";
+ else if ((res = expectThisString("Oct")) == Operator::ACCEPT)
+ s_in += "Oct";
+ else if ((res = expectThisString("Nov")) == Operator::ACCEPT)
+ s_in += "Nov";
+ else if ((res = expectThisString("Dec")) == Operator::ACCEPT)
+ s_in += "Dec";
else {
session.setLastError("expected month");
return res;
}
-
+
/* - */
if ((res = expectThisString("-")) != Operator::ACCEPT) {
session.setLastError("expected -");
@@ -495,7 +513,7 @@ Operator::ParseResult Binc::expectDate(string &s_in)
session.setLastError("expected \"");
return res;
}
-
+
return Operator::ACCEPT;
}
@@ -503,8 +521,7 @@ Operator::ParseResult Binc::expectDate(string &s_in)
Operator::ParseResult Binc::expectCRLF(void)
{
Operator::ParseResult res;
- if ((res = expectCR()) == Operator::ACCEPT
- && (res = expectLF()) == Operator::ACCEPT)
+ if ((res = expectCR()) == Operator::ACCEPT && (res = expectLF()) == Operator::ACCEPT)
return Operator::ACCEPT;
else
return res;
@@ -519,8 +536,7 @@ Operator::ParseResult Binc::expectCR(void)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
@@ -541,8 +557,7 @@ Operator::ParseResult Binc::expectLF(void)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
@@ -558,38 +573,108 @@ Operator::ParseResult Binc::expectLF(void)
Operator::ParseResult Binc::expectTagChar(int &c_in)
{
Session &session = Session::getInstance();
-
+
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
switch (c) {
- case 041: case 043: case 044: case 046: case 047: case 054:
- case 055: case 056: case 057: case 060: case 061: case 062:
- case 063: case 064: case 065: case 066: case 067: case 070:
- case 071: case 072: case 073: case 074: case 075: case 076:
- case 077: case 0100: case 0101: case 0102: case 0103: case 0104:
- case 0105: case 0106: case 0107: case 0110: case 0111: case 0112:
- case 0113: case 0114: case 0115: case 0116: case 0117: case 0120:
- case 0121: case 0122: case 0123: case 0124: case 0125: case 0126:
- case 0127: case 0130: case 0131: case 0132: case 0133: case 0135:
- case 0136: case 0137: case 0140: case 0141: case 0142: case 0143:
- case 0144: case 0145: case 0146: case 0147: case 0150: case 0151:
- case 0152: case 0153: case 0154: case 0155: case 0156: case 0157:
- case 0160: case 0161: case 0162: case 0163: case 0164: case 0165:
- case 0166: case 0167: case 0170: case 0171: case 0172: case 0174:
- case 0175: case 0176:
+ case 041:
+ case 043:
+ case 044:
+ case 046:
+ case 047:
+ case 054:
+ case 055:
+ case 056:
+ case 057:
+ case 060:
+ case 061:
+ case 062:
+ case 063:
+ case 064:
+ case 065:
+ case 066:
+ case 067:
+ case 070:
+ case 071:
+ case 072:
+ case 073:
+ case 074:
+ case 075:
+ case 076:
+ case 077:
+ case 0100:
+ case 0101:
+ case 0102:
+ case 0103:
+ case 0104:
+ case 0105:
+ case 0106:
+ case 0107:
+ case 0110:
+ case 0111:
+ case 0112:
+ case 0113:
+ case 0114:
+ case 0115:
+ case 0116:
+ case 0117:
+ case 0120:
+ case 0121:
+ case 0122:
+ case 0123:
+ case 0124:
+ case 0125:
+ case 0126:
+ case 0127:
+ case 0130:
+ case 0131:
+ case 0132:
+ case 0133:
+ case 0135:
+ case 0136:
+ case 0137:
+ case 0140:
+ case 0141:
+ case 0142:
+ case 0143:
+ case 0144:
+ case 0145:
+ case 0146:
+ case 0147:
+ case 0150:
+ case 0151:
+ case 0152:
+ case 0153:
+ case 0154:
+ case 0155:
+ case 0156:
+ case 0157:
+ case 0160:
+ case 0161:
+ case 0162:
+ case 0163:
+ case 0164:
+ case 0165:
+ case 0166:
+ case 0167:
+ case 0170:
+ case 0171:
+ case 0172:
+ case 0174:
+ case 0175:
+ case 0176:
c_in = c;
return Operator::ACCEPT;
default:
break;
}
-
+
bincClient.unreadChar(c);
return Operator::REJECT;
@@ -643,8 +728,7 @@ Operator::ParseResult Binc::expectSPACE(void)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
@@ -667,11 +751,9 @@ Operator::ParseResult Binc::expectMailbox(string &s_in)
Operator::ParseResult Binc::expectAstring(string &s_in)
{
Operator::ParseResult res;
- if ((res = expectAtom(s_in)) == Operator::ACCEPT)
- return Operator::ACCEPT;
+ if ((res = expectAtom(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
- if ((res = expectString(s_in)) == Operator::ACCEPT)
- return Operator::ACCEPT;
+ if ((res = expectString(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
return res;
}
@@ -685,33 +767,104 @@ Operator::ParseResult Binc::expectAtomChar(int &c_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
switch (c) {
- case 041: case 043: case 044: case 046: case 047: case 053:
- case 054: case 055: case 056: case 057: case 060: case 061:
- case 062: case 063: case 064: case 065: case 066: case 067:
- case 070: case 071: case 072: case 073: case 074: case 075:
- case 076: case 077: case 0100: case 0101: case 0102: case 0103:
- case 0104: case 0105: case 0106: case 0107: case 0110: case 0111:
- case 0112: case 0113: case 0114: case 0115: case 0116: case 0117:
- case 0120: case 0121: case 0122: case 0123: case 0124: case 0125:
- case 0126: case 0127: case 0130: case 0131: case 0132: case 0133:
- case 0135: case 0136: case 0137: case 0140: case 0141: case 0142:
- case 0143: case 0144: case 0145: case 0146: case 0147: case 0150:
- case 0151: case 0152: case 0153: case 0154: case 0155: case 0156:
- case 0157: case 0160: case 0161: case 0162: case 0163: case 0164:
- case 0165: case 0166: case 0167: case 0170: case 0171: case 0172:
- case 0174: case 0175: case 0176:
+ case 041:
+ case 043:
+ case 044:
+ case 046:
+ case 047:
+ case 053:
+ case 054:
+ case 055:
+ case 056:
+ case 057:
+ case 060:
+ case 061:
+ case 062:
+ case 063:
+ case 064:
+ case 065:
+ case 066:
+ case 067:
+ case 070:
+ case 071:
+ case 072:
+ case 073:
+ case 074:
+ case 075:
+ case 076:
+ case 077:
+ case 0100:
+ case 0101:
+ case 0102:
+ case 0103:
+ case 0104:
+ case 0105:
+ case 0106:
+ case 0107:
+ case 0110:
+ case 0111:
+ case 0112:
+ case 0113:
+ case 0114:
+ case 0115:
+ case 0116:
+ case 0117:
+ case 0120:
+ case 0121:
+ case 0122:
+ case 0123:
+ case 0124:
+ case 0125:
+ case 0126:
+ case 0127:
+ case 0130:
+ case 0131:
+ case 0132:
+ case 0133:
+ case 0135:
+ case 0136:
+ case 0137:
+ case 0140:
+ case 0141:
+ case 0142:
+ case 0143:
+ case 0144:
+ case 0145:
+ case 0146:
+ case 0147:
+ case 0150:
+ case 0151:
+ case 0152:
+ case 0153:
+ case 0154:
+ case 0155:
+ case 0156:
+ case 0157:
+ case 0160:
+ case 0161:
+ case 0162:
+ case 0163:
+ case 0164:
+ case 0165:
+ case 0166:
+ case 0167:
+ case 0170:
+ case 0171:
+ case 0172:
+ case 0174:
+ case 0175:
+ case 0176:
c_in = c;
return Operator::ACCEPT;
default:
break;
}
-
+
bincClient.unreadChar(c);
return Operator::REJECT;
}
@@ -739,11 +892,9 @@ Operator::ParseResult Binc::expectAtom(string &s_in)
Operator::ParseResult Binc::expectString(string &s_in)
{
Operator::ParseResult res;
- if ((res = expectQuoted(s_in)) == Operator::ACCEPT)
- return Operator::ACCEPT;
+ if ((res = expectQuoted(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
- if ((res = expectLiteral(s_in)) == Operator::ACCEPT)
- return Operator::ACCEPT;
+ if ((res = expectLiteral(s_in)) == Operator::ACCEPT) return Operator::ACCEPT;
return res;
}
@@ -755,9 +906,8 @@ Operator::ParseResult Binc::expectQuoted(string &s_in)
int quotedchar;
Operator::ParseResult res;
- if ((res = expectThisString("\"")) != Operator::ACCEPT)
- return res;
-
+ if ((res = expectThisString("\"")) != Operator::ACCEPT) return res;
+
while ((res = expectQuotedChar(quotedchar)) == Operator::ACCEPT)
quoted += quotedchar;
@@ -779,28 +929,134 @@ Operator::ParseResult Binc::expectQuotedChar(int &c_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
switch (c) {
- case 01: case 02: case 03: case 04: case 05: case 06: case 07:
- case 010: case 011: case 013: case 014: case 016: case 017:
- case 020: case 021: case 022: case 023: case 024: case 025: case 026: case 027:
- case 030: case 031: case 032: case 033: case 034: case 035: case 036: case 037:
- case 040: case 041: case 043: case 044: case 045: case 046: case 047:
- case 050: case 051: case 052: case 053: case 054: case 055: case 056: case 057:
- case 060: case 061: case 062: case 063: case 064: case 065: case 066: case 067:
- case 070: case 071: case 072: case 073: case 074: case 075: case 076: case 077:
- case 0100: case 0101: case 0102: case 0103: case 0104: case 0105: case 0106: case 0107:
- case 0110: case 0111: case 0112: case 0113: case 0114: case 0115: case 0116: case 0117:
- case 0120: case 0121: case 0122: case 0123: case 0124: case 0125: case 0126: case 0127:
- case 0130: case 0131: case 0132: case 0133: case 0135: case 0136: case 0137:
- case 0140: case 0141: case 0142: case 0143: case 0144: case 0145: case 0146: case 0147:
- case 0150: case 0151: case 0152: case 0153: case 0154: case 0155: case 0156: case 0157:
- case 0160: case 0161: case 0162: case 0163: case 0164: case 0165: case 0166: case 0167:
- case 0170: case 0171: case 0172: case 0173: case 0174: case 0175: case 0176: case 0177:
+ case 01:
+ case 02:
+ case 03:
+ case 04:
+ case 05:
+ case 06:
+ case 07:
+ case 010:
+ case 011:
+ case 013:
+ case 014:
+ case 016:
+ case 017:
+ case 020:
+ case 021:
+ case 022:
+ case 023:
+ case 024:
+ case 025:
+ case 026:
+ case 027:
+ case 030:
+ case 031:
+ case 032:
+ case 033:
+ case 034:
+ case 035:
+ case 036:
+ case 037:
+ case 040:
+ case 041:
+ case 043:
+ case 044:
+ case 045:
+ case 046:
+ case 047:
+ case 050:
+ case 051:
+ case 052:
+ case 053:
+ case 054:
+ case 055:
+ case 056:
+ case 057:
+ case 060:
+ case 061:
+ case 062:
+ case 063:
+ case 064:
+ case 065:
+ case 066:
+ case 067:
+ case 070:
+ case 071:
+ case 072:
+ case 073:
+ case 074:
+ case 075:
+ case 076:
+ case 077:
+ case 0100:
+ case 0101:
+ case 0102:
+ case 0103:
+ case 0104:
+ case 0105:
+ case 0106:
+ case 0107:
+ case 0110:
+ case 0111:
+ case 0112:
+ case 0113:
+ case 0114:
+ case 0115:
+ case 0116:
+ case 0117:
+ case 0120:
+ case 0121:
+ case 0122:
+ case 0123:
+ case 0124:
+ case 0125:
+ case 0126:
+ case 0127:
+ case 0130:
+ case 0131:
+ case 0132:
+ case 0133:
+ case 0135:
+ case 0136:
+ case 0137:
+ case 0140:
+ case 0141:
+ case 0142:
+ case 0143:
+ case 0144:
+ case 0145:
+ case 0146:
+ case 0147:
+ case 0150:
+ case 0151:
+ case 0152:
+ case 0153:
+ case 0154:
+ case 0155:
+ case 0156:
+ case 0157:
+ case 0160:
+ case 0161:
+ case 0162:
+ case 0163:
+ case 0164:
+ case 0165:
+ case 0166:
+ case 0167:
+ case 0170:
+ case 0171:
+ case 0172:
+ case 0173:
+ case 0174:
+ case 0175:
+ case 0176:
+ case 0177:
c_in = c;
return Operator::ACCEPT;
case '\\': {
@@ -824,7 +1080,7 @@ Operator::ParseResult Binc::expectQuotedChar(int &c_in)
default:
break;
}
-
+
bincClient.unreadChar(c);
return Operator::REJECT;
}
@@ -850,8 +1106,7 @@ Operator::ParseResult Binc::expectLiteral(string &s_in)
// sent by the client with an extra '+' appended after the octet
// count.
bool literalPlus = false;
- if ((res = expectThisString("+")) == Operator::ACCEPT)
- literalPlus = true;
+ if ((res = expectThisString("+")) == Operator::ACCEPT) literalPlus = true;
if ((res = expectThisString("}")) != Operator::ACCEPT) {
session.setLastError("expected }");
@@ -900,9 +1155,8 @@ Operator::ParseResult Binc::expectNumber(unsigned int &i_in)
i_in = (i_in * 10) + n;
}
- if (res == Operator::TIMEOUT)
- return res;
-
+ if (res == Operator::TIMEOUT) return res;
+
return Operator::ACCEPT;
}
@@ -915,8 +1169,7 @@ Operator::ParseResult Binc::expectDigit(unsigned int &i_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
@@ -926,8 +1179,7 @@ Operator::ParseResult Binc::expectDigit(unsigned int &i_in)
} else
bincClient.unreadChar(c);
- if (expectDigitNZ(i_in) != Operator::ACCEPT)
- return Operator::REJECT;
+ if (expectDigitNZ(i_in) != Operator::ACCEPT) return Operator::REJECT;
return Operator::ACCEPT;
}
@@ -940,23 +1192,40 @@ Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in)
char c;
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
-
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
switch (c) {
- case '1': i_in = 1; break;
- case '2': i_in = 2; break;
- case '3': i_in = 3; break;
- case '4': i_in = 4; break;
- case '5': i_in = 5; break;
- case '6': i_in = 6; break;
- case '7': i_in = 7; break;
- case '8': i_in = 8; break;
- case '9': i_in = 9; break;
- case -1:
+ case '1':
+ i_in = 1;
+ break;
+ case '2':
+ i_in = 2;
+ break;
+ case '3':
+ i_in = 3;
+ break;
+ case '4':
+ i_in = 4;
+ break;
+ case '5':
+ i_in = 5;
+ break;
+ case '6':
+ i_in = 6;
+ break;
+ case '7':
+ i_in = 7;
+ break;
+ case '8':
+ i_in = 8;
+ break;
+ case '9':
+ i_in = 9;
+ break;
+ case -1:
session.setLastError(bincClient.getLastErrorString());
return Operator::ERROR;
case -2:
@@ -965,7 +1234,7 @@ Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in)
bincClient.unreadChar(c);
return Operator::REJECT;
}
-
+
return Operator::ACCEPT;
}
@@ -973,14 +1242,13 @@ Operator::ParseResult Binc::expectDigitNZ(unsigned int &i_in)
Operator::ParseResult Binc::expectSet(SequenceSet &s_in)
{
Session &session = Session::getInstance();
- unsigned int seqnum = (unsigned int) -1;
-
+ unsigned int seqnum = (unsigned int)-1;
+
Operator::ParseResult res;
/* if a set does not start with a sequencenum, then it's not a
* set. :-) seqnum == -1 means '*'. */
- if ((res = expectSequenceNum(seqnum)) != Operator::ACCEPT)
- return res;
+ if ((res = expectSequenceNum(seqnum)) != Operator::ACCEPT) return res;
/* the first number is always a part of the set */
s_in.addNumber(seqnum);
@@ -989,7 +1257,7 @@ Operator::ParseResult Binc::expectSet(SequenceSet &s_in)
* sequencenum after the colon. if not, it's a syntax error. a
* colon delimits two numbers in a range. */
if ((res = expectThisString(":")) == Operator::ACCEPT) {
- unsigned int seqnum2 = (unsigned int) -1;
+ unsigned int seqnum2 = (unsigned int)-1;
if ((res = expectSequenceNum(seqnum2)) != Operator::ACCEPT) {
session.setLastError("expected sequencenum");
return res;
@@ -1018,13 +1286,12 @@ Operator::ParseResult Binc::expectSequenceNum(unsigned int &i_in)
if (!bincClient.readChar(&c)) {
session.setLastError(bincClient.getLastErrorString());
- if (bincClient.getLastError() == IODevice::Timeout)
- return Operator::TIMEOUT;
+ if (bincClient.getLastError() == IODevice::Timeout) return Operator::TIMEOUT;
return Operator::ERROR;
}
if (c == '*') {
- i_in = (unsigned int) -1;
+ i_in = (unsigned int)-1;
return Operator::ACCEPT;
} else
bincClient.unreadChar(c);
@@ -1041,15 +1308,13 @@ Operator::ParseResult Binc::expectNZNumber(unsigned int &i_in)
unsigned int c;
Operator::ParseResult res;
- if ((res = expectDigitNZ(c)) != Operator::ACCEPT)
- return res;
+ if ((res = expectDigitNZ(c)) != Operator::ACCEPT) return res;
i_in = c;
while ((res = expectDigit(c)) == Operator::ACCEPT)
i_in = (i_in * 10) + c;
- if (res == Operator::TIMEOUT)
- return res;
+ if (res == Operator::TIMEOUT) return res;
return Operator::ACCEPT;
}
diff --git a/src/regmatch.cc b/src/regmatch.cc
index c433087..6e4b261 100644
--- a/src/regmatch.cc
+++ b/src/regmatch.cc
@@ -5,12 +5,14 @@
* @date 2002-2005
* ----------------------------------------------------------------- **/
#include "regmatch.h"
+
#include <string>
-#include <sys/types.h>
-#include <regex.h>
#include <stdio.h>
+#include <regex.h>
+#include <sys/types.h>
+
using namespace ::std;
//------------------------------------------------------------------------
@@ -19,8 +21,7 @@ int Binc::regexMatch(const string &data_in, const string &p_in)
regex_t r;
regmatch_t rm[2];
- if (regcomp(&r, p_in.c_str(), REG_EXTENDED | REG_NOSUB) != 0)
- return 2;
+ if (regcomp(&r, p_in.c_str(), REG_EXTENDED | REG_NOSUB) != 0) return 2;
int n = regexec(&r, data_in.c_str(), data_in.length(), rm, 0);
regfree(&r);
diff --git a/src/session-initialize-bincimap-up.cc b/src/session-initialize-bincimap-up.cc
index e6a817f..12c099c 100644
--- a/src/session-initialize-bincimap-up.cc
+++ b/src/session-initialize-bincimap-up.cc
@@ -1,26 +1,27 @@
/** --------------------------------------------------------------------
* @file session-initialize-bincimap-up.cc
- * @brief bincimap-up requires sslserver
+ * @brief bincimap-up requires sslserver
* @author Andreas Aardal Hanssen, Erwin Hoffmann
- * @date 2002-2005, 2023
+ * @date 2002-2005, 2023
* ----------------------------------------------------------------- **/
-#include <syslog.h>
-#include <ctype.h>
-
#include "broker.h"
#include "convert.h"
#include "globals.h"
#include "iodevice.h"
#include "iofactory.h"
#include "multilogdevice.h"
-#include "syslogdevice.h"
-#include "stdiodevice.h"
#include "session.h"
+#include "stdiodevice.h"
+#include "syslogdevice.h"
#include "tools.h"
-#include <fcntl.h>
-#include <string>
#include <map>
+#include <string>
+
+#include <ctype.h>
+
+#include <fcntl.h>
+#include <syslog.h>
using namespace ::std;
using namespace Binc;
@@ -42,8 +43,7 @@ bool Session::initialize(int argc, char *argv[])
IOFactory::getLogger().clearFlags(IODevice::FlushesOnEndl);
// Read command line arguments
- if (!session.parseCommandLine(argc, argv))
- return false;
+ if (!session.parseCommandLine(argc, argv)) return false;
// Show help if asked for it
if (session.command.help) {
@@ -53,7 +53,7 @@ bool Session::initialize(int argc, char *argv[])
// Show version if asked for it
if (session.command.version) {
- printf("Binc IMAP v" BINC_VERSION"\n");
+ printf("Binc IMAP v" BINC_VERSION "\n");
return false;
}
@@ -61,16 +61,16 @@ bool Session::initialize(int argc, char *argv[])
session.assignCommandLineArgs();
// for log input
- string ip = getenv("TCP6REMOTEIP") ? getenv("TCP6REMOTEIP") :
- getenv("TCPREMOTEIP") ? getenv("TCPREMOTEIP") : "?";
+ string ip = getenv("TCP6REMOTEIP") ? getenv("TCP6REMOTEIP")
+ : getenv("TCPREMOTEIP") ? getenv("TCPREMOTEIP")
+ : "?";
session.setIP(ip);
string logtype = session.getEnv("LOG_TYPE");
lowercase(logtype);
trim(logtype);
if (logtype == "" || logtype == "multilog") {
- MultilogDevice *device = new MultilogDevice(IODevice::IsEnabled
- | IODevice::FlushesOnEndl);
+ MultilogDevice *device = new MultilogDevice(IODevice::IsEnabled | IODevice::FlushesOnEndl);
ioFactory.addDevice(device);
} else if (logtype == "syslog") {
const string f = session.getEnv("SYSLOG_FACILITY");
@@ -79,20 +79,29 @@ bool Session::initialize(int argc, char *argv[])
if (isdigit(f[0])) {
facility = atoi(f);
} else {
- if (f == "LOG_USER") facility = LOG_USER;
- else if (f == "LOG_LOCAL0") facility = LOG_LOCAL0;
- else if (f == "LOG_LOCAL1") facility = LOG_LOCAL1;
- else if (f == "LOG_LOCAL2") facility = LOG_LOCAL2;
- else if (f == "LOG_LOCAL3") facility = LOG_LOCAL3;
- else if (f == "LOG_LOCAL4") facility = LOG_LOCAL4;
- else if (f == "LOG_LOCAL5") facility = LOG_LOCAL5;
- else if (f == "LOG_LOCAL6") facility = LOG_LOCAL6;
- else if (f == "LOG_LOCAL7") facility = LOG_LOCAL7;
- else facility = LOG_DAEMON;
+ if (f == "LOG_USER")
+ facility = LOG_USER;
+ else if (f == "LOG_LOCAL0")
+ facility = LOG_LOCAL0;
+ else if (f == "LOG_LOCAL1")
+ facility = LOG_LOCAL1;
+ else if (f == "LOG_LOCAL2")
+ facility = LOG_LOCAL2;
+ else if (f == "LOG_LOCAL3")
+ facility = LOG_LOCAL3;
+ else if (f == "LOG_LOCAL4")
+ facility = LOG_LOCAL4;
+ else if (f == "LOG_LOCAL5")
+ facility = LOG_LOCAL5;
+ else if (f == "LOG_LOCAL6")
+ facility = LOG_LOCAL6;
+ else if (f == "LOG_LOCAL7")
+ facility = LOG_LOCAL7;
+ else
+ facility = LOG_DAEMON;
}
- SyslogDevice *device = new SyslogDevice(IODevice::IsEnabled
- | IODevice::FlushesOnEndl,
+ SyslogDevice *device = new SyslogDevice(IODevice::IsEnabled | IODevice::FlushesOnEndl,
"bincimap-up",
LOG_NDELAY | LOG_PID,
facility);
@@ -112,10 +121,10 @@ bool Session::initialize(int argc, char *argv[])
stls = -1;
// else we will do starttls - requires new FDs
} else if (getenv("UCSPITLS")) {
- string ucspitls = session.getEnv("UCSPITLS");
- if (ucspitls == "+") stls = 1;
- if (ucspitls == "-") stls = 0;
- if (ucspitls == "!") stls = 2;
+ string ucspitls = session.getEnv("UCSPITLS");
+ if (ucspitls == "+") stls = 1;
+ if (ucspitls == "-") stls = 0;
+ if (ucspitls == "!") stls = 2;
}
BrokerFactory &brokerfactory = BrokerFactory::getInstance();
diff --git a/src/session-initialize-bincimapd.cc b/src/session-initialize-bincimapd.cc
index 18d43b1..057accd 100644
--- a/src/session-initialize-bincimapd.cc
+++ b/src/session-initialize-bincimapd.cc
@@ -5,28 +5,29 @@
* @date 2002-2005, 2023
* --------------------------------------------------------------------
*/
-#include <unistd.h>
-#include <syslog.h>
-#include <errno.h>
-
#include "broker.h"
-#include "maildir.h"
+#include "convert.h"
#include "depot.h"
#include "globals.h"
+#include "imapserver.h"
#include "iodevice.h"
#include "iofactory.h"
+#include "maildir.h"
#include "multilogdevice.h"
#include "session.h"
#include "stdiodevice.h"
#include "syslogdevice.h"
#include "tools.h"
-#include "convert.h"
-#include "imapserver.h"
-#include <string>
#include <map>
+#include <string>
+
+#include <errno.h>
#include <signal.h>
+#include <syslog.h>
+#include <unistd.h>
+
using namespace ::std;
using namespace Binc;
@@ -37,9 +38,8 @@ bool Session::initialize(int argc, char *argv[])
{
IOFactory &ioFactory = IOFactory::getInstance();
- IODevice *stdioDevice = new StdIODevice(IODevice::IsEnabled
- | IODevice::HasInputLimit
- | IODevice::HasTimeout);
+ IODevice *stdioDevice =
+ new StdIODevice(IODevice::IsEnabled | IODevice::HasInputLimit | IODevice::HasTimeout);
stdioDevice->setFlags(IODevice::HasOutputLimit);
stdioDevice->setMaxOutputBufferSize(TRANSFER_BUFFER_SIZE);
ioFactory.addDevice(stdioDevice);
@@ -47,8 +47,7 @@ bool Session::initialize(int argc, char *argv[])
Session &session = Session::getInstance();
// Read command line arguments
- if (!session.parseCommandLine(argc, argv))
- return false;
+ if (!session.parseCommandLine(argc, argv)) return false;
// Show help if asked for it
if (session.command.help) {
@@ -58,48 +57,58 @@ bool Session::initialize(int argc, char *argv[])
// Show version if asked for it
if (session.command.version) {
- printf("Binc IMAP v" BINC_VERSION"\n");
+ printf("Binc IMAP v" BINC_VERSION "\n");
return false;
}
// Assign command line arguments to global config.
session.assignCommandLineArgs();
- // log settings
- string ip = getenv("TCP6REMOTEIP") ? getenv("TCP6REMOTEIP") :
- getenv("TCPREMOTEIP") ? getenv("TCPREMOTEIP") : "?";
+ // log settings
+ string ip = getenv("TCP6REMOTEIP") ? getenv("TCP6REMOTEIP")
+ : getenv("TCPREMOTEIP") ? getenv("TCPREMOTEIP")
+ : "?";
session.setIP(ip);
string logtype = session.getEnv("LOG_TYPE");
lowercase(logtype);
trim(logtype);
- if (logtype == "" || logtype == "multilog" ) {
+ if (logtype == "" || logtype == "multilog") {
ioFactory.addDevice(new MultilogDevice(IODevice::IsEnabled));
} else if (logtype == "syslog") {
const string f = session.getEnv("SYSLOG_FACILITY");
int facility;
- if (isdigit(f[0])) facility = atoi(f);
+ if (isdigit(f[0]))
+ facility = atoi(f);
else {
- if (f == "LOG_USER") facility = LOG_USER;
- else if (f == "LOG_LOCAL0") facility = LOG_LOCAL0;
- else if (f == "LOG_LOCAL1") facility = LOG_LOCAL1;
- else if (f == "LOG_LOCAL2") facility = LOG_LOCAL2;
- else if (f == "LOG_LOCAL3") facility = LOG_LOCAL3;
- else if (f == "LOG_LOCAL4") facility = LOG_LOCAL4;
- else if (f == "LOG_LOCAL5") facility = LOG_LOCAL5;
- else if (f == "LOG_LOCAL6") facility = LOG_LOCAL6;
- else if (f == "LOG_LOCAL7") facility = LOG_LOCAL7;
- else facility = LOG_DAEMON;
- }
+ if (f == "LOG_USER")
+ facility = LOG_USER;
+ else if (f == "LOG_LOCAL0")
+ facility = LOG_LOCAL0;
+ else if (f == "LOG_LOCAL1")
+ facility = LOG_LOCAL1;
+ else if (f == "LOG_LOCAL2")
+ facility = LOG_LOCAL2;
+ else if (f == "LOG_LOCAL3")
+ facility = LOG_LOCAL3;
+ else if (f == "LOG_LOCAL4")
+ facility = LOG_LOCAL4;
+ else if (f == "LOG_LOCAL5")
+ facility = LOG_LOCAL5;
+ else if (f == "LOG_LOCAL6")
+ facility = LOG_LOCAL6;
+ else if (f == "LOG_LOCAL7")
+ facility = LOG_LOCAL7;
+ else
+ facility = LOG_DAEMON;
+ }
session.setEnv("SYSLOG_FACILITY", toString(facility));
- ioFactory.addDevice(new SyslogDevice(IODevice::IsEnabled,
- "bincimapd",
- LOG_NDELAY | LOG_PID,
- facility));
+ ioFactory.addDevice(
+ new SyslogDevice(IODevice::IsEnabled, "bincimapd", LOG_NDELAY | LOG_PID, facility));
}
// Now that we know the log type, we can flush.
@@ -111,10 +120,9 @@ bool Session::initialize(int argc, char *argv[])
char *logindetails = getenv("BINCIMAP_LOGIN");
if (logindetails == 0) {
- bincLog
- << "bincimapd: pid " << pid
- << " BINCIMAP_LOGIN missing from environment (are you sure you invoked "
- << argv[0] << " properly?)\n";
+ bincLog << "bincimapd: pid " << pid
+ << " BINCIMAP_LOGIN missing from environment (are you sure you invoked " << argv[0]
+ << " properly?)\n";
return false;
}
@@ -126,8 +134,7 @@ bool Session::initialize(int argc, char *argv[])
if (depottype == "") depottype = "Maildir++";
if ((depot = depotfactory.get(depottype)) == 0) {
- bincLog << "bincimapd: pid " << pid
- << " Found no Depot for: " << depottype
+ bincLog << "bincimapd: pid " << pid << " Found no Depot for: " << depottype
<< ". Please check your configurations file under the Mailbox section\n";
bincLog.flush();
return false;
@@ -169,14 +176,13 @@ bool Session::initialize(int argc, char *argv[])
// automatically create depot directory if it's not there already
string path;
- if (session.args.getUnqualifiedArgs().size() > 0)
- path = session.args.getUnqualifiedArgs()[0];
- if (path == "") path = ".";
+ if (session.args.getUnqualifiedArgs().size() > 0) path = session.args.getUnqualifiedArgs()[0];
+ if (path == "")
+ path = ".";
else if (chdir(path.c_str()) != 0) {
mkdir(path.c_str(), 0777);
if (chdir(path.c_str()) != 0) {
- bincLog << "bincimapd: pid" << pid
- << " Error entering depot " + toImapString(path) + ": "
+ bincLog << "bincimapd: pid" << pid << " Error entering depot " + toImapString(path) + ": "
<< strerror(errno) << endl;
return false;
}
@@ -184,8 +190,7 @@ bool Session::initialize(int argc, char *argv[])
// automatically create INBOX if it's not there already
if (depot->get("INBOX") == 0 && !depot->createMailbox("INBOX")) {
- bincLog << "bincimapd: pid " << pid
- << " " << depot->getLastError() << endl;
+ bincLog << "bincimapd: pid " << pid << " " << depot->getLastError() << endl;
return false;
}
@@ -197,8 +202,7 @@ bool Session::initialize(int argc, char *argv[])
const string details = logindetails;
string::size_type det = details.find('+');
if (det == string::npos) {
- bincLog << "bincimapd: pid " << pid
- << " Invalid content of BINCIMAP_LOGIN - did you invoke "
+ bincLog << "bincimapd: pid " << pid << " Invalid content of BINCIMAP_LOGIN - did you invoke "
<< argv[0] << " correctly?" << endl;
return false;
}
diff --git a/src/session.cc b/src/session.cc
index 849c1d6..b6a0834 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -2,16 +2,18 @@
* @file session.cc
* @brief Implementation of the Session class.
* ------------------------------------------------------------------ **/
-#include <unistd.h>
-#include <syslog.h>
+#include "session.h"
#include "argparser.h"
#include "convert.h"
#include "globals.h"
-#include "session.h"
#include "tools.h"
-#include <string>
+
#include <map>
+#include <string>
+
+#include <syslog.h>
+#include <unistd.h>
using namespace ::std;
using namespace Binc;
@@ -133,7 +135,7 @@ int Session::getReadBytes(void) const
}
//----------------------------------------------------------------------
-bool Session::parseCommandLine(int argc, char * argv[])
+bool Session::parseCommandLine(int argc, char *argv[])
{
args.addOptional("h|help", "Display this help screen", true);
args.addOptional("version", "Display the version of Binc IMAP", true);
@@ -159,20 +161,15 @@ bool Session::parseCommandLine(int argc, char * argv[])
//----------------------------------------------------------------------
void Session::assignCommandLineArgs(void)
{
- if (args.hasArg("allow-plain"))
- setEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS", "yes");
+ if (args.hasArg("allow-plain")) setEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS", "yes");
- if (args.hasArg("show-version"))
- setEnv("SHOW_VERSION_IN_GREETING", "yes");
+ if (args.hasArg("show-version")) setEnv("SHOW_VERSION_IN_GREETING", "yes");
- if (args.hasArg("log-type"))
- setEnv("LOG_TYPE", args["log-type"]);
+ if (args.hasArg("log-type")) setEnv("LOG_TYPE", args["log-type"]);
- if (args.hasArg("depot"))
- setEnv("DEPOT", args["depot"]);
+ if (args.hasArg("depot")) setEnv("DEPOT", args["depot"]);
- if (args.hasArg("delimiter"))
- setEnv("DELIMITER", args["delimiter"]);
+ if (args.hasArg("delimiter")) setEnv("DELIMITER", args["delimiter"]);
}
//----------------------------------------------------------------------
@@ -208,8 +205,7 @@ void Session::clearResponseCode(void) const
//----------------------------------------------------------------------
pid_t Session::getPid(void)
{
- if (pid == 0)
- pid = getpid();
+ if (pid == 0) pid = getpid();
return pid;
}
diff --git a/src/status.cc b/src/status.cc
index b9d4f17..8b481ef 100644
--- a/src/status.cc
+++ b/src/status.cc
@@ -10,11 +10,7 @@ using namespace ::std;
using namespace Binc;
//------------------------------------------------------------------------
-Status::Status(void)
-{
-}
+Status::Status(void) {}
//------------------------------------------------------------------------
-Status::~Status(void)
-{
-}
+Status::~Status(void) {}
diff --git a/src/stdiodevice.cc b/src/stdiodevice.cc
index 9eb5f9c..a9cce91 100644
--- a/src/stdiodevice.cc
+++ b/src/stdiodevice.cc
@@ -5,27 +5,25 @@
* @date 2003/2023
* ---------------------------------------------------------------- **/
#include "stdiodevice.h"
+
#include <string>
-#include <sys/types.h>
+#include <errno.h>
+
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
using namespace ::std;
using namespace ::Binc;
//------------------------------------------------------------------------
-StdIODevice::StdIODevice(int f) : IODevice(f)
-{
-}
+StdIODevice::StdIODevice(int f) : IODevice(f) {}
//------------------------------------------------------------------------
-StdIODevice::~StdIODevice(void)
-{
-}
+StdIODevice::~StdIODevice(void) {}
//------------------------------------------------------------------------
string StdIODevice::service(void) const
@@ -37,7 +35,7 @@ string StdIODevice::service(void) const
bool StdIODevice::canRead(void) const
{
size_t bytes;
- return ioctl(fileno(stdin), FIONREAD, (char *) &bytes) > 0;
+ return ioctl(fileno(stdin), FIONREAD, (char *)&bytes) > 0;
}
//------------------------------------------------------------------------
@@ -76,8 +74,7 @@ bool StdIODevice::waitForRead(void) const
IODevice::WriteResult StdIODevice::write(void)
{
for (;;) {
- ssize_t wrote = ::write(fileno(stdout), outputBuffer.str().c_str(),
- outputBuffer.getSize());
+ ssize_t wrote = ::write(fileno(stdout), outputBuffer.str().c_str(), outputBuffer.getSize());
if (wrote == -1) {
if (errno == EINTR)
@@ -88,8 +85,7 @@ IODevice::WriteResult StdIODevice::write(void)
outputBuffer.popString(wrote);
- if (wrote == (ssize_t) outputBuffer.getSize())
- return WriteDone;
+ if (wrote == (ssize_t)outputBuffer.getSize()) return WriteDone;
return WriteWait;
}
}
@@ -97,13 +93,11 @@ IODevice::WriteResult StdIODevice::write(void)
//------------------------------------------------------------------------
bool StdIODevice::fillInputBuffer(void)
{
- if (!waitForRead())
- return false;
+ if (!waitForRead()) return false;
char buf[4096];
ssize_t red = read(fileno(stdin), buf, sizeof(buf) - 1);
- if (red <= 0)
- return false;
+ if (red <= 0) return false;
buf[red] = '\0';
inputBuffer << buf;
diff --git a/src/syslogdevice.cc b/src/syslogdevice.cc
index 927416e..f694835 100644
--- a/src/syslogdevice.cc
+++ b/src/syslogdevice.cc
@@ -5,6 +5,7 @@
* @date 2002, 2003
* ----------------------------------------------------------------- **/
#include "syslogdevice.h"
+
#include <string>
#include <syslog.h>
@@ -16,8 +17,11 @@ using namespace ::Binc;
string SyslogDevice::ident;
//------------------------------------------------------------------------
-SyslogDevice::SyslogDevice(int f, const char *i, int o, int fa)
- : IODevice(f), option(o), facility(fa), priority(LOG_INFO)
+SyslogDevice::SyslogDevice(int f, const char *i, int o, int fa)
+ : IODevice(f)
+ , option(o)
+ , facility(fa)
+ , priority(LOG_INFO)
{
ident = i;
openlog(ident.c_str(), option, facility);
@@ -61,7 +65,7 @@ IODevice::WriteResult SyslogDevice::write(void)
} else if (*i != '\r')
out += *i;
}
-
+
if (out != "") syslog(priority, out.c_str(), out.size());
outputBuffer.clear();
diff --git a/src/tools.cc b/src/tools.cc
index 24c3757..95c28d6 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -4,18 +4,17 @@
* @author Andreas Aardal Hanssen
* @date 2002-2005
* ------------------------------------------------------------------ **/
-#include <errno.h>
+#include "tools.h"
+
#include <cstring>
-#include "tools.h"
+#include <errno.h>
using namespace ::std;
using namespace Binc;
//------------------------------------------------------------------------
-Tools::Tools(void)
-{
-}
+Tools::Tools(void) {}
//------------------------------------------------------------------------
Tools &Tools::getInstance(void)