+
+/*
+ * Calculate the RFC 822 size of file.
+ */
+
+static size_t
+rfc822size(const char *filename)
+{
+ FILE *f;
+ size_t total = 0, linecap = 0;
+ ssize_t rc;
+ char *line = NULL;
+
+ if (! (f = fopen(filename, "r")))
+ die("Unable to open %s: %s", filename, strerror(errno));
+
+ while ((rc = getline(&line, &linecap, f)) > 0) {
+ total += rc;
+ if (line[rc - 1] == '\n' && (rc == 1 || line[rc - 2] != '\r'))
+ total++;
+ if (line[rc - 1] != '\n')
+ total += 2;
+ }
+
+ free(line);
+
+ if (! feof(f))
+ die("Error while reading %s: %s", filename, strerror(errno));
+
+ fclose(f);
+
+ return total;
+}