-/*
- * Inbox handling rules
- *
- * Copyright (c) 1987-2020 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * 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.
- */
+// Inbox handling rules
+//
+// Copyright (c) 1987-2022 by the citadel.org team
+//
+// This program is open source software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 3.
+//
+// This program is distributed in the hope that it will be useful,
+// 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.
#include "sysdep.h"
#include <stdlib.h>
#include "ctdl_module.h"
-/*
- * The next sections are enums and keys that drive the serialize/deserialize functions for the inbox rules/state configuration.
- */
+// The next sections are enums and keys that drive the serialize/deserialize functions for the inbox rules/state configuration.
// Fields to be compared
enum {
return NULL;
}
- /* Make a copy of the supplied buffer because we're going to shit all over it with strtok_r() */
+ // Make a copy of the supplied buffer because we're going to shit all over it with strtok_r()
char *sr = strdup(serialized_rules);
if (!sr) {
return NULL;
while ((token = strtok_r(rest, "\n", &rest))) {
// For backwards compatibility, "# WEBCIT_RULE" is an alias for "rule".
- // Prior to version 930, WebCit converted its rules to Sieve scripts, but saved the rules as comments for later re-editing.
- // Now, the rules hidden in the comments become the real rules.
+ // Prior to version 930, WebCit converted its rules to Sieve scripts, but saved the rules as comments for
+ // later re-editing. Now, the rules hidden in the comments become the real rules.
if (!strncasecmp(token, "# WEBCIT_RULE|", 14)) {
strcpy(token, "rule|");
strcpy(&token[5], &token[14]);
}
-/*
- * Perform the "reject" action (delete the message, and tell the sender we deleted it)
- */
+// Perform the "reject" action (delete the message, and tell the sender we deleted it)
void inbox_do_reject(struct irule *rule, struct CtdlMessage *msg) {
syslog(LOG_DEBUG, "inbox_do_reject: sender: <%s>, reject", msg->cm_fields[erFc822Addr]);
}
-/*
- * Perform the "vacation" action (send an automatic response)
- */
+// Perform the "vacation" action (send an automatic response)
void inbox_do_vacation(struct irule *rule, struct CtdlMessage *msg) {
syslog(LOG_DEBUG, "inbox_do_vacation: sender: <%s>, vacation", msg->cm_fields[erFc822Addr]);
int flushing = 0;
int finished = 0;
int dotdot = 0;
- int lines_read = 0; // FIXME remove this after debugging
LineBuf = NewStrBufPlain(NULL, SIZ);
if (exist == NULL) {
if (CtdlClientGetLine(LineBuf) < 0) {
finished = 1;
}
- ++lines_read;
if ((StrLength(LineBuf) == tlen) && (!strcmp(ChrPtr(LineBuf), terminator))) {
finished = 1;
}
}
/* if we've hit the max msg length, flush the rest */
- if (StrLength(Message) >= maxlen) flushing = 1;
+ if (StrLength(Message) >= maxlen) {
+ flushing = 1;
+ }
} while (!finished);
FreeStrBuf(&LineBuf);
- // DEBUG remove this
- int lines_in_buffer = num_tokens(ChrPtr(Message), '\n');
- syslog(LOG_DEBUG, "\033[31mLines from client : %d\033[0m", lines_read);
- syslog(LOG_DEBUG, "\033[32mLines in buffer : %d\033[0m", lines_in_buffer);
- assert(lines_read == lines_in_buffer);
-
+ if (flushing) {
+ syslog(LOG_ERR, "msgbase: exceeded maximum message length of %d - message was truncated", maxlen);
+ }
return Message;
}
-/*
- * Back end function used by CtdlMakeMessage() and similar functions
- */
-char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */
+// Back end function used by CtdlMakeMessage() and similar functions
+char *CtdlReadMessageBody(char *terminator, // token signalling EOT
long tlen,
- size_t maxlen, /* maximum message length */
- StrBuf *exist, /* if non-null, append to it;
- exist is ALWAYS freed */
- int crlf /* CRLF newlines instead of LF */
- )
-{
+ size_t maxlen, // maximum message length
+ StrBuf *exist, // if non-null, append to it; exist is ALWAYS freed
+ int crlf // CRLF newlines instead of LF
+) {
StrBuf *Message;
Message = CtdlReadMessageBodyBuf(terminator,
exist,
crlf
);
- if (Message == NULL)
+ if (Message == NULL) {
return NULL;
- else
+ }
+ else {
return SmashStrBuf(&Message);
+ }
}
-/*
- * Copyright (c) 1987-2018 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * 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
- */
+// Copyright (c) 1987-2022 by the citadel.org team
+//
+// This program is open source software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// 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
#define _GNU_SOURCE
#include "sysdep.h"
return (Str != NULL) ? Str->BufUsed : 0;
}
-/**
- * @ingroup StrBuf_DeConstructors
- * @brief local utility function to resize the buffer
- * @param Buf the buffer whichs storage we should increase
- * @param KeepOriginal should we copy the original buffer or just start over with a new one
- * @param DestSize what should fit in after?
- */
-static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize)
-{
+// local utility function to resize the buffer
+// Buf the buffer whichs storage we should increase
+// KeepOriginal should we copy the original buffer or just start over with a new one
+// DestSize what should fit in after?
+static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize) {
char *NewBuf;
size_t NewSize = Buf->BufSize * 2;
- if (Buf->ConstBuf)
+ if (Buf->ConstBuf) {
return -1;
+ }
- if (DestSize > 0)
- while ((NewSize <= DestSize) && (NewSize != 0))
+ if (DestSize > 0) {
+ while ((NewSize <= DestSize) && (NewSize != 0)) {
NewSize *= 2;
+ }
+ }
- if (NewSize == 0)
+ if (NewSize == 0) {
return -1;
+ }
- NewBuf= (char*) malloc(NewSize);
- if (NewBuf == NULL)
+ NewBuf = (char*) malloc(NewSize);
+ if (NewBuf == NULL) {
return -1;
+ }
- if (KeepOriginal && (Buf->BufUsed > 0))
- {
+ if (KeepOriginal && (Buf->BufUsed > 0)) {
memcpy(NewBuf, Buf->buf, Buf->BufUsed);
}
- else
- {
+ else {
NewBuf[0] = '\0';
Buf->BufUsed = 0;
}
return Buf->BufSize;
}
-/**
- * @ingroup StrBuf_DeConstructors
- * @brief shrink / increase an _EMPTY_ buffer to NewSize. Buffercontent is thoroughly ignored and flushed.
- * @param Buf Buffer to shrink (has to be empty)
- * @param ThreshHold if the buffer is bigger then this, its readjusted
- * @param NewSize if we Shrink it, how big are we going to be afterwards?
- */
-void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize)
-{
- if ((Buf != NULL) &&
- (Buf->BufUsed == 0) &&
- (Buf->BufSize < ThreshHold)) {
+
+// shrink / increase an _EMPTY_ buffer to NewSize. Buffercontent is thoroughly ignored and flushed.
+// Buf Buffer to shrink (has to be empty)
+// ThreshHold if the buffer is bigger then this, its readjusted
+// NewSize if we Shrink it, how big are we going to be afterwards?
+void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize) {
+ if ((Buf != NULL) && (Buf->BufUsed == 0) && (Buf->BufSize < ThreshHold)) {
free(Buf->buf);
Buf->buf = (char*) malloc(NewSize);
Buf->BufUsed = 0;
}
}
+
/**
* @ingroup StrBuf_DeConstructors
* @brief shrink long term buffers to their real size so they don't waste memory
return;
if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1)
- IncreaseBuf(Buf,
- (Buf->BufUsed > 0),
- AppendBuf->BufUsed + Buf->BufUsed);
+ IncreaseBuf(Buf, (Buf->BufUsed > 0), AppendBuf->BufUsed + Buf->BufUsed);
- memcpy(Buf->buf + Buf->BufUsed,
- AppendBuf->buf + Offset,
- AppendBuf->BufUsed - Offset);
+ memcpy(Buf->buf + Buf->BufUsed, AppendBuf->buf + Offset, AppendBuf->BufUsed - Offset);
Buf->BufUsed += AppendBuf->BufUsed - Offset;
Buf->buf[Buf->BufUsed] = '\0';
}
-/**
- * @ingroup StrBuf_Filler
- * @brief Append a C-String to the buffer
- * @param Buf Buffer to modify
- * @param AppendBuf Buffer to copy at the end of our buffer
- * @param AppendSize number of bytes to copy; set to -1 if we should count it in advance
- * @param Offset Should we start copying from an offset?
- */
-void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset)
-{
+// Append a C-String to the buffer
+// Buf Buffer to modify
+// AppendBuf Buffer to copy at the end of our buffer
+// AppendSize number of bytes to copy; set to -1 if we should count it in advance
+// Offset Should we start copying from an offset?
+void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset) {
long aps;
long BufSizeRequired;
if ((AppendBuf == NULL) || (Buf == NULL))
return;
- if (AppendSize < 0 )
+ if (AppendSize < 0) {
aps = strlen(AppendBuf + Offset);
- else
+ }
+ else {
aps = AppendSize - Offset;
+ }
BufSizeRequired = Buf->BufUsed + aps + 1;
- if (Buf->BufSize <= BufSizeRequired)
+ if (Buf->BufSize <= BufSizeRequired) {
IncreaseBuf(Buf, (Buf->BufUsed > 0), BufSizeRequired);
+ }
memcpy(Buf->buf + Buf->BufUsed,
AppendBuf + Offset,
Buf->buf[Buf->BufUsed] = '\0';
}
-/**
+/*
* @ingroup StrBuf_Filler
* @brief sprintf like function appending the formated string to the buffer
* vsnprintf version to wrap into own calls