I found it and fixed it :-)
Seems like mozilla doesn't like a final space before the closing ) in a
status response.
I've also cleaned up imapcommands to use the ci_write wrapper for
writing output to clients which helped with making dbmail's tcp
behaviour more compliant.
Mozilla/thunderbird will now behave as expected when checking all imap
folders.
Paul J Stevens wrote:
More on this;
I've fixed imapcommands to strictly use ci_write. The packet trace now
looks real clean in terms of tcp. Still no luck though. I'll have to use
another imap server as comparison. Mozilla apparently doesn't like
something about dbmail's responses and just disconnects, period.
Paul J Stevens wrote:
Following up on myself,
Looks like imapcommands.c writes after the client sends FIN packets. I
guess the ci_write patch should be expanded to include imapcommands as
well.
Mozilla closes the connection by sending FIN after receiving response
to a command. If the server then wants to send OK tags after that the
client barfs and sends RST.
I've attached a ethereal capture.
Paul J Stevens wrote:
When I specify mentioned option in mozilla or thunderbird, the client
will happily check all imap mailfolders on uw-imapd. However, this
does not work for dbmail.
This very annoying problem was identified today as being a dbmail
issue, instead of a client issue.
Looks like IMAPClientHandler bails out when it shouldn't. I'll see
what I can find.
------------------------------------------------------------------------
_______________________________________________
Dbmail-dev mailing list
[email protected]
http://twister.fastxs.net/mailman/listinfo/dbmail-dev
--
________________________________________________________________
Paul Stevens mailto:[EMAIL PROTECTED]
NET FACILITIES GROUP PGP: finger [EMAIL PROTECTED]
The Netherlands________________________________http://www.nfg.nl
diff -urNad /usr/src/dbmail2/dbmail-2.0/imap4.c dbmail-2.0/imap4.c
--- /usr/src/dbmail2/dbmail-2.0/imap4.c 2004-04-16 00:24:26.000000000 +0200
+++ dbmail-2.0/imap4.c 2004-04-16 00:30:39.000000000 +0200
@@ -110,20 +110,6 @@
};
-int ci_write(FILE * fd, char * msg, ...);
-
-int ci_write(FILE * fd, char * msg, ...)
-{
- va_list ap;
- va_start(ap, msg);
-
- if (feof(fd) || vfprintf(fd,msg,ap) < 0 || fflush(fd) < 0) {
- va_end(ap);
- return -1;
- }
- va_end(ap);
- return 0;
-}
void ci_cleanup(ClientInfo *ci);
void ci_cleanup(ClientInfo *ci)
@@ -133,6 +119,7 @@
null_free(ci->userData);
}
+
/*
* Main handling procedure
*
diff -urNad /usr/src/dbmail2/dbmail-2.0/imapcommands.c dbmail-2.0/imapcommands.c
--- /usr/src/dbmail2/dbmail-2.0/imapcommands.c 2004-04-16 00:24:45.000000000 +0200
+++ dbmail-2.0/imapcommands.c 2004-04-16 00:35:01.000000000 +0200
@@ -108,8 +108,8 @@
if (!check_state_and_args("CAPABILITY", tag, args, 0, -1, ci))
return 1; /* error, return */
- fprintf(ci->tx, "* CAPABILITY %s\r\n", IMAP_CAPABILITY_STRING);
- fprintf(ci->tx, "%s OK CAPABILITY completed\r\n", tag);
+ ci_write(ci->tx, "* CAPABILITY %s\r\n", IMAP_CAPABILITY_STRING);
+ ci_write(ci->tx, "%s OK CAPABILITY completed\r\n", tag);
return 0;
}
@@ -125,7 +125,7 @@
if (!check_state_and_args("NOOP", tag, args, 0, -1, ci))
return 1; /* error, return */
- fprintf(ci->tx, "%s OK NOOP completed\r\n", tag);
+ ci_write(ci->tx, "%s OK NOOP completed\r\n", tag);
return 0;
}
@@ -151,7 +151,7 @@
"_ic_logout(): user (id:%llu) logging out @ [%s]\r\n",
ud->userid, timestring);
- fprintf(ci->tx, "* BYE dbmail imap server kisses you goodbye\r\n");
+ ci_write(ci->tx, "* BYE dbmail imap server kisses you goodbye\r\n");
return 0;
}
@@ -186,7 +186,7 @@
if (validate_result == -1) {
/* a db-error occurred */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal db error validating user\r\n");
trace(TRACE_ERROR,
"_ic_login(): db-validate error while validating user %s (pass %s).",
@@ -201,7 +201,7 @@
trace(TRACE_MESSAGE,
"IMAPD [PID %d]: user (name %s) login rejected @ %s\r\n",
(int) getpid(), args[0], timestring);
- fprintf(ci->tx, "%s NO login rejected\r\n", tag);
+ ci_write(ci->tx, "%s NO login rejected\r\n", tag);
return 1;
}
@@ -221,7 +221,7 @@
if (imap_before_smtp)
db_log_ip(ci->ip);
- fprintf(ci->tx, "%s OK LOGIN completed\r\n", tag);
+ ci_write(ci->tx, "%s OK LOGIN completed\r\n", tag);
return 0;
}
@@ -248,7 +248,7 @@
/* check authentication method */
if (strcasecmp(args[0], "login") != 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO Invalid authentication mechanism specified\r\n",
tag);
return 1;
@@ -257,7 +257,7 @@
/* ask for username (base64 encoded) */
memset(buf, 0, MAX_LINESIZE);
base64encode("username\r\n", buf);
- fprintf(ci->tx, "+ %s\r\n", buf);
+ ci_write(ci->tx, "+ %s\r\n", buf);
fflush(ci->tx);
alarm(ci->timeout);
@@ -269,7 +269,7 @@
/* ask for password */
memset(buf, 0, MAX_LINESIZE);
base64encode("password\r\n", buf);
- fprintf(ci->tx, "+ %s\r\n", buf);
+ ci_write(ci->tx, "+ %s\r\n", buf);
fflush(ci->tx);
alarm(ci->timeout);
@@ -284,7 +284,7 @@
if (validate_result == -1) {
/* a db-error occurred */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal db error validating user\r\n");
trace(TRACE_ERROR,
"IMAPD: authenticate(): db-validate error while validating user %s "
@@ -296,7 +296,7 @@
sleep(2); /* security */
/* validation failed: invalid user/pass combination */
- fprintf(ci->tx, "%s NO login rejected\r\n", tag);
+ ci_write(ci->tx, "%s NO login rejected\r\n", tag);
/* validation failed: invalid user/pass combination */
trace(TRACE_MESSAGE,
@@ -321,7 +321,7 @@
set_proc_title("USER %s [%s]", args[0], ci->ip);
#endif
- fprintf(ci->tx, "%s OK AUTHENTICATE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK AUTHENTICATE completed\r\n", tag);
return 0;
}
@@ -350,11 +350,11 @@
return 1; /* error, return */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
if (mboxid == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO Could not find specified mailbox\r\n", tag);
ud->state = IMAPCS_AUTHENTICATED;
@@ -367,11 +367,11 @@
/* check if user has right to select mailbox */
result = acl_has_right(ud->userid, mboxid, ACL_RIGHT_READ);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to select mailbox\r\n", tag);
ud->state = IMAPCS_AUTHENTICATED;
my_free(ud->mailbox.seq_list);
@@ -383,7 +383,7 @@
result = db_isselectable(mboxid);
if (result == 0) {
/* error: cannot select mailbox */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO specified mailbox is not selectable\r\n",
tag);
@@ -394,7 +394,7 @@
return 1;
}
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
@@ -402,63 +402,63 @@
/* read info from mailbox */ result = db_getmailbox(&ud->mailbox);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
/* show mailbox info */
/* msg counts */
- fprintf(ci->tx, "* %u EXISTS\r\n", ud->mailbox.exists);
- fprintf(ci->tx, "* %u RECENT\r\n", ud->mailbox.recent);
+ ci_write(ci->tx, "* %u EXISTS\r\n", ud->mailbox.exists);
+ ci_write(ci->tx, "* %u RECENT\r\n", ud->mailbox.recent);
/* flags */
- fprintf(ci->tx, "* FLAGS (");
+ ci_write(ci->tx, "* FLAGS (");
if (ud->mailbox.flags & IMAPFLAG_SEEN)
- fprintf(ci->tx, "\\Seen ");
+ ci_write(ci->tx, "\\Seen ");
if (ud->mailbox.flags & IMAPFLAG_ANSWERED)
- fprintf(ci->tx, "\\Answered ");
+ ci_write(ci->tx, "\\Answered ");
if (ud->mailbox.flags & IMAPFLAG_DELETED)
- fprintf(ci->tx, "\\Deleted ");
+ ci_write(ci->tx, "\\Deleted ");
if (ud->mailbox.flags & IMAPFLAG_FLAGGED)
- fprintf(ci->tx, "\\Flagged ");
+ ci_write(ci->tx, "\\Flagged ");
if (ud->mailbox.flags & IMAPFLAG_DRAFT)
- fprintf(ci->tx, "\\Draft ");
+ ci_write(ci->tx, "\\Draft ");
if (ud->mailbox.flags & IMAPFLAG_RECENT)
- fprintf(ci->tx, "\\Recent ");
+ ci_write(ci->tx, "\\Recent ");
- fprintf(ci->tx, ")\r\n");
+ ci_write(ci->tx, ")\r\n");
/* permanent flags */
- fprintf(ci->tx, "* OK [PERMANENTFLAGS (");
+ ci_write(ci->tx, "* OK [PERMANENTFLAGS (");
if (ud->mailbox.flags & IMAPFLAG_SEEN)
- fprintf(ci->tx, "\\Seen ");
+ ci_write(ci->tx, "\\Seen ");
if (ud->mailbox.flags & IMAPFLAG_ANSWERED)
- fprintf(ci->tx, "\\Answered ");
+ ci_write(ci->tx, "\\Answered ");
if (ud->mailbox.flags & IMAPFLAG_DELETED)
- fprintf(ci->tx, "\\Deleted ");
+ ci_write(ci->tx, "\\Deleted ");
if (ud->mailbox.flags & IMAPFLAG_FLAGGED)
- fprintf(ci->tx, "\\Flagged ");
+ ci_write(ci->tx, "\\Flagged ");
if (ud->mailbox.flags & IMAPFLAG_DRAFT)
- fprintf(ci->tx, "\\Draft ");
+ ci_write(ci->tx, "\\Draft ");
if (ud->mailbox.flags & IMAPFLAG_RECENT)
- fprintf(ci->tx, "\\Recent ");
+ ci_write(ci->tx, "\\Recent ");
- fprintf(ci->tx, ")]\r\n");
+ ci_write(ci->tx, ")]\r\n");
/* UID */
- fprintf(ci->tx, "* OK [UIDVALIDITY %llu] UID value\r\n",
+ ci_write(ci->tx, "* OK [UIDVALIDITY %llu] UID value\r\n",
ud->mailbox.uid);
/* show idx of first unseen msg (if present) */
key = db_first_unseen(ud->mailbox.uid);
if (key == (u64_t) (-1)) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
if (binary_search(ud->mailbox.seq_list, ud->mailbox.exists,
key, &idx) != -1)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* OK [UNSEEN %u] first unseen message\r\n",
idx + 1);
@@ -476,7 +476,7 @@
"IMAPD: select(): detected invalid permission mode for mailbox %llu ('%s')",
ud->mailbox.uid, args[0]);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE fatal: detected invalid mailbox settings\r\n");
return -1;
}
@@ -484,7 +484,7 @@
/* ok, update state */
ud->state = IMAPCS_SELECTED;
- fprintf(ci->tx, "%s OK [%s] SELECT completed\r\n", tag,
+ ci_write(ci->tx, "%s OK [%s] SELECT completed\r\n", tag,
permstring);
return 0;
}
@@ -506,11 +506,11 @@
return 1; /* error, return */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
if (mboxid == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO Could not find specified mailbox\r\n", tag);
return 1;
}
@@ -518,11 +518,11 @@
/* check if user has right to examine mailbox */
result = acl_has_right(ud->userid, mboxid, ACL_RIGHT_READ);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to examine mailbox\r\n", tag);
ud->state = IMAPCS_AUTHENTICATED;
my_free(ud->mailbox.seq_list);
@@ -534,13 +534,13 @@
result = db_isselectable(mboxid);
if (result == 0) {
/* error: cannot select mailbox */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO specified mailbox is not selectable\r\n",
tag);
return 1; /* fatal */
}
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
@@ -550,52 +550,52 @@
result = db_getmailbox(&ud->mailbox);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
/* show mailbox info */
/* msg counts */
- fprintf(ci->tx, "* %u EXISTS\r\n", ud->mailbox.exists);
- fprintf(ci->tx, "* %u RECENT\r\n", ud->mailbox.recent);
+ ci_write(ci->tx, "* %u EXISTS\r\n", ud->mailbox.exists);
+ ci_write(ci->tx, "* %u RECENT\r\n", ud->mailbox.recent);
/* flags */
- fprintf(ci->tx, "* FLAGS (");
+ ci_write(ci->tx, "* FLAGS (");
if (ud->mailbox.flags & IMAPFLAG_SEEN)
- fprintf(ci->tx, "\\Seen ");
+ ci_write(ci->tx, "\\Seen ");
if (ud->mailbox.flags & IMAPFLAG_ANSWERED)
- fprintf(ci->tx, "\\Answered ");
+ ci_write(ci->tx, "\\Answered ");
if (ud->mailbox.flags & IMAPFLAG_DELETED)
- fprintf(ci->tx, "\\Deleted ");
+ ci_write(ci->tx, "\\Deleted ");
if (ud->mailbox.flags & IMAPFLAG_FLAGGED)
- fprintf(ci->tx, "\\Flagged ");
+ ci_write(ci->tx, "\\Flagged ");
if (ud->mailbox.flags & IMAPFLAG_DRAFT)
- fprintf(ci->tx, "\\Draft ");
+ ci_write(ci->tx, "\\Draft ");
if (ud->mailbox.flags & IMAPFLAG_RECENT)
- fprintf(ci->tx, "\\Recent ");
+ ci_write(ci->tx, "\\Recent ");
- fprintf(ci->tx, ")\r\n");
+ ci_write(ci->tx, ")\r\n");
/* permanent flags */
- fprintf(ci->tx, "* OK [PERMANENTFLAGS (");
+ ci_write(ci->tx, "* OK [PERMANENTFLAGS (");
if (ud->mailbox.flags & IMAPFLAG_SEEN)
- fprintf(ci->tx, "\\Seen ");
+ ci_write(ci->tx, "\\Seen ");
if (ud->mailbox.flags & IMAPFLAG_ANSWERED)
- fprintf(ci->tx, "\\Answered ");
+ ci_write(ci->tx, "\\Answered ");
if (ud->mailbox.flags & IMAPFLAG_DELETED)
- fprintf(ci->tx, "\\Deleted ");
+ ci_write(ci->tx, "\\Deleted ");
if (ud->mailbox.flags & IMAPFLAG_FLAGGED)
- fprintf(ci->tx, "\\Flagged ");
+ ci_write(ci->tx, "\\Flagged ");
if (ud->mailbox.flags & IMAPFLAG_DRAFT)
- fprintf(ci->tx, "\\Draft ");
+ ci_write(ci->tx, "\\Draft ");
if (ud->mailbox.flags & IMAPFLAG_RECENT)
- fprintf(ci->tx, "\\Recent ");
+ ci_write(ci->tx, "\\Recent ");
- fprintf(ci->tx, ")]\r\n");
+ ci_write(ci->tx, ")]\r\n");
/* UID */
- fprintf(ci->tx, "* OK [UIDVALIDITY %llu] UID value\r\n",
+ ci_write(ci->tx, "* OK [UIDVALIDITY %llu] UID value\r\n",
ud->mailbox.uid);
/* update permission: examine forces read-only */
@@ -604,7 +604,7 @@
/* ok, update state */
ud->state = IMAPCS_SELECTED;
- fprintf(ci->tx, "%s OK [READ-ONLY] EXAMINE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK [READ-ONLY] EXAMINE completed\r\n", tag);
return 0;
}
@@ -639,19 +639,19 @@
/* check if this mailbox already exists */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
/* dbase failure */
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
if (mboxid != 0) {
/* mailbox already exists */
- fprintf(ci->tx, "%s NO mailbox already exists\r\n", tag);
+ ci_write(ci->tx, "%s NO mailbox already exists\r\n", tag);
return 1;
}
/* check if new name is valid */
if (!checkmailboxname(args[0])) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD new mailbox name contains invalid characters\r\n",
tag);
return 1;
@@ -662,7 +662,7 @@
if (!cpy) {
/* out of mem */
trace(TRACE_ERROR, "IMAPD: create(): not enough memory");
- fprintf(ci->tx, "* BYE server ran out of memory\r\n");
+ ci_write(ci->tx, "* BYE server ran out of memory\r\n");
return -1;
}
@@ -673,14 +673,14 @@
/* serious error while making chunks */
trace(TRACE_ERROR,
"IMAPD: create(): could not create chunks");
- fprintf(ci->tx, "* BYE server ran out of memory\r\n");
+ ci_write(ci->tx, "* BYE server ran out of memory\r\n");
my_free(cpy);
return -1;
}
if (chunks[0] == NULL) {
/* wrong argument */
- fprintf(ci->tx, "%s NO invalid mailbox name specified\r\n",
+ ci_write(ci->tx, "%s NO invalid mailbox name specified\r\n",
tag);
free_chunks(chunks);
my_free(cpy);
@@ -693,7 +693,7 @@
for (i = 0; chunks[i]; i++) {
if (strlen(chunks[i]) == 0) {
/* no can do */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO invalid mailbox name specified\r\n",
tag);
free_chunks(chunks);
@@ -729,7 +729,7 @@
/* check if this mailbox already exists */
if (db_findmailbox(cpy, ud->userid, &mboxid) == -1) {
/* dbase failure */
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
free_chunks(chunks);
my_free(cpy);
return -1; /* fatal */
@@ -749,7 +749,7 @@
parent_mboxid,
ACL_RIGHT_CREATE);
if (result < 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal database "
"error\r\n");
free_chunks(chunks);
@@ -757,7 +757,7 @@
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to create "
"mailbox here\r\n", tag);
free_chunks(chunks);
@@ -770,7 +770,7 @@
another namespace, but we don't specify
the parent's mailbox, we should not be
allowed to do so */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to create "
"mailbox here\r\n", tag);
free_chunks(chunks);
@@ -783,7 +783,7 @@
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal dbase error\r\n");
return -1; /* fatal */
}
@@ -793,7 +793,7 @@
/* mailbox does exist, failure if no_inferiors flag set */
result = db_noinferiors(mboxid);
if (result == 1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO mailbox cannot have inferior names\r\n",
tag);
free_chunks(chunks);
@@ -804,7 +804,7 @@
if (result == -1) {
/* dbase failure */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal dbase error\r\n");
free_chunks(chunks);
my_free(cpy);
@@ -817,7 +817,7 @@
free_chunks(chunks);
my_free(cpy);
- fprintf(ci->tx, "%s OK CREATE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK CREATE completed\r\n", tag);
return 0;
}
@@ -844,12 +844,12 @@
/* check if this mailbox exists */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
/* dbase failure */
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
if (mboxid == 0) {
/* mailbox does not exist */
- fprintf(ci->tx, "%s NO mailbox does not exist\r\n", tag);
+ ci_write(ci->tx, "%s NO mailbox does not exist\r\n", tag);
return 1;
}
@@ -857,11 +857,11 @@
the user has the right to delete it. */
result = db_user_is_mailbox_owner(ud->userid, mboxid);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to delete mailbox\r\n", tag);
ud->state = IMAPCS_AUTHENTICATED;
my_free(ud->mailbox.seq_list);
@@ -871,7 +871,7 @@
/* check if there is an attempt to delete inbox */
if (strcasecmp(args[0], "inbox") == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO cannot delete special mailbox INBOX\r\n",
tag);
return 1;
@@ -885,7 +885,7 @@
/* error */
trace(TRACE_ERROR,
"IMAPD: delete(): cannot retrieve list of mailbox children");
- fprintf(ci->tx, "* BYE dbase/memory error\r\n");
+ ci_write(ci->tx, "* BYE dbase/memory error\r\n");
return -1;
}
@@ -893,14 +893,14 @@
/* mailbox has inferior names; error if \noselect specified */
result = db_isselectable(mboxid);
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO mailbox is non-selectable\r\n",
tag);
my_free(children);
return 1;
}
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(children);
return -1; /* fatal */
}
@@ -911,7 +911,7 @@
result = db_setselectable(mboxid, 0); /* set non-selectable flag */
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(children);
return -1; /* fatal */
}
@@ -924,7 +924,7 @@
}
/* ok done */
- fprintf(ci->tx, "%s OK DELETE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK DELETE completed\r\n", tag);
my_free(children);
return 0;
}
@@ -939,7 +939,7 @@
ud->state = IMAPCS_AUTHENTICATED;
}
- fprintf(ci->tx, "%s OK DELETE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK DELETE completed\r\n", tag);
return 0;
}
@@ -980,12 +980,12 @@
/* check if new mailbox exists */
if (db_findmailbox(args[1], ud->userid, &mboxid) == -1) {
/* dbase failure */
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
if (mboxid != 0) {
/* mailbox exists */
- fprintf(ci->tx, "%s NO new mailbox already exists\r\n",
+ ci_write(ci->tx, "%s NO new mailbox already exists\r\n",
tag);
return 1;
}
@@ -993,12 +993,12 @@
/* check if original mailbox exists */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
/* dbase failure */
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
if (mboxid == 0) {
/* mailbox does not exist */
- fprintf(ci->tx, "%s NO mailbox does not exist\r\n", tag);
+ ci_write(ci->tx, "%s NO mailbox does not exist\r\n", tag);
return 1;
}
@@ -1006,11 +1006,11 @@
the user has the right to delete it. */
result = db_user_is_mailbox_owner(ud->userid, mboxid);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to rename mailbox\r\n", tag);
ud->state = IMAPCS_AUTHENTICATED;
my_free(ud->mailbox.seq_list);
@@ -1020,7 +1020,7 @@
/* check if new name is valid */
if (!checkmailboxname(args[1])) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO new mailbox name contains invalid characters\r\n",
tag);
return 1;
@@ -1035,7 +1035,7 @@
*/
if (strncasecmp(args[0], args[1], oldnamelen) == 0 &&
strlen(args[1]) > oldnamelen && args[1][oldnamelen] == '/') {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO new mailbox would invade mailbox structure\r\n",
tag);
return 1;
@@ -1051,12 +1051,12 @@
if (db_findmailbox(args[1], ud->userid, &parentmboxid) ==
-1) {
/* dbase failure */
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
if (parentmboxid == 0) {
/* parent mailbox does not exist */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO new mailbox would invade mailbox structure\r\n",
tag);
return 1;
@@ -1073,18 +1073,18 @@
/* inferior names of INBOX are left unchanged */
result = db_createmailbox(args[1], ud->userid, &newmboxid);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
result = db_movemsg(newmboxid, mboxid);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
/* ok done */
- fprintf(ci->tx, "%s OK RENAME completed\r\n", tag);
+ ci_write(ci->tx, "%s OK RENAME completed\r\n", tag);
return 0;
}
@@ -1093,7 +1093,7 @@
db_listmailboxchildren(mboxid, ud->userid, &children,
&nchildren, "%");
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
@@ -1101,7 +1101,7 @@
for (i = 0; i < nchildren; i++) {
result = db_getmailboxname(children[i], ud->userid, name);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(children);
return -1;
}
@@ -1110,7 +1110,7 @@
/* strange error, let's say its fatal */
trace(TRACE_ERROR,
"IMAPD: rename(): mailbox names are fucked up");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal error regarding mailbox names\r\n");
my_free(children);
return -1;
@@ -1121,7 +1121,7 @@
result = db_setmailboxname(children[i], newname);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(children);
return -1;
}
@@ -1132,11 +1132,11 @@
/* now replace name */
result = db_setmailboxname(mboxid, args[1]);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
- fprintf(ci->tx, "%s OK RENAME completed\r\n", tag);
+ ci_write(ci->tx, "%s OK RENAME completed\r\n", tag);
return 0;
}
@@ -1158,12 +1158,12 @@
return 1; /* error, return */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
if (mboxid == 0) {
/* mailbox does not exist */
- fprintf(ci->tx, "%s NO mailbox does not exist\r\n", tag);
+ ci_write(ci->tx, "%s NO mailbox does not exist\r\n", tag);
return 0;
}
@@ -1171,11 +1171,11 @@
use, so I guessed it should be lookup */
result = acl_has_right(ud->userid, mboxid, ACL_RIGHT_LOOKUP);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to subscribe to mailbox\r\n",
tag);
ud->state = IMAPCS_AUTHENTICATED;
@@ -1185,11 +1185,11 @@
}
if (db_subscribe(mboxid, ud->userid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
- fprintf(ci->tx, "%s OK SUBSCRIBE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK SUBSCRIBE completed\r\n", tag);
return 0;
}
@@ -1211,12 +1211,12 @@
return 1; /* error, return */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
if (mboxid == 0) {
/* mailbox does not exist */
- fprintf(ci->tx, "%s NO mailbox does not exist\r\n", tag);
+ ci_write(ci->tx, "%s NO mailbox does not exist\r\n", tag);
return 0;
}
@@ -1224,11 +1224,11 @@
use, so I guessed it should be lookup */
result = acl_has_right(ud->userid, mboxid, ACL_RIGHT_LOOKUP);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to unsubscribe from mailbox\r\n",
tag);
ud->state = IMAPCS_AUTHENTICATED;
@@ -1238,11 +1238,11 @@
}
if (db_unsubscribe(mboxid, ud->userid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
- fprintf(ci->tx, "%s OK UNSUBSCRIBE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK UNSUBSCRIBE completed\r\n", tag);
return 0;
}
@@ -1274,9 +1274,9 @@
/* this has special meaning; show root & delimiter */
trace(TRACE_ERROR,
"_ic_list(): showing delimiter [(\\NoSelect) \"/\" \"\"]");
- fprintf(ci->tx, "* %s (\\NoSelect) \"/\" \"\"\r\n",
+ ci_write(ci->tx, "* %s (\\NoSelect) \"/\" \"\"\r\n",
thisname);
- fprintf(ci->tx, "%s OK %s completed\r\n", tag, thisname);
+ ci_write(ci->tx, "%s OK %s completed\r\n", tag, thisname);
return 0;
}
@@ -1284,7 +1284,7 @@
for (i = 0, slen = strlen(args[0]); args[0][i]; i++) {
if (stridx(AcceptedMailboxnameChars, args[0][i]) == slen) {
/* wrong char found */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD reference name contains invalid characters\r\n",
tag);
return 1;
@@ -1297,7 +1297,7 @@
space. This is bound to fail sometime!! */
pattern = (char *) my_malloc(sizeof(char) * (plen + slen + 20));
if (!pattern) {
- fprintf(ci->tx, "* BYE out of memory\r\n");
+ ci_write(ci->tx, "* BYE out of memory\r\n");
return -1;
}
@@ -1335,14 +1335,14 @@
db_findmailbox_by_regex(ud->userid, pattern, &children,
&nchildren, list_is_lsub);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(children);
my_free(pattern);
return -1;
}
if (result == 1) {
- fprintf(ci->tx, "%s BAD invalid pattern specified\r\n",
+ ci_write(ci->tx, "%s BAD invalid pattern specified\r\n",
tag);
my_free(children);
my_free(pattern);
@@ -1356,18 +1356,18 @@
__FILE__, __FUNCTION__, i, children[i]);
result = db_getmailboxname(children[i], ud->userid, name);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(children);
my_free(pattern);
return -1;
}
- fprintf(ci->tx, "* %s (", thisname);
+ ci_write(ci->tx, "* %s (", thisname);
/* show flags */
result = db_isselectable(children[i]);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
my_free(children);
my_free(pattern);
@@ -1375,13 +1375,13 @@
}
if (!result)
- fprintf(ci->tx, "\\noselect ");
+ ci_write(ci->tx, "\\noselect ");
result = db_noinferiors(children[i]);
if (result == -1) {
trace(TRACE_ERROR, "%s,%s: error in call to db_noinferiors",
__FILE__, __FUNCTION__);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
my_free(children);
my_free(pattern);
@@ -1389,10 +1389,10 @@
}
if (result)
- fprintf(ci->tx, "\\noinferiors ");
+ ci_write(ci->tx, "\\noinferiors ");
/* show delimiter & name */
- fprintf(ci->tx, ") \"/\" \"%s\"\r\n", name);
+ ci_write(ci->tx, ") \"/\" \"%s\"\r\n", name);
}
if (children)
@@ -1400,7 +1400,7 @@
my_free(pattern);
- fprintf(ci->tx, "%s OK %s completed\r\n", tag, thisname);
+ ci_write(ci->tx, "%s OK %s completed\r\n", tag, thisname);
return 0;
}
@@ -1431,23 +1431,23 @@
imap_userdata_t *ud = (imap_userdata_t *) ci->userData;
mailbox_t mb;
int i, endfound, result;
-
+
if (ud->state != IMAPCS_AUTHENTICATED
&& ud->state != IMAPCS_SELECTED) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD STATUS command received in invalid state\r\n",
tag);
return 1;
}
if (!args[0] || !args[1] || !args[2]) {
- fprintf(ci->tx, "%s BAD missing argument(s) to STATUS\r\n",
+ ci_write(ci->tx, "%s BAD missing argument(s) to STATUS\r\n",
tag);
return 1;
}
if (strcmp(args[1], "(") != 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD argument list should be parenthesed\r\n",
tag);
return 1;
@@ -1461,7 +1461,7 @@
}
if (strcmp(args[i], "(") == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD too many parentheses specified\r\n",
tag);
return 1;
@@ -1469,12 +1469,12 @@
}
if (endfound == 2) {
- fprintf(ci->tx, "%s BAD argument list empty\r\n", tag);
+ ci_write(ci->tx, "%s BAD argument list empty\r\n", tag);
return 1;
}
if (args[endfound + 1]) {
- fprintf(ci->tx, "%s BAD argument list too long\r\n", tag);
+ ci_write(ci->tx, "%s BAD argument list too long\r\n", tag);
return 1;
}
@@ -1484,24 +1484,24 @@
/* check if mailbox exists */
if (db_findmailbox(args[0], ud->userid, &(mb.uid)) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
if (mb.uid == 0) {
/* mailbox does not exist */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO specified mailbox does not exist\r\n", tag);
return 1;
}
result = acl_has_right(ud->userid, mb.uid, ACL_RIGHT_READ);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no rights to get status for mailbox\r\n",
tag);
return 1;
@@ -1511,37 +1511,41 @@
result = db_getmailbox(&mb);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
-
- fprintf(ci->tx, "* STATUS \"%s\" (", args[0]);
-
+
+ char response[255];
+ char a[32];
+ snprintf(response,255, "* STATUS %s (", args[0]);
for (i = 2; args[i]; i++) {
+ if ((i > 2) && strcasecmp(args[i], ")"))
+ strncat(response, " ", 255 - strlen(response) - 1);
if (strcasecmp(args[i], "messages") == 0)
- fprintf(ci->tx, "MESSAGES %u ", mb.exists);
+ snprintf(a,32, "MESSAGES %u", mb.exists);
else if (strcasecmp(args[i], "recent") == 0)
- fprintf(ci->tx, "RECENT %u ", mb.recent);
+ snprintf(a,32, "RECENT %u", mb.recent);
else if (strcasecmp(args[i], "unseen") == 0)
- fprintf(ci->tx, "UNSEEN %u ", mb.unseen);
+ snprintf(a,32, "UNSEEN %u", mb.unseen);
else if (strcasecmp(args[i], "uidnext") == 0)
- fprintf(ci->tx, "UIDNEXT %llu ", mb.msguidnext);
+ snprintf(a,32, "UIDNEXT %llu", mb.msguidnext);
else if (strcasecmp(args[i], "uidvalidity") == 0)
- fprintf(ci->tx, "UIDVALIDITY %llu ", mb.uid);
+ snprintf(a,32, "UIDVALIDITY %llu", mb.uid);
else if (strcasecmp(args[i], ")") == 0)
break; /* done */
else {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n%s BAD unrecognized option '%s' specified\r\n",
tag, args[i]);
my_free(mb.seq_list);
return 1;
}
+ strncat(response, a, 255 - strlen(response) - 1);
}
-
- fprintf(ci->tx, ")\r\n");
-
- fprintf(ci->tx, "%s OK STATUS completed\r\n", tag);
+ strncat(response, ")\r\n", 255 - strlen(response) - 1);
+ trace(TRACE_DEBUG,"%s,%s: RESPONSE [ %s ]", __FILE__, __FUNCTION__, response);
+ ci_write(ci->tx, "%s", response);
+ ci_write(ci->tx, "%s OK STATUS completed\r\n", tag);
my_free(mb.seq_list);
return 0;
@@ -1567,7 +1571,7 @@
flaglist[i] = 0;
if (!args[0] || !args[1]) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid arguments specified to APPEND\r\n",
tag);
return 1;
@@ -1575,12 +1579,12 @@
/* find the mailbox to place the message */
if (db_findmailbox(args[0], ud->userid, &mboxid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error");
+ ci_write(ci->tx, "* BYE internal dbase error");
return -1;
}
if (mboxid == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO [TRYCREATE] could not find specified mailbox\r\n",
tag);
return 1;
@@ -1591,11 +1595,11 @@
/* check if user has right to append to mailbox */
result = acl_has_right(ud->userid, mboxid, ACL_RIGHT_INSERT);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to append to mailbox\r\n",
tag);
ud->state = IMAPCS_AUTHENTICATED;
@@ -1636,7 +1640,7 @@
if (!args[i]) {
trace(TRACE_INFO,
"ic_append(): unexpected end of arguments\n");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid arguments specified to APPEND\r\n",
tag);
return 1;
@@ -1652,12 +1656,12 @@
if (flaglist[IMAP_STORE_FLAG_SEEN] == 1) {
result = acl_has_right(ud->userid, mboxid, ACL_RIGHT_SEEN);
if (result < 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal database error\r\n");
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no right to store \\SEEN flag\r\n",
tag);
return 1;
@@ -1667,12 +1671,12 @@
result =
acl_has_right(ud->userid, mboxid, ACL_RIGHT_DELETE);
if (result < 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal database error\r\n");
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no right to store \\DELETED flag\r\n",
tag);
return 1;
@@ -1685,12 +1689,12 @@
result =
acl_has_right(ud->userid, mboxid, ACL_RIGHT_WRITE);
if (result < 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"*BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no right to store flags\r\n", tag);
return 1;
}
@@ -1731,23 +1735,23 @@
switch (result) {
case -1:
trace(TRACE_ERROR, "ic_append(): error appending msg\n");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal dbase error storing message\r\n");
break;
case 1:
trace(TRACE_ERROR, "ic_append(): faulty msg\n");
- fprintf(ci->tx, "%s NO invalid message specified\r\n",
+ ci_write(ci->tx, "%s NO invalid message specified\r\n",
tag);
break;
case 2:
trace(TRACE_INFO, "ic_append(): quotum would exceed\n");
- fprintf(ci->tx, "%s NO not enough quotum left\r\n", tag);
+ ci_write(ci->tx, "%s NO not enough quotum left\r\n", tag);
break;
case 0:
- fprintf(ci->tx, "%s OK APPEND completed\r\n", tag);
+ ci_write(ci->tx, "%s OK APPEND completed\r\n", tag);
break;
}
@@ -1790,16 +1794,16 @@
result =
acl_has_right(ud->userid, ud->mailbox.uid, ACL_RIGHT_READ);
if (result < 0) {
- fprintf(ci->tx, "* BYE Internal database error\r\n");
+ ci_write(ci->tx, "* BYE Internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx, "%s NO no permission to do check on "
+ ci_write(ci->tx, "%s NO no permission to do check on "
"mailbox\r\n", tag);
return 1;
}
- fprintf(ci->tx, "%s OK CHECK completed\r\n", tag);
+ ci_write(ci->tx, "%s OK CHECK completed\r\n", tag);
return 0;
}
@@ -1824,7 +1828,7 @@
result =
acl_has_right(ud->userid, ud->mailbox.uid, ACL_RIGHT_DELETE);
if (result < 0) {
- fprintf(ci->tx, "* BYE Internal database error\r\n");
+ ci_write(ci->tx, "* BYE Internal database error\r\n");
return -1;
}
/* only perform the expunge if the user has the right to do it */
@@ -1840,7 +1844,7 @@
my_free(ud->mailbox.seq_list);
memset(&ud->mailbox, 0, sizeof(ud->mailbox));
- fprintf(ci->tx, "%s OK CLOSE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK CLOSE completed\r\n", tag);
return 0;
}
@@ -1865,7 +1869,7 @@
return 1; /* error, return */
if (ud->mailbox.permission != IMAPPERM_READWRITE) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO you do not have write permission on this folder\r\n",
tag);
return 1;
@@ -1874,11 +1878,11 @@
result =
acl_has_right(ud->userid, ud->mailbox.uid, ACL_RIGHT_DELETE);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO you do not have delete rights on this "
"mailbox\r\n", tag);
return -1;
@@ -1887,7 +1891,7 @@
/* delete messages */
result = db_expunge(ud->mailbox.uid, ud->userid, &msgids, &nmsgs);
if (result == -1) {
- fprintf(ci->tx, "* BYE dbase/memory error\r\n");
+ ci_write(ci->tx, "* BYE dbase/memory error\r\n");
return -1;
}
@@ -1897,7 +1901,7 @@
binary_search(ud->mailbox.seq_list, ud->mailbox.exists,
msgids[i], &idx);
- fprintf(ci->tx, "* %u EXPUNGE\r\n", idx + 1); /* add one: IMAP MSN starts at 1 not zero */
+ ci_write(ci->tx, "* %u EXPUNGE\r\n", idx + 1); /* add one: IMAP MSN starts at 1 not zero */
}
my_free(msgids);
msgids = NULL;
@@ -1910,21 +1914,21 @@
result = db_getmailbox(&newmailbox);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
my_free(newmailbox.seq_list);
return -1; /* fatal */
}
if (newmailbox.exists != ud->mailbox.exists)
- fprintf(ci->tx, "* %u EXISTS\r\n", newmailbox.exists);
+ ci_write(ci->tx, "* %u EXISTS\r\n", newmailbox.exists);
if (newmailbox.recent != ud->mailbox.recent)
- fprintf(ci->tx, "* %u RECENT\r\n", newmailbox.recent);
+ ci_write(ci->tx, "* %u RECENT\r\n", newmailbox.recent);
my_free(ud->mailbox.seq_list);
memcpy(&ud->mailbox, &newmailbox, sizeof(newmailbox));
- fprintf(ci->tx, "%s OK EXPUNGE completed\r\n", tag);
+ ci_write(ci->tx, "%s OK EXPUNGE completed\r\n", tag);
return 0;
}
@@ -1944,7 +1948,7 @@
search_key_t sk;
if (ud->state != IMAPCS_SELECTED) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD SEARCH command received in invalid state\r\n",
tag);
return 1;
@@ -1954,7 +1958,7 @@
list_init(&sk.sub_search);
if (!args[0]) {
- fprintf(ci->tx, "%s BAD invalid arguments to SEARCH\r\n",
+ ci_write(ci->tx, "%s BAD invalid arguments to SEARCH\r\n",
tag);
return 1;
}
@@ -1962,13 +1966,13 @@
if (strcasecmp(args[0], "charset") == 0) {
/* charset specified */
if (!args[1]) {
- fprintf(ci->tx, "%s BAD invalid argument list\r\n",
+ ci_write(ci->tx, "%s BAD invalid argument list\r\n",
tag);
return 1;
}
if (strcasecmp(args[1], "us-ascii") != 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO specified charset is not supported\r\n",
tag);
return 0;
@@ -1985,13 +1989,13 @@
if (result == -2) {
free_searchlist(&sk.sub_search);
- fprintf(ci->tx, "* BYE server ran out of memory\r\n");
+ ci_write(ci->tx, "* BYE server ran out of memory\r\n");
return -1;
}
if (result == -1) {
free_searchlist(&sk.sub_search);
- fprintf(ci->tx, "%s BAD syntax error in search keys\r\n",
+ ci_write(ci->tx, "%s BAD syntax error in search keys\r\n",
tag);
return 1;
}
@@ -2000,12 +2004,12 @@
result =
acl_has_right(ud->userid, ud->mailbox.uid, ACL_RIGHT_READ);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
free_searchlist(&sk.sub_search);
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to search mailbox\r\n", tag);
free_searchlist(&sk.sub_search);
return 1;
@@ -2024,7 +2028,7 @@
if (result == -1)
{
free_searchlist(&sk.sub_search);
-fprintf(ci->tx,"* BYE internal dbase error\r\n");
+ci_write(ci->tx,"* BYE internal dbase error\r\n");
return -1;
}
*/
@@ -2035,7 +2039,7 @@
ud->mailbox.exists);
if (!result_set) {
free_searchlist(&sk.sub_search);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE server ran out of memory\r\n");
return -1;
}
@@ -2055,7 +2059,7 @@
if (result < 0) {
free_searchlist(&sk.sub_search);
my_free(result_set);
- fprintf(ci->tx, "%s", (result == -1) ?
+ ci_write(ci->tx, "%s", (result == -1) ?
"* BYE internal dbase error\r\n" :
"* BYE server ran out of memory\r\n");
@@ -2075,24 +2079,24 @@
free_searchlist(&sk.sub_search);
if (result == 1) {
- fprintf(ci->tx, "* BYE error synchronizing dbase\r\n");
+ ci_write(ci->tx, "* BYE error synchronizing dbase\r\n");
return -1;
}
/* ok, display results */
- fprintf(ci->tx, "* SEARCH");
+ ci_write(ci->tx, "* SEARCH");
for (i = 0; i < ud->mailbox.exists; i++) {
if (result_set[i])
- fprintf(ci->tx, " %llu",
+ ci_write(ci->tx, " %llu",
imapcommands_use_uid ? ud->mailbox.
seq_list[i] : (u64_t) (i + 1));
}
- fprintf(ci->tx, "\r\n");
+ ci_write(ci->tx, "\r\n");
my_free(result_set);
- fprintf(ci->tx, "%s OK SEARCH completed\r\n", tag);
+ ci_write(ci->tx, "%s OK SEARCH completed\r\n", tag);
return 0;
}
@@ -2134,14 +2138,14 @@
memset(&headermsg, 0, sizeof(headermsg));
if (ud->state != IMAPCS_SELECTED) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD FETCH command received in invalid state\r\n",
tag);
return 1;
}
if (!args[0] || !args[1]) {
- fprintf(ci->tx, "%s BAD missing argument(s) to FETCH\r\n",
+ ci_write(ci->tx, "%s BAD missing argument(s) to FETCH\r\n",
tag);
return 1;
}
@@ -2150,11 +2154,11 @@
result =
acl_has_right(ud->userid, ud->mailbox.uid, ACL_RIGHT_READ);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to fetch from mailbox\r\n",
tag);
return 1;
@@ -2168,7 +2172,7 @@
idx = next_fetch_item(args, idx, &fetchitem);
if (idx == -2) {
list_freelist(&fetch_list.start);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid argument list to fetch\r\n",
tag);
return 1;
@@ -2178,7 +2182,7 @@
&& !list_nodeadd(&fetch_list, &fetchitem,
sizeof(fetchitem))) {
list_freelist(&fetch_list.start);
- fprintf(ci->tx, "* BYE out of memory\r\n");
+ ci_write(ci->tx, "* BYE out of memory\r\n");
return 1;
}
@@ -2236,7 +2240,7 @@
if (!list_nodeadd
(&fetch_list, &fetchitem, sizeof(fetchitem))) {
list_freelist(&fetch_list.start);
- fprintf(ci->tx, "* BYE out of memory\r\n");
+ ci_write(ci->tx, "* BYE out of memory\r\n");
return -1;
}
}
@@ -2255,10 +2259,10 @@
(imapcommands_use_uid ? (ud->mailbox.msguidnext - 1) :
ud->mailbox.exists)) {
if (imapcommands_use_uid)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s OK FETCH completed\r\n", tag);
else
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid message range specified\r\n",
tag);
@@ -2284,7 +2288,7 @@
? (ud->mailbox.msguidnext -
1) : ud->mailbox.exists)) {
if (!imapcommands_use_uid) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid message range specified\r\n",
tag);
@@ -2306,7 +2310,7 @@
break;
default:
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid character in message range\r\n",
tag);
list_freelist(&fetch_list.start);
@@ -2344,14 +2348,14 @@
if (result == -1) {
list_freelist(&fetch_list.start);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal dbase error\r\n");
return -1;
}
if (result == -2) {
list_freelist(&fetch_list.start);
- fprintf(ci->tx, "* BYE out of memory\r\n");
+ ci_write(ci->tx, "* BYE out of memory\r\n");
return -1;
}
@@ -2363,7 +2367,7 @@
uid,
&headermsg);
if (result == -2) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist(&fetch_list.
start);
@@ -2371,7 +2375,7 @@
return -1;
}
if (result == -3) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE out of memory\r\n");
list_freelist(&fetch_list.
start);
@@ -2399,7 +2403,7 @@
* when building the mailbox info
* let's call it fatal and let the client re-connect :)
*/
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal syncing error\r\n");
list_freelist(&fetch_list.start);
@@ -2407,7 +2411,7 @@
return -1;
}
- fprintf(ci->tx, "* %u FETCH (", (fn + 1));
+ ci_write(ci->tx, "* %u FETCH (", (fn + 1));
curr = list_getstart(&fetch_list);
isfirstfetchout = 1;
@@ -2423,10 +2427,10 @@
isfirstfetchout =
0;
else
- fprintf(ci->tx,
+ ci_write(ci->tx,
" ");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"INTERNALDATE \"%s\"",
date_sql2imap
(msginfo[i].
@@ -2438,10 +2442,10 @@
isfirstfetchout =
0;
else
- fprintf(ci->tx,
+ ci_write(ci->tx,
" ");
- fprintf(ci->tx, "UID %llu",
+ ci_write(ci->tx, "UID %llu",
msginfo[i].uid);
}
@@ -2450,10 +2454,10 @@
isfirstfetchout =
0;
else
- fprintf(ci->tx,
+ ci_write(ci->tx,
" ");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"RFC822.SIZE %llu",
msginfo[i].
rfcsize);
@@ -2466,10 +2470,10 @@
isfirstfetchout =
0;
else
- fprintf(ci->tx,
+ ci_write(ci->tx,
" ");
- fprintf(ci->tx, "FLAGS (");
+ ci_write(ci->tx, "FLAGS (");
for (j = 0;
j < IMAP_NFLAGS;
j++) {
@@ -2490,13 +2494,13 @@
0;
}
}
- fprintf(ci->tx, ")");
+ ci_write(ci->tx, ")");
}
curr = curr->nextnode;
}
- fprintf(ci->tx, ")\r\n");
+ ci_write(ci->tx, ")\r\n");
}
my_free(msginfo);
@@ -2513,7 +2517,7 @@
if (imapcommands_use_uid) {
if (i > ud->mailbox.msguidnext - 1) {
/* passed the last one */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s OK FETCH completed\r\n",
tag);
list_freelist(&fetch_list.start);
@@ -2527,10 +2531,10 @@
continue;
}
- fprintf(ci->tx, "* %u FETCH (", fn + 1);
+ ci_write(ci->tx, "* %u FETCH (", fn + 1);
} else
- fprintf(ci->tx, "* %llu FETCH (", i + 1);
+ ci_write(ci->tx, "* %llu FETCH (", i + 1);
trace(TRACE_DEBUG,
"Fetching msgID %llu (fetch num %llu)",
@@ -2554,7 +2558,7 @@
if (db_get_rfcsize
(thisnum, ud->mailbox.uid,
&rfcsize) == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist(&fetch_list.
start);
@@ -2586,7 +2590,7 @@
&headermsg.rfcheader);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist
(&fetch_list.
@@ -2597,7 +2601,7 @@
}
if (result == -2) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE out of memory\r\n");
list_freelist
(&fetch_list.
@@ -2628,7 +2632,7 @@
(thisnum,
&cached_msg.msg);
if (result == -2) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist
(&fetch_list.
@@ -2638,7 +2642,7 @@
return -1;
}
if (result == -3) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE out of memory\r\n");
list_freelist
(&fetch_list.
@@ -2689,7 +2693,7 @@
db_get_msgdate(ud->mailbox.uid,
thisnum, date);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist(&fetch_list.
start);
@@ -2700,9 +2704,9 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"INTERNALDATE \"%s\"",
date_sql2imap(date));
}
@@ -2711,9 +2715,9 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx, "UID %llu",
+ ci_write(ci->tx, "UID %llu",
thisnum);
}
@@ -2721,15 +2725,15 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx, "BODYSTRUCTURE ");
+ ci_write(ci->tx, "BODYSTRUCTURE ");
result =
retrieve_structure(ci->tx,
&cached_msg.
msg, 1);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE error fetching body structure\r\n");
list_freelist(&fetch_list.
start);
@@ -2742,15 +2746,15 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx, "BODY ");
+ ci_write(ci->tx, "BODY ");
result =
retrieve_structure(ci->tx,
&cached_msg.
msg, 0);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE error fetching body\r\n");
list_freelist(&fetch_list.
start);
@@ -2763,9 +2767,9 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx, "ENVELOPE ");
+ ci_write(ci->tx, "ENVELOPE ");
result =
retrieve_envelope(ci->tx,
&cached_msg.
@@ -2773,7 +2777,7 @@
rfcheader);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE error fetching envelope structure\r\n");
list_freelist(&fetch_list.
start);
@@ -2827,9 +2831,9 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx,
+ ci_write(ci->tx,
"RFC822 {%llu}\r\n",
cached_msg.dumpsize);
send_data(ci->tx,
@@ -2845,9 +2849,9 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx, "RFC822.SIZE %llu",
+ ci_write(ci->tx, "RFC822.SIZE %llu",
rfcsize);
}
@@ -2893,13 +2897,13 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
if (fi->bodyfetch.octetstart == -1) {
mseek(cached_msg.memdump,
0, SEEK_SET);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"BODY[] {%llu}\r\n",
cached_msg.
dumpsize);
@@ -2934,7 +2938,7 @@
octetstart) : fi->
bodyfetch.octetcnt;
- fprintf(ci->tx,
+ ci_write(ci->tx,
"BODY[]<%llu> {%llu}\r\n",
fi->bodyfetch.
octetstart,
@@ -2961,7 +2965,7 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
if (cached_msg.num == thisnum) {
mrewind(cached_msg.
@@ -2976,7 +2980,7 @@
mseek(cached_msg.tmpdump,
0, SEEK_SET);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"RFC822.HEADER {%llu}\r\n",
tmpdumpsize);
send_data(ci->tx,
@@ -2998,7 +3002,7 @@
mseek(cached_msg.tmpdump,
0, SEEK_SET);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"RFC822.HEADER {%llu}\r\n",
tmpdumpsize);
send_data(ci->tx,
@@ -3012,7 +3016,7 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
mrewind(cached_msg.tmpdump);
tmpdumpsize =
@@ -3027,7 +3031,7 @@
mseek(cached_msg.tmpdump, 0,
SEEK_SET);
- fprintf(ci->tx,
+ ci_write(ci->tx,
"RFC822.TEXT {%llu}\r\n",
tmpdumpsize);
send_data(ci->tx,
@@ -3043,7 +3047,7 @@
if (fi->bodyfetch.partspec[0]) {
if (fi->bodyfetch.
partspec[0] == '0') {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n%s BAD protocol error\r\n",
tag);
trace(TRACE_DEBUG,
@@ -3160,14 +3164,14 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
if (fi->bodyfetch.noseen)
- fprintf(ci->tx, "BODY[%s",
+ ci_write(ci->tx, "BODY[%s",
fi->bodyfetch.
partspec);
else {
- fprintf(ci->tx, "BODY[%s",
+ ci_write(ci->tx, "BODY[%s",
fi->bodyfetch.
partspec);
setseen = 1;
@@ -3176,7 +3180,7 @@
switch (fi->bodyfetch.itemtype) {
case BFIT_TEXT_SILENT:
if (!msgpart)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"] NIL ");
else {
tmpdumpsize = 0;
@@ -3263,9 +3267,9 @@
case BFIT_TEXT:
/* dump body text */
- fprintf(ci->tx, "TEXT");
+ ci_write(ci->tx, "TEXT");
if (!msgpart)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"] NIL ");
else {
tmpdumpsize =
@@ -3336,11 +3340,11 @@
break;
case BFIT_HEADER:
- fprintf(ci->tx, "HEADER");
+ ci_write(ci->tx, "HEADER");
if (!msgpart
||
only_text_from_msgpart)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"] NIL\r\n");
else {
tmpdumpsize =
@@ -3410,7 +3414,7 @@
break;
case BFIT_HEADER_FIELDS:
- fprintf(ci->tx,
+ ci_write(ci->tx,
"HEADER.FIELDS (");
isfirstout = 1;
@@ -3442,12 +3446,12 @@
argstart]);
}
- fprintf(ci->tx, ")] ");
+ ci_write(ci->tx, ")] ");
if (!msgpart
||
only_text_from_msgpart)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"NIL\r\n");
else {
tmpdumpsize =
@@ -3520,7 +3524,7 @@
}
break;
case BFIT_HEADER_FIELDS_NOT:
- fprintf(ci->tx,
+ ci_write(ci->tx,
"HEADER.FIELDS.NOT (");
isfirstout = 1;
@@ -3552,12 +3556,12 @@
argstart]);
}
- fprintf(ci->tx, ")] ");
+ ci_write(ci->tx, ")] ");
if (!msgpart
||
only_text_from_msgpart)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"NIL\r\n");
else {
tmpdumpsize =
@@ -3630,10 +3634,10 @@
}
break;
case BFIT_MIME:
- fprintf(ci->tx, "MIME] ");
+ ci_write(ci->tx, "MIME] ");
if (!msgpart)
- fprintf(ci->tx,
+ ci_write(ci->tx,
"NIL\r\n");
else {
tmpdumpsize =
@@ -3702,7 +3706,7 @@
break;
default:
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal server error\r\n");
list_freelist(&fetch_list.
start);
@@ -3726,7 +3730,7 @@
ud->mailbox.uid,
ACL_RIGHT_SEEN);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n *BYE internal dbase "
"error\r\n");
list_freelist(&fetch_list.start);
@@ -3741,7 +3745,7 @@
setSeenSet,
IMAPFA_ADD);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist(&fetch_list.
start);
@@ -3751,7 +3755,7 @@
}
fi->getFlags = 1;
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
}
/* FLAGS ? */
@@ -3759,9 +3763,9 @@
if (isfirstfetchout)
isfirstfetchout = 0;
else
- fprintf(ci->tx, " ");
+ ci_write(ci->tx, " ");
- fprintf(ci->tx, "FLAGS (");
+ ci_write(ci->tx, "FLAGS (");
isfirstout = 1;
@@ -3771,7 +3775,7 @@
uid,
msgflags);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
list_freelist(&fetch_list.
start);
@@ -3799,14 +3803,14 @@
[j]);
}
}
- fprintf(ci->tx, ")");
+ ci_write(ci->tx, ")");
}
curr = curr->nextnode;
}
if (!bad_response_send)
- fprintf(ci->tx, ")\r\n");
+ ci_write(ci->tx, ")\r\n");
}
}
@@ -3815,7 +3819,7 @@
list_freelist(&fetch_list.start);
db_free_msg(&headermsg);
- fprintf(ci->tx, "%s OK %sFETCH completed\r\n", tag,
+ ci_write(ci->tx, "%s OK %sFETCH completed\r\n", tag,
imapcommands_use_uid ? "UID " : "");
return 0;
}
@@ -3840,21 +3844,21 @@
memset(flaglist, 0, sizeof(int) * IMAP_NFLAGS);
if (ud->state != IMAPCS_SELECTED) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD STORE command received in invalid state\r\n",
tag);
return 1;
}
if (!args[0] || !args[1] || !args[2]) {
- fprintf(ci->tx, "%s BAD missing argument(s) to STORE\r\n",
+ ci_write(ci->tx, "%s BAD missing argument(s) to STORE\r\n",
tag);
return 1;
}
/* multiple flags should be parenthesed */
if (args[3] && strcmp(args[2], "(") != 0) {
- fprintf(ci->tx, "%s BAD invalid argument(s) to STORE\r\n",
+ ci_write(ci->tx, "%s BAD invalid argument(s) to STORE\r\n",
tag);
return 1;
}
@@ -3879,7 +3883,7 @@
}
if (action == IMAPFA_NONE) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid STORE action specified\r\n", tag);
return 1;
}
@@ -3896,7 +3900,7 @@
}
if (j == IMAP_NFLAGS) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid flag list to STORE command\r\n",
tag);
return 1;
@@ -3909,11 +3913,11 @@
acl_has_right(ud->userid, ud->mailbox.uid,
ACL_RIGHT_SEEN);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error");
+ ci_write(ci->tx, "* BYE internal database error");
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no right to store \\SEEN flag\r\n",
tag);
return 1;
@@ -3924,11 +3928,11 @@
acl_has_right(ud->userid, ud->mailbox.uid,
ACL_RIGHT_DELETE);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no right to store \\DELETED flag\r\n",
tag);
return 1;
@@ -3942,11 +3946,11 @@
acl_has_right(ud->userid, ud->mailbox.uid,
ACL_RIGHT_WRITE);
if (result < 0) {
- fprintf(ci->tx, "*BYE internal database error");
+ ci_write(ci->tx, "*BYE internal database error");
return -1;
}
if (result == 0) {
- fprintf(ci->tx, "%s NO no right to store flags",
+ ci_write(ci->tx, "%s NO no right to store flags",
tag);
return 1;
}
@@ -3965,7 +3969,7 @@
if (store_start == 0 || store_start >
(imapcommands_use_uid ? (ud->mailbox.msguidnext - 1) :
ud->mailbox.exists)) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid message range specified\r\n",
tag);
return 1;
@@ -3988,7 +3992,7 @@
(imapcommands_use_uid
? (ud->mailbox.msguidnext -
1) : ud->mailbox.exists)) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid message range specified\r\n",
tag);
return 1;
@@ -4007,7 +4011,7 @@
break;
default:
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid character in message range\r\n",
tag);
return 1;
@@ -4037,7 +4041,7 @@
flaglist, action);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
return -1;
}
@@ -4048,12 +4052,12 @@
ud->mailbox.uid,
msgflags);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
return -1;
}
- fprintf(ci->tx, "* %llu FETCH (FLAGS (",
+ ci_write(ci->tx, "* %llu FETCH (FLAGS (",
imapcommands_use_uid ? (u64_t) (fn
+
1)
@@ -4062,7 +4066,7 @@
for (j = 0, isfirstout = 1;
j < IMAP_NFLAGS; j++) {
if (msgflags[j]) {
- fprintf(ci->tx, "%s%s",
+ ci_write(ci->tx, "%s%s",
isfirstout ? "" :
" ",
imap_flag_desc_escaped
@@ -4072,7 +4076,7 @@
}
}
- fprintf(ci->tx, "))\r\n");
+ ci_write(ci->tx, "))\r\n");
}
} else {
if (!imapcommands_use_uid) {
@@ -4090,7 +4094,7 @@
flaglist, action);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
return -1;
}
@@ -4117,12 +4121,12 @@
uid,
msgflags);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"\r\n* BYE internal dbase error\r\n");
return -1;
}
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* %llu FETCH (FLAGS (",
imapcommands_use_uid
? (u64_t) (fn + 1) : i +
@@ -4131,7 +4135,7 @@
for (j = 0, isfirstout = 1;
j < IMAP_NFLAGS; j++) {
if (msgflags[j]) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s%s",
isfirstout
? "" : " ",
@@ -4143,13 +4147,13 @@
}
}
- fprintf(ci->tx, "))\r\n");
+ ci_write(ci->tx, "))\r\n");
}
}
}
}
- fprintf(ci->tx, "%s OK %sSTORE completed\r\n", tag,
+ ci_write(ci->tx, "%s OK %sSTORE completed\r\n", tag,
imapcommands_use_uid ? "UID " : "");
return 0;
}
@@ -4176,12 +4180,12 @@
/* check if destination mailbox exists */
if (db_findmailbox(args[1], ud->userid, &destmboxid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1; /* fatal */
}
if (destmboxid == 0) {
/* error: cannot select mailbox */
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO [TRYCREATE] specified mailbox does not exist\r\n",
tag);
return 1;
@@ -4190,11 +4194,11 @@
result =
acl_has_right(ud->userid, ud->mailbox.uid, ACL_RIGHT_READ);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to copy from mailbox\r\n",
tag);
return 1;
@@ -4202,11 +4206,11 @@
// check if user has right to COPY to destination mailbox
result = acl_has_right(ud->userid, destmboxid, ACL_RIGHT_INSERT);
if (result < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1; /* fatal */
}
if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO no permission to copy to mailbox\r\n", tag);
return 1;
}
@@ -4223,7 +4227,7 @@
if (copy_start == 0 || copy_start >
(imapcommands_use_uid ? (ud->mailbox.msguidnext - 1) :
ud->mailbox.exists)) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid message range specified\r\n",
tag);
return 1;
@@ -4246,7 +4250,7 @@
(imapcommands_use_uid
? (ud->mailbox.msguidnext -
1) : ud->mailbox.exists)) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid message range specified\r\n",
tag);
return 1;
@@ -4265,7 +4269,7 @@
break;
default:
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD invalid character in message range\r\n",
tag);
return 1;
@@ -4293,12 +4297,12 @@
db_copymsg(thisnum, destmboxid, ud->userid,
&new_msgid);
if (result == -1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* BYE internal dbase error\r\n");
return -1;
}
if (result == -2) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO quotum would exceed\r\n",
tag);
return 1;
@@ -4306,7 +4310,7 @@
}
}
- fprintf(ci->tx, "%s OK %sCOPY completed\r\n", tag,
+ ci_write(ci->tx, "%s OK %sCOPY completed\r\n", tag,
imapcommands_use_uid ? "UID " : "");
return 0;
}
@@ -4323,14 +4327,14 @@
int result;
if (ud->state != IMAPCS_SELECTED) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s BAD UID command received in invalid state\r\n",
tag);
return 1;
}
if (!args[0]) {
- fprintf(ci->tx, "%s BAD missing argument(s) to UID\r\n",
+ ci_write(ci->tx, "%s BAD missing argument(s) to UID\r\n",
tag);
return 1;
}
@@ -4346,7 +4350,7 @@
else if (strcasecmp(args[0], "search") == 0)
result = _ic_search(tag, &args[1], ci);
else {
- fprintf(ci->tx, "%s BAD invalid UID command\r\n", tag);
+ ci_write(ci->tx, "%s BAD invalid UID command\r\n", tag);
result = 1;
}
@@ -4376,7 +4380,7 @@
default:
continue;
}
- fprintf(ci->tx,
+ ci_write(ci->tx,
"* QUOTA \"%s\" (%s %llu %llu)\r\n",
quota->root, name, usage, limit);
}
@@ -4400,22 +4404,22 @@
root = quota_get_quotaroot(ud->userid, args[0], &errormsg);
if (root == NULL) {
- fprintf(ci->tx, "%s NO %s\r\n", tag, errormsg);
+ ci_write(ci->tx, "%s NO %s\r\n", tag, errormsg);
return 1;
}
quota = quota_get_quota(ud->userid, root, &errormsg);
if (quota == NULL) {
- fprintf(ci->tx, "%s NO %s\r\n", tag, errormsg);
+ ci_write(ci->tx, "%s NO %s\r\n", tag, errormsg);
return 1;
}
- fprintf(ci->tx, "* QUOTAROOT \"%s\" \"%s\"\r\n", args[0],
+ ci_write(ci->tx, "* QUOTAROOT \"%s\" \"%s\"\r\n", args[0],
quota->root);
send_quota(quota, ci);
quota_free(quota);
- fprintf(ci->tx, "%s OK GETQUOTAROOT completed\r\n", tag);
+ ci_write(ci->tx, "%s OK GETQUOTAROOT completed\r\n", tag);
return 0;
}
@@ -4436,14 +4440,14 @@
quota = quota_get_quota(ud->userid, args[0], &errormsg);
if (quota == NULL) {
- fprintf(ci->tx, "%s NO %s\r\n", tag, errormsg);
+ ci_write(ci->tx, "%s NO %s\r\n", tag, errormsg);
return 1;
}
send_quota(quota, ci);
quota_free(quota);
- fprintf(ci->tx, "%s OK GETQUOTA completed\r\n", tag);
+ ci_write(ci->tx, "%s OK GETQUOTA completed\r\n", tag);
return 0;
}
@@ -4480,26 +4484,26 @@
result = imap_acl_pre_administer(args[0], args[1], ud->userid,
&mboxid, &targetuserid);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
} else if (result == 0) {
- fprintf(ci->tx, "%s NO SETACL failure: can't set acl\r\n",
+ ci_write(ci->tx, "%s NO SETACL failure: can't set acl\r\n",
tag);
return 1;
}
// has the rights to 'administer' this mailbox?
if (acl_has_right(ud->userid, mboxid, ACL_RIGHT_ADMINISTER) != 1) {
- fprintf(ci->tx, "%s NO SETACL failure: can't set acl, "
+ ci_write(ci->tx, "%s NO SETACL failure: can't set acl, "
"you don't have the proper rights\r\n", tag);
return 1;
}
// set the new acl
if (acl_set_rights(targetuserid, mboxid, args[2]) < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
- fprintf(ci->tx, "%s OK SETACL completed\r\n", tag);
+ ci_write(ci->tx, "%s OK SETACL completed\r\n", tag);
return 0;
}
@@ -4517,22 +4521,22 @@
if (imap_acl_pre_administer(args[0], args[1], ud->userid,
&mboxid, &targetuserid) == -1) {
- fprintf(ci->tx, "* BYE internal dbase error\r\n");
+ ci_write(ci->tx, "* BYE internal dbase error\r\n");
return -1;
}
// has the rights to 'administer' this mailbox?
if (acl_has_right(ud->userid, mboxid, ACL_RIGHT_ADMINISTER) != 1) {
- fprintf(ci->tx, "%s NO DELETEACL failure: can't delete "
+ ci_write(ci->tx, "%s NO DELETEACL failure: can't delete "
"acl\r\n", tag);
return 1;
}
// set the new acl
if (acl_delete_acl(targetuserid, mboxid) < 0) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
- fprintf(ci->tx, "%s OK DELETEACL completed\r\n", tag);
+ ci_write(ci->tx, "%s OK DELETEACL completed\r\n", tag);
return 0;
}
@@ -4550,22 +4554,22 @@
result = db_findmailbox(args[0], ud->userid, &mboxid);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
} else if (result == 0) {
- fprintf(ci->tx, "%s NO GETACL failure: can't get acl\r\n",
+ ci_write(ci->tx, "%s NO GETACL failure: can't get acl\r\n",
tag);
return 1;
}
// get acl string (string of identifier-rights pairs)
if (!(acl_string = acl_get_acl(mboxid))) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
- fprintf(ci->tx, "* ACL \"%s\" %s\r\n", args[0], acl_string);
+ ci_write(ci->tx, "* ACL \"%s\" %s\r\n", args[0], acl_string);
my_free(acl_string);
- fprintf(ci->tx, "%s OK GETACL completed\r\n", tag);
+ ci_write(ci->tx, "%s OK GETACL completed\r\n", tag);
return 0;
}
@@ -4586,30 +4590,30 @@
result = imap_acl_pre_administer(args[0], args[1], ud->userid,
&mboxid, &targetuserid);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
} else if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s, NO LISTRIGHTS failure: can't set acl\r\n",
tag);
return 1;
}
// has the rights to 'administer' this mailbox?
if (acl_has_right(ud->userid, mboxid, ACL_RIGHT_ADMINISTER) != 1) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s NO LISTRIGHTS failure: can't set acl\r\n",
tag);
return 1;
}
// set the new acl
if (!(listrights_string = acl_listrights(targetuserid, mboxid))) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
- fprintf(ci->tx, "* LISTRIGHTS \"%s\" %s %s\r\n",
+ ci_write(ci->tx, "* LISTRIGHTS \"%s\" %s %s\r\n",
args[0], args[1], listrights_string);
- fprintf(ci->tx, "%s OK LISTRIGHTS completed\r\n", tag);
+ ci_write(ci->tx, "%s OK LISTRIGHTS completed\r\n", tag);
return 0;
}
@@ -4627,24 +4631,24 @@
result = db_findmailbox(args[0], ud->userid, &mboxid);
if (result == -1) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
} else if (result == 0) {
- fprintf(ci->tx,
+ ci_write(ci->tx,
"%s, NO MYRIGHTS failure: unknown mailbox\r\n",
tag);
return 1;
}
if (!(myrights_string = acl_myrights(ud->userid, mboxid))) {
- fprintf(ci->tx, "* BYE internal database error\r\n");
+ ci_write(ci->tx, "* BYE internal database error\r\n");
return -1;
}
- fprintf(ci->tx, "* MYRIGHTS \"%s\" %s\r\n", args[0],
+ ci_write(ci->tx, "* MYRIGHTS \"%s\" %s\r\n", args[0],
myrights_string);
my_free(myrights_string);
- fprintf(ci->tx, "%s OK MYRIGHTS complete\r\n", tag);
+ ci_write(ci->tx, "%s OK MYRIGHTS complete\r\n", tag);
return 0;
}
@@ -4655,10 +4659,10 @@
IMAPCS_AUTHENTICATED, ci))
return 1;
- fprintf(ci->tx, "* NAMESPACE ((\"\" \"%s\")) ((\"%s\" \"%s\")) "
+ ci_write(ci->tx, "* NAMESPACE ((\"\" \"%s\")) ((\"%s\" \"%s\")) "
"((\"%s\" \"%s\"))\r\n",
MAILBOX_SEPERATOR, NAMESPACE_USER,
MAILBOX_SEPERATOR, NAMESPACE_PUBLIC, MAILBOX_SEPERATOR);
- fprintf(ci->tx, "%s OK NAMESPACE complete\r\n", tag);
+ ci_write(ci->tx, "%s OK NAMESPACE complete\r\n", tag);
return 0;
}
diff -urNad /usr/src/dbmail2/dbmail-2.0/imaputil.c dbmail-2.0/imaputil.c
--- /usr/src/dbmail2/dbmail-2.0/imaputil.c 2004-04-16 00:24:26.000000000 +0200
+++ dbmail-2.0/imaputil.c 2004-04-16 00:30:39.000000000 +0200
@@ -3094,3 +3094,17 @@
cached_msg.dumpsize = 0;
return 0;
}
+
+int ci_write(FILE * fd, char * msg, ...)
+{
+ va_list ap;
+ va_start(ap, msg);
+
+ if (feof(fd) || vfprintf(fd,msg,ap) < 0 || fflush(fd) < 0) {
+ va_end(ap);
+ return -1;
+ }
+ va_end(ap);
+ return 0;
+}
+
diff -urNad /usr/src/dbmail2/dbmail-2.0/imaputil.h dbmail-2.0/imaputil.h
--- /usr/src/dbmail2/dbmail-2.0/imaputil.h 2004-04-16 00:24:26.000000000 +0200
+++ dbmail-2.0/imaputil.h 2004-04-16 00:30:39.000000000 +0200
@@ -96,4 +96,5 @@
int init_cache(void);
void close_cache(void);
+int ci_write(FILE * fd, char * msg, ...);
#endif