/*
* IMAP server for the Citadel system
*
- * Copyright (C) 2000-2011 by Art Cancro and others.
+ * Copyright (C) 2000-2015 by Art Cancro and others.
* This code is released under the terms of the GNU General Public License.
*
* WARNING: the IMAP protocol is badly designed. No implementation of it
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdep.h"
IAPuts("* OK [");
imap_output_capability_string();
- IAPrintf("] %s IMAP4rev1 %s ready\r\n", config.c_fqdn, CITADEL);
+ IAPrintf("] %s IMAP4rev1 %s ready\r\n", CtdlGetConfigStr("c_fqdn"), CITADEL);
IUnbuffer();
}
}
if (!strcasecmp(Params[2].Key, "LOGIN")) {
- CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+ size_t len = CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+ if (UsrBuf[len - 1] == '\n') {
+ UsrBuf[len - 1] = '\0';
+ }
+
IAPrintf("+ %s\r\n", UsrBuf);
IMAP->authstate = imap_as_expecting_username;
strcpy(IMAP->authseq, Params[0].Key);
}
if (!strcasecmp(Params[2].Key, "PLAIN")) {
- // CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+ // size_t len = CtdlEncodeBase64(UsrBuf, "Username:", 9, 0);
+ // if (UsrBuf[len - 1] == '\n') {
+ // UsrBuf[len - 1] = '\0';
+ // }
// IAPuts("+ %s\r\n", UsrBuf);
IAPuts("+ \r\n");
IMAP->authstate = imap_as_expecting_plainauth;
char pass[256] = "";
int result;
long decoded_len;
- long len;
+ long len = 0;
+ long plen = 0;
memset(pass, 0, sizeof(pass));
decoded_len = StrBufDecodeBase64(Imap->Cmd.CmdBuf);
if (decoded_len > 0)
{
- len = safestrncpy(pass, decoded_authstring, sizeof pass);
+ plen = safestrncpy(pass, decoded_authstring, sizeof pass);
- if (len < 0)
- len = sizeof(pass) - 1;
+ if (plen < 0)
+ plen = sizeof(pass) - 1;
}
}
Imap->authstate = imap_as_normal;
}
if (result == login_ok) {
- if (CtdlTryPassword(pass, len) == pass_ok) {
+ if (CtdlTryPassword(pass, plen) == pass_ok) {
IAPrintf("%s OK authentication succeeded\r\n", Imap->authseq);
return;
}
case imap_as_expecting_username:
StrBufDecodeBase64(Imap->Cmd.CmdBuf);
CtdlLoginExistingUser(NULL, ChrPtr(Imap->Cmd.CmdBuf));
- CtdlEncodeBase64(PWBuf, "Password:", 9, 0);
+ size_t len = CtdlEncodeBase64(PWBuf, "Password:", 9, 0);
+ if (PWBuf[len - 1] == '\n') {
+ PWBuf[len - 1] = '\0';
+ }
+
IAPrintf("+ %s\r\n", PWBuf);
Imap->authstate = imap_as_expecting_password;
* the number of messages and number of new messages.
*/
memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
- CtdlUserGoto(NULL, 0, 0, &msgs, &new);
+ CtdlUserGoto(NULL, 0, 0, &msgs, &new, NULL, NULL);
Imap->selected = 1;
if (!strcasecmp(Params[1].Key, "EXAMINE")) {
IAPrintf("* %d RECENT\r\n", new);
IAPrintf("* OK [UIDVALIDITY %ld] UID validity status\r\n", GLOBAL_UIDVALIDITY_VALUE);
- IAPrintf("* OK [UIDNEXT %ld] Predicted next UID\r\n", CitControl.MMhighest + 1);
+ IAPrintf("* OK [UIDNEXT %ld] Predicted next UID\r\n", CtdlGetConfigLong("MMhighest") + 1);
/* Technically, \Deleted is a valid flag, but not a permanent flag,
* because we don't maintain its state across sessions. Citadel
if (IMAP->selected) {
strcpy(savedroom, CC->room.QRname);
}
- CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+ CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
/*
* Tell the client what it wants to know. In fact, tell it *more* than
IPutStr(imaproomname, len);
IAPrintf(" (MESSAGES %d ", msgs);
IAPrintf("RECENT %d ", new); /* Initially, new==recent */
- IAPrintf("UIDNEXT %ld ", CitControl.MMhighest + 1);
+ IAPrintf("UIDNEXT %ld ", CtdlGetConfigLong("MMhighest") + 1);
IAPrintf("UNSEEN %d)\r\n", new);
/*
* our happy day without violent explosions.
*/
if (IMAP->selected) {
- CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+ CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
}
/*
if (IMAP->selected) {
strcpy(savedroom, CC->room.QRname);
}
- CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+ CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
/*
* If another folder is selected, go back to that room so we can resume
* our happy day without violent explosions.
*/
if (IMAP->selected) {
- CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+ CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
}
IReply("OK SUBSCRIBE completed");
if (IMAP->selected) {
strcpy(savedroom, CC->room.QRname);
}
- CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+ CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
/*
* Now make the API call to zap the room
* our happy day without violent explosions.
*/
if (IMAP->selected) {
- CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+ CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
}
}
if (IMAP->selected) {
strcpy(savedroom, CC->room.QRname);
}
- CtdlUserGoto(roomname, 0, 0, &msgs, &new);
+ CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
/*
* Now delete the room.
* our happy day without violent explosions.
*/
if (IMAP->selected) {
- CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
+ CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
}
}
if (IMAP->selected) {
imap_do_expunge(); /* yes, we auto-expunge at logout */
}
- IAPrintf("* BYE %s logging out\r\n", config.c_fqdn);
+ IAPrintf("* BYE %s logging out\r\n", CtdlGetConfigStr("c_fqdn"));
IReply("OK Citadel IMAP session ended.");
CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
return;
if (!threading)
{
CtdlRegisterDebugFlagHook(HKEY("imapsrv"), SetIMAPDebugEnabled, &IMAPDebugEnabled);
- CtdlRegisterServiceHook(config.c_imap_port,
+ CtdlRegisterServiceHook(CtdlGetConfigInt("c_imap_port"),
NULL, imap_greeting, imap_command_loop, NULL, CitadelServiceIMAP);
#ifdef HAVE_OPENSSL
- CtdlRegisterServiceHook(config.c_imaps_port,
+ CtdlRegisterServiceHook(CtdlGetConfigInt("c_imaps_port"),
NULL, imaps_greeting, imap_command_loop, NULL, CitadelServiceIMAPS);
#endif
CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP, PRIO_STOP + 30);