/* FIXME: Remove it. Use mu_tempfile instead. */ char * mu_tempname (const char *tmpdir) { struct mu_tempfile_hints hints; char *filename = NULL; int fd; hints.tmpdir = (char*)tmpdir; if (mu_tempfile (&hints, MU_TEMPFILE_TMPDIR, &fd, &filename)) return NULL; close (fd); return filename; }
void make_tmp (FILE *input, const char *from, char **tempfile) { time_t t; int fd = mu_tempfile (NULL, tempfile); FILE *fp; char *buf = NULL; size_t n = 0; int line; if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL) { mu_error ("%s: unable to open temporary file", progname); exit (1); } line = 0; while (getline (&buf, &n, input) > 0) { int len = strlen (buf); if (len >= 2 && buf[len - 2] == '\r') { buf[len - 2] = '\n'; buf[len - 1] = 0; } line++; if (line == 1) { if (memcmp (buf, "From ", 5)) { char *from = from_address (); if (from) { time (&t); fprintf (fp, "From %s %s", from, ctime (&t)); free (from); } else { mu_error ("%s: can't determine sender address", progname); exit (1); } } } else if (!memcmp (buf, "From ", 5)) fputc ('>', fp); if (dot && buf[0] == '.' && ((buf[1] == '\r' && buf[2] == '\n') || (buf[1] == '\n'))) break; if (fputs (buf, fp) == EOF) { mu_error ("%s: temporary file write error", progname); fclose (fp); exit (1); } } if (buf && strchr (buf, '\n') == NULL) putc ('\n', fp); putc ('\n', fp); free (buf); fclose (fp); }