int num_processed = 0;
long thismsg;
struct MetaData smi;
- struct CtdlMessage *msg;
+ struct CtdlMessage *msg = NULL;
int is_seen = 0;
long lastold = 0L;
int printed_lastold = 0;
template = (struct CtdlMessage *)
malloc(sizeof(struct CtdlMessage));
memset(template, 0, sizeof(struct CtdlMessage));
+ template->cm_magic = CTDLMESSAGE_MAGIC;
+ template->cm_anon_type = MES_NORMAL;
+
while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
extract_token(tfield, buf, 0, '|', sizeof tfield);
extract_token(tvalue, buf, 1, '|', sizeof tvalue);
{
int i;
- if (is_valid_message(msg) == 0) return;
+ if (is_valid_message(msg) == 0)
+ {
+ if (msg != NULL) free (msg);
+ return;
+ }
for (i = 0; i < 256; ++i)
if (msg->cm_fields[i] != NULL) {
++start_of_text;
start_of_text = strstr(start_of_text, "\n");
++start_of_text;
+
+ char outbuf[1024];
+ int outlen = 0;
+ int nllen = strlen(nl);
while (ch=*mptr, ch!=0) {
if (ch==13) {
/* do nothing */
}
- else switch(headers_only) {
- case HEADERS_NONE:
- if (mptr >= start_of_text) {
- if (ch == 10) cprintf("%s", nl);
- else cprintf("%c", ch);
+ else {
+ if (
+ ((headers_only == HEADERS_NONE) && (mptr >= start_of_text))
+ || ((headers_only == HEADERS_ONLY) && (mptr < start_of_text))
+ || ((headers_only != HEADERS_NONE) && (headers_only != HEADERS_ONLY))
+ ) {
+ if (ch == 10) {
+ sprintf(&outbuf[outlen], "%s", nl);
+ outlen += nllen;
}
- break;
- case HEADERS_ONLY:
- if (mptr < start_of_text) {
- if (ch == 10) cprintf("%s", nl);
- else cprintf("%c", ch);
+ else {
+ outbuf[outlen++] = ch;
}
- break;
- default:
- if (ch == 10) cprintf("%s", nl);
- else cprintf("%c", ch);
- break;
+ }
}
++mptr;
+ if (outlen > 1000) {
+ client_write(outbuf, outlen);
+ outlen = 0;
+ }
+ }
+ if (outlen > 0) {
+ client_write(outbuf, outlen);
+ outlen = 0;
}
+
goto DONE;
}
}
void cmd_msg3(char *cmdbuf)
{
long msgnum;
- struct CtdlMessage *msg;
+ struct CtdlMessage *msg = NULL;
struct ser_ret smr;
if (CC->internal_pgm == 0) {
lprintf(CTDL_DEBUG, "Delivering private local mail to <%s>\n",
recipient);
if (getuser(&userbuf, recipient) == 0) {
+ // Add a flag so the Funambol module knows its mail
+ msg->cm_fields['W'] = strdup(recipient);
MailboxName(actual_rm, sizeof actual_rm,
&userbuf, MAILROOM);
CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0, msg);
BumpNewMailCounter(userbuf.usernum);
+ if (strlen(config.c_funambol_host) > 0) {
+ /* Generate a instruction message for the Funambol notification
+ server, in the same style as the SMTP queue */
+ instr = malloc(SIZ * 2);
+ snprintf(instr, SIZ * 2,
+ "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
+ "bounceto|%s@%s\n",
+ SPOOLMIME, newmsgid, (long)time(NULL),
+ msg->cm_fields['A'], msg->cm_fields['N']
+ );
+
+ imsg = malloc(sizeof(struct CtdlMessage));
+ memset(imsg, 0, sizeof(struct CtdlMessage));
+ imsg->cm_magic = CTDLMESSAGE_MAGIC;
+ imsg->cm_anon_type = MES_NORMAL;
+ imsg->cm_format_type = FMT_RFC822;
+ imsg->cm_fields['A'] = strdup("Citadel");
+ imsg->cm_fields['J'] = strdup("do not journal");
+ imsg->cm_fields['M'] = instr;
+ imsg->cm_fields['W'] = strdup(recipient);
+ CtdlSubmitMsg(imsg, NULL, FNBL_QUEUE_ROOM);
+ CtdlFreeMessage(imsg);
+ }
}
else {
lprintf(CTDL_DEBUG, "No user <%s>\n", recipient);
}
if (subject != NULL) {
+ long length;
striplt(subject);
- if (strlen(subject) > 0) {
- msg->cm_fields['U'] = strdup(subject);
+ length = strlen(subject);
+ if (length > 0) {
+ long i;
+ long IsAscii;
+ IsAscii = -1;
+ i = 0;
+ while ((subject[i] != '\0') &&
+ (IsAscii = isascii(subject[i]) != 0 ))
+ i++;
+ if (IsAscii != 0)
+ msg->cm_fields['U'] = strdup(subject);
+ else /* ok, we've got utf8 in the string. */
+ {
+ msg->cm_fields['U'] = rfc2047encode(subject, length);
+ }
+
}
}
* returns 0 on success.
*/
int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n) {
+ int ra;
if (!(CC->logged_in)) {
snprintf(errmsgbuf, n, "Not logged in.");
return (ERROR + HIGHER_ACCESS_REQUIRED);
}
- if ((CC->user.axlevel < 4)
- && (CC->room.QRflags & QR_NETWORK)) {
- snprintf(errmsgbuf, n, "Need net privileges to enter here.");
- return (ERROR + HIGHER_ACCESS_REQUIRED);
- }
-
- if ((CC->user.axlevel < 6)
- && (CC->room.QRflags & QR_READONLY)) {
- snprintf(errmsgbuf, n, "Sorry, this is a read-only room.");
+ CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
+ if (!(ra & UA_POSTALLOWED)) {
+ snprintf(errmsgbuf, n, "Higher access is required to post in this room.");
return (ERROR + HIGHER_ACCESS_REQUIRED);
}
/* Use the negative of the message number for the metadata db index */
TheIndex = (0L - smibuf->meta_msgnum);
- lprintf(CTDL_DEBUG, "PutMetaData(%ld) - ref count is %d\n",
- smibuf->meta_msgnum, smibuf->meta_refcount);
-
cdb_store(CDB_MSGMAIN,
&TheIndex, (int)sizeof(long),
smibuf, (int)sizeof(struct MetaData));
smi.meta_refcount += incr;
PutMetaData(&smi);
end_critical_section(S_SUPPMSGMAIN);
- lprintf(CTDL_DEBUG, "msg %ld ref count incr %d, is now %d\n",
+ lprintf(CTDL_DEBUG, "msg %ld ref count delta %d, is now %d\n",
msgnum, incr, smi.meta_refcount);
/* If the reference count is now zero, delete the message