/* Load the message list */
cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
if (cdbfr != NULL) {
- Imap->msgids = malloc(cdbfr->len);
- memcpy(Imap->msgids, cdbfr->ptr, cdbfr->len);
+ Imap->msgids = (long*)cdbfr->ptr;
Imap->num_msgs = cdbfr->len / sizeof(long);
Imap->num_alloc = cdbfr->len / sizeof(long);
+ cdbfr->ptr = NULL;
+ cdbfr->len = 0;
cdb_free(cdbfr);
}
if (Imap->num_msgs) {
Imap->flags = malloc(Imap->num_alloc * sizeof(unsigned int));
- memset(Imap->flags, 0, (Imap->num_alloc * sizeof(long)) );
+ memset(Imap->flags, 0, (Imap->num_alloc * sizeof(unsigned int)) );
}
imap_set_seen_flags(0);
*/
cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
if (cdbfr != NULL) {
- msglist = malloc(cdbfr->len + 1);
- if (msglist == NULL) {
- IMAPM_syslog(LOG_CRIT, "malloc() failed");
- CC->kill_me = KILLME_MALLOC_FAILED;
- return;
- }
- memcpy(msglist, cdbfr->ptr, (size_t)cdbfr->len);
+ msglist = (long*)cdbfr->ptr;
+ cdbfr->ptr = NULL;
num_msgs = cdbfr->len / sizeof(long);
+ cdbfr->len = 0;
cdb_free(cdbfr);
} else {
num_msgs = 0;
(Imap->num_msgs - i)));
memmove(&Imap->flags[i],
&Imap->flags[i + 1],
- (sizeof(long) *
+ (sizeof(unsigned int) *
(Imap->num_msgs - i)));
-
--i;
}
}
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;
{
citimap *Imap = IMAP;
const char *decoded_authstring;
- char ident[256];
- char user[256];
- char pass[256];
+ char ident[256] = "";
+ char user[256] = "";
+ char pass[256] = "";
int result;
- long len;
+ long decoded_len;
+ long len = 0;
+ long plen = 0;
memset(pass, 0, sizeof(pass));
- StrBufDecodeBase64(Imap->Cmd.CmdBuf);
+ decoded_len = StrBufDecodeBase64(Imap->Cmd.CmdBuf);
+
+ if (decoded_len > 0)
+ {
+ decoded_authstring = ChrPtr(Imap->Cmd.CmdBuf);
+
+ len = safestrncpy(ident, decoded_authstring, sizeof ident);
- decoded_authstring = ChrPtr(Imap->Cmd.CmdBuf);
- safestrncpy(ident, decoded_authstring, sizeof ident);
- safestrncpy(user, &decoded_authstring[strlen(ident) + 1], sizeof user);
- len = safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
- if (len < 0)
- len = sizeof(pass) - 1;
+ decoded_len -= len - 1;
+ decoded_authstring += len + 1;
+ if (decoded_len > 0)
+ {
+ len = safestrncpy(user, decoded_authstring, sizeof user);
+
+ decoded_authstring += len + 1;
+ decoded_len -= len - 1;
+ }
+
+ if (decoded_len > 0)
+ {
+ plen = safestrncpy(pass, decoded_authstring, sizeof pass);
+
+ if (plen < 0)
+ plen = sizeof(pass) - 1;
+ }
+ }
Imap->authstate = imap_as_normal;
if (!IsEmptyStr(ident)) {
}
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")) {
*/
void imap_namespace(int num_parms, ConstStr *Params)
{
+ long len;
int i;
struct floor *fl;
int floors = 0;
if (fl->f_flags & F_INUSE) {
/* if (floors > 0) IAPuts(" "); samjam says this confuses javamail */
IAPuts("(");
- snprintf(Namespace, sizeof(Namespace), "%s/", fl->f_name);
- plain_imap_strout(Namespace);
+ len = snprintf(Namespace, sizeof(Namespace), "%s/", fl->f_name);
+ IPutStr(Namespace, len);
IAPuts(" \"/\")");
++floors;
}
*/
void imap_status(int num_parms, ConstStr *Params)
{
+ long len;
int ret;
char roomname[ROOMNAMELEN];
char imaproomname[SIZ];
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
* names and simply spew all possible data items. It's far easier to
* code and probably saves us some processing time too.
*/
- imap_mailboxname(imaproomname, sizeof imaproomname, &CC->room);
+ len = imap_mailboxname(imaproomname, sizeof imaproomname, &CC->room);
IAPuts("* STATUS ");
- plain_imap_strout(imaproomname);
+ IPutStr(imaproomname, len);
IAPrintf(" (MESSAGES %d ", msgs);
IAPrintf("RECENT %d ", new); /* Initially, new==recent */
IAPrintf("UIDNEXT %ld ", CitControl.MMhighest + 1);
* 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);
}
}