#define HDR_LEN 128
+/*
+ * Like strncpy() but with terminated result.
+ */
+char *stringcopy(char *dest, const char *src, size_t n)
+{
+ strncpy(dest, src, n-1);
+ dest[n-1] = '\0';
+ return dest;
+}
+
int inspect_mbox(char *path, char *prefix, off_t size)
{
FILE *f;
#endif
priority = 0;
} else {
- if (strncasecmp(buf, "From ", 5) == 0) {
- strncpy(from_, buf+5, sizeof(from_)-1);
- from[sizeof(from_)-1] = '\0';
- } else if (strncasecmp(buf, "From: ", 6) == 0) {
- strncpy(from, buf+6, sizeof(from)-1);
- from[sizeof(from)-1] = '\0';
+ if (strncasecmp(buf, "From ", 5) == 0)
+ stringcopy(from_, buf+5, sizeof(from_)-1);
+ else if (strncasecmp(buf, "From: ", 6) == 0)
+ stringcopy(from, buf+6, sizeof(from)-1);
#ifdef FROM_DETECTION
- } else if (strncasecmp(buf, "To: ", 4) == 0) {
- strncpy(to, buf+4, sizeof(to)-1);
- from[sizeof(to)-1] = '\0';
+ else if (strncasecmp(buf, "To: ", 4) == 0)
+ stringcopy(to, buf+4, sizeof(to)-1);
#endif
- } else if (strncasecmp(buf, "Subject: ", 9) == 0) {
- strncpy(subject, buf+9, sizeof(subject)-1);
- from[sizeof(subject)-1] = '\0';
- } else if (strncasecmp(buf, "Priority: ", 10) == 0)
+ else if (strncasecmp(buf, "Subject: ", 9) == 0)
+ stringcopy(subject, buf+9, sizeof(subject)-1);
+ else if (strncasecmp(buf, "Priority: ", 10) == 0)
priority = 1;
}
} else if (strncasecmp(buf, "From ", 5) == 0) {