summaryrefslogtreecommitdiff
path: root/src/session-initialize-bincimapd.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/session-initialize-bincimapd.cc')
-rw-r--r--src/session-initialize-bincimapd.cc102
1 files changed, 53 insertions, 49 deletions
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;
}