2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
6 * This file is part of mutt-ng, see http://www.muttng.org/.
7 * It's licensed under the GNU General Public License,
8 * please see the file GPL in the top level source directory.
19 #include "mutt_curses.h"
30 #include "imap/mx_imap.h"
33 #include "mutt_crypt.h"
38 #include "lib/debug.h"
49 #include <sys/types.h>
52 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
54 BODY *mutt_new_body (void)
56 BODY *p = (BODY *) mem_calloc (1, sizeof (BODY));
58 p->disposition = DISPATTACH;
64 /* Modified by blong to accept a "suggestion" for file name. If
65 * that file exists, then construct one with unique name but
66 * keep any extension. This might fail, I guess.
67 * Renamed to mutt_adv_mktemp so I only have to change where it's
68 * called, and not all possible cases.
70 void mutt_adv_mktemp (const char* dir, char *s, size_t l)
72 char buf[_POSIX_PATH_MAX];
73 char tmp[_POSIX_PATH_MAX];
78 strfcpy (buf, dir && *dir ? dir : NONULL (Tempdir), sizeof (buf));
79 mutt_expand_path (buf, sizeof (buf));
81 snprintf (s, l, "%s/muttXXXXXX", buf);
85 strfcpy (tmp, s, sizeof (tmp));
86 mutt_sanitize_filename (tmp, 1);
87 snprintf (s, l, "%s/%s", buf, tmp);
88 if (lstat (s, &sb) == -1 && errno == ENOENT)
90 if ((period = strrchr (tmp, '.')) != NULL)
92 snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
97 strfcpy (s + sl, period, l - sl);
102 /* create a send-mode duplicate from a receive-mode body */
104 int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
106 char tmp[_POSIX_PATH_MAX];
109 PARAMETER *par, **ppar;
115 strfcpy (tmp, src->filename, sizeof (tmp));
122 mutt_adv_mktemp (NULL, tmp, sizeof (tmp));
123 if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
126 *tgt = mutt_new_body ();
129 memcpy (b, src, sizeof (BODY));
133 b->filename = str_dup (tmp);
134 b->use_disp = use_disp;
137 if (mutt_is_text_part (b))
140 b->xtype = str_dup (b->xtype);
141 b->subtype = str_dup (b->subtype);
142 b->form_name = str_dup (b->form_name);
143 b->filename = str_dup (b->filename);
144 b->d_filename = str_dup (b->d_filename);
145 b->description = str_dup (b->description);
148 * we don't seem to need the HEADER structure currently.
149 * XXX - this may change in the future
155 /* copy parameters */
156 for (par = b->parameter, ppar = &b->parameter; par;
157 ppar = &(*ppar)->next, par = par->next) {
158 *ppar = mutt_new_parameter ();
159 (*ppar)->attribute = str_dup (par->attribute);
160 (*ppar)->value = str_dup (par->value);
163 mutt_stamp_attachment (b);
170 void mutt_free_body (BODY ** p)
179 mutt_free_parameter (&b->parameter);
180 if (b->unlink && b->filename) {
181 debug_print (1, ("unlinking %s.\n", b->filename));
182 unlink (b->filename);
184 else if (b->filename)
185 debug_print (1, ("not unlinking %s.\n", b->filename));
187 mem_free (&b->filename);
188 mem_free (&b->content);
189 mem_free (&b->xtype);
190 mem_free (&b->subtype);
191 mem_free (&b->description);
192 mem_free (&b->form_name);
195 /* Don't free twice (b->hdr->content = b->parts) */
196 b->hdr->content = NULL;
197 mutt_free_header (&b->hdr);
201 mutt_free_body (&b->parts);
209 void mutt_free_parameter (PARAMETER ** p)
215 mem_free (&t->attribute);
216 mem_free (&t->value);
224 HEADER *mutt_dup_header (HEADER * h)
228 hnew = mutt_new_header ();
229 memcpy (hnew, h, sizeof (HEADER));
233 void mutt_free_header (HEADER ** h)
237 mutt_free_envelope (&(*h)->env);
238 mutt_free_body (&(*h)->content);
239 mem_free (&(*h)->maildir_flags);
240 mem_free (&(*h)->tree);
241 mem_free (&(*h)->path);
243 mutt_free_list (&(*h)->chain);
245 #if defined USE_POP || defined USE_IMAP || defined USE_NNTP
246 mem_free (&(*h)->data);
251 /* returns true if the header contained in "s" is in list "t" */
252 int mutt_matches_ignore (const char *s, LIST * t)
254 for (; t; t = t->next) {
255 if (!ascii_strncasecmp (s, t->data, str_len (t->data))
262 /* prepend the path part of *path to *link */
263 void mutt_expand_link (char *newpath, const char *path, const char *link)
265 const char *lb = NULL;
268 /* link is full path */
270 strfcpy (newpath, link, _POSIX_PATH_MAX);
274 if ((lb = strrchr (path, '/')) == NULL) {
275 /* no path in link */
276 strfcpy (newpath, link, _POSIX_PATH_MAX);
281 memcpy (newpath, path, len);
282 strfcpy (newpath + len, link, _POSIX_PATH_MAX - len);
285 char *mutt_expand_path (char *s, size_t slen)
287 return _mutt_expand_path (s, slen, 0);
290 char *_mutt_expand_path (char *s, size_t slen, int rx)
292 char p[_POSIX_PATH_MAX] = "";
293 char q[_POSIX_PATH_MAX] = "";
294 char tmp[_POSIX_PATH_MAX];
307 if (*(s + 1) == '/' || *(s + 1) == 0) {
308 strfcpy (p, NONULL (Homedir), sizeof (p));
314 if ((t = strchr (s + 1, '/')))
317 if ((pw = getpwnam (s + 1))) {
318 strfcpy (p, pw->pw_dir, sizeof (p));
327 /* user not found! */
341 /* if folder = imap[s]://host/: don't append slash */
342 if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP &&
343 Maildir[str_len (Maildir) - 1] == '/')
344 strfcpy (p, NONULL (Maildir), sizeof (p));
347 snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
353 /* elm compatibility, @ expands alias to user name */
360 if ((alias = mutt_lookup_alias (s + 1))) {
361 h = mutt_new_header ();
362 h->env = mutt_new_envelope ();
363 h->env->from = h->env->to = alias;
364 mutt_default_save (p, sizeof (p), h);
365 h->env->from = h->env->to = NULL;
366 mutt_free_header (&h);
367 /* Avoid infinite recursion if the resulting folder starts with '@' */
378 strfcpy (p, NONULL (Inbox), sizeof (p));
385 strfcpy (p, NONULL (Outbox), sizeof (p));
392 if (*(s + 1) == '!') {
393 strfcpy (p, NONULL (LastFolder), sizeof (p));
397 strfcpy (p, NONULL (Spoolfile), sizeof (p));
405 strfcpy (p, NONULL (LastFolder), sizeof (p));
412 strfcpy (p, NONULL (CurrentFolder), sizeof (p));
424 if (rx && *p && !recurse) {
425 mutt_rx_sanitize_string (q, sizeof (q), p);
426 snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
429 snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
431 strfcpy (s, tmp, slen);
438 /* Extract the real name from /etc/passwd's GECOS field.
439 * When set, honor the regular expression in GecosMask,
440 * otherwise assume that the GECOS field is a
441 * comma-separated list.
442 * Replace "&" by a capitalized version of the user's login
446 char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
448 regmatch_t pat_match[1];
453 if (!pw || !pw->pw_gecos)
456 memset (dest, 0, destlen);
459 if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
460 strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so,
461 MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
463 else if ((p = strchr (pw->pw_gecos, ',')))
464 strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
466 strfcpy (dest, pw->pw_gecos, destlen);
468 pwnl = str_len (pw->pw_name);
470 for (idx = 0; dest[idx]; idx++) {
471 if (dest[idx] == '&') {
472 memmove (&dest[idx + pwnl], &dest[idx + 1],
473 MAX (destlen - idx - pwnl - 1, 0));
474 memcpy (&dest[idx], pw->pw_name, MIN (destlen - idx - 1, pwnl));
475 dest[idx] = toupper ((unsigned char) dest[idx]);
483 char *mutt_get_parameter (const char *s, PARAMETER * p)
485 for (; p; p = p->next)
486 if (ascii_strcasecmp (s, p->attribute) == 0)
492 void mutt_set_parameter (const char *attribute, const char *value,
498 mutt_delete_parameter (attribute, p);
502 for (q = *p; q; q = q->next) {
503 if (ascii_strcasecmp (attribute, q->attribute) == 0) {
504 str_replace (&q->value, value);
509 q = mutt_new_parameter ();
510 q->attribute = str_dup (attribute);
511 q->value = str_dup (value);
516 void mutt_delete_parameter (const char *attribute, PARAMETER ** p)
520 for (q = *p; q; p = &q->next, q = q->next) {
521 if (ascii_strcasecmp (attribute, q->attribute) == 0) {
524 mutt_free_parameter (&q);
530 /* returns 1 if Mutt can't display this type of data, 0 otherwise */
531 int mutt_needs_mailcap (BODY * m)
536 if (!ascii_strcasecmp ("plain", m->subtype) ||
537 !ascii_strcasecmp ("rfc822-headers", m->subtype) ||
538 !ascii_strcasecmp ("enriched", m->subtype))
542 case TYPEAPPLICATION:
543 if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (m))
545 if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime (m))
557 int mutt_is_text_part (BODY * b)
560 char *s = b->subtype;
562 if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b))
568 if (t == TYPEMESSAGE) {
569 if (!ascii_strcasecmp ("delivery-status", s))
573 if ((WithCrypto & APPLICATION_PGP) && t == TYPEAPPLICATION) {
574 if (!ascii_strcasecmp ("pgp-keys", s))
581 void mutt_free_envelope (ENVELOPE ** p)
585 rfc822_free_address (&(*p)->return_path);
586 rfc822_free_address (&(*p)->from);
587 rfc822_free_address (&(*p)->to);
588 rfc822_free_address (&(*p)->cc);
589 rfc822_free_address (&(*p)->bcc);
590 rfc822_free_address (&(*p)->sender);
591 rfc822_free_address (&(*p)->reply_to);
592 rfc822_free_address (&(*p)->mail_followup_to);
594 mem_free (&(*p)->list_post);
595 mem_free (&(*p)->subject);
596 /* real_subj is just an offset to subject and shouldn't be freed */
597 mem_free (&(*p)->message_id);
598 mem_free (&(*p)->supersedes);
599 mem_free (&(*p)->date);
600 mem_free (&(*p)->x_label);
601 mem_free (&(*p)->organization);
603 mem_free (&(*p)->newsgroups);
604 mem_free (&(*p)->xref);
605 mem_free (&(*p)->followup_to);
606 mem_free (&(*p)->x_comment_to);
609 mutt_buffer_free (&(*p)->spam);
610 mutt_free_list (&(*p)->references);
611 mutt_free_list (&(*p)->in_reply_to);
612 mutt_free_list (&(*p)->userhdrs);
616 /* move all the headers from extra not present in base into base */
617 void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
619 /* copies each existing element if necessary, and sets the element
620 * to NULL in the source so that mutt_free_envelope doesn't leave us
621 * with dangling pointers. */
622 #define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
623 MOVE_ELEM(return_path);
630 MOVE_ELEM(mail_followup_to);
631 MOVE_ELEM(list_post);
632 MOVE_ELEM(message_id);
633 MOVE_ELEM(supersedes);
636 if (!base->refs_changed) {
637 MOVE_ELEM(references);
639 if (!base->irt_changed) {
640 MOVE_ELEM(in_reply_to);
642 /* real_subj is subordinate to subject */
643 if (!base->subject) {
644 base->subject = (*extra)->subject;
645 base->real_subj = (*extra)->real_subj;
646 (*extra)->subject = NULL;
647 (*extra)->real_subj = NULL;
649 /* spam and user headers should never be hashed, and the new envelope may
650 * have better values. Use new versions regardless. */
651 mutt_buffer_free (&base->spam);
652 mutt_free_list (&base->userhdrs);
657 mutt_free_envelope(extra);
660 void _mutt_mktemp (char *s, const char *src, int line)
663 snprintf (s, _POSIX_PATH_MAX, "%s/muttng-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
664 NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++,
665 (unsigned int) rand(), (unsigned int) rand());
666 debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
670 void mutt_free_alias (ALIAS ** p)
678 rfc822_free_address (&t->addr);
683 /* collapse the pathname using ~ or = when possible */
684 void mutt_pretty_mailbox (char *s)
690 scheme = url_check_scheme (s);
693 if (scheme == U_IMAP || scheme == U_IMAPS) {
694 imap_pretty_mailbox (s);
699 /* if s is an url, only collapse path component */
700 if (scheme != U_UNKNOWN) {
701 p = strchr (s, ':') + 1;
702 if (!strncmp (p, "//", 2))
703 q = strchr (p + 2, '/');
705 q = strchr (p, '\0');
709 /* first attempt to collapse the pathname */
711 if (*p == '/' && p[1] == '/') {
715 else if (p[0] == '/' && p[1] == '.' && p[2] == '/') {
724 if (str_ncmp (s, Maildir, (len = str_len (Maildir))) == 0 &&
727 memmove (s, s + len, str_len (s + len) + 1);
729 else if (str_ncmp (s, Homedir, (len = str_len (Homedir))) == 0 &&
732 memmove (s, s + len - 1, str_len (s + len - 1) + 1);
736 void mutt_pretty_size (char *s, size_t len, long n)
739 strfcpy (s, "0K", len);
740 else if (n < 10189) /* 0.1K - 9.9K */
741 snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
742 else if (n < 1023949) { /* 10K - 999K */
743 /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
744 snprintf (s, len, "%ldK", (n + 51) / 1024);
746 else if (n < 10433332) /* 1.0M - 9.9M */
747 snprintf (s, len, "%3.1fM", n / 1048576.0);
750 /* (10433332 + 52428) / 1048576 = 10 */
751 snprintf (s, len, "%ldM", (n + 52428) / 1048576);
755 void mutt_expand_file_fmt (char *dest, size_t destlen, const char *fmt,
758 char tmp[LONG_STRING];
760 mutt_quote_filename (tmp, sizeof (tmp), src);
761 mutt_expand_fmt (dest, destlen, fmt, tmp);
764 void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt,
772 slen = str_len (src);
775 for (p = fmt, d = dest; destlen && *p; p++) {
784 strfcpy (d, src, destlen + 1);
785 d += destlen > slen ? slen : destlen;
786 destlen -= destlen > slen ? slen : destlen;
803 if (!found && destlen > 0) {
804 str_cat (dest, destlen, " ");
805 str_cat (dest, destlen, src);
810 /* return 0 on success, -1 on abort, 1 on error */
811 int mutt_check_overwrite (const char *attname, const char *path,
812 char *fname, size_t flen, int *append,
816 char tmp[_POSIX_PATH_MAX];
819 strfcpy (fname, path, flen);
820 if (access (fname, F_OK) != 0)
822 if (stat (fname, &st) != 0)
824 if (S_ISDIR (st.st_mode)) {
826 switch (mutt_multi_choice
827 (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
830 str_replace (directory, fname);
833 mem_free (directory);
836 mem_free (directory);
839 mem_free (directory);
845 mutt_yesorno (_("File is a directory, save under it?"),
847 return (rc == M_NO) ? 1 : -1;
849 if (!attname || !attname[0]) {
851 if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
852 M_FILE | M_CLEAR) != 0 || !tmp[0])
854 mutt_concat_path (fname, path, tmp, flen);
857 mutt_concat_path (fname, path, mutt_basename (attname), flen);
860 if (*append == 0 && access (fname, F_OK) == 0) {
861 switch (mutt_multi_choice
862 (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
870 *append = M_SAVE_APPEND;
872 case 1: /* overwrite */
873 *append = M_SAVE_OVERWRITE;
880 void mutt_save_path (char *d, size_t dsize, ADDRESS * a)
882 if (a && a->mailbox) {
883 strfcpy (d, a->mailbox, dsize);
884 if (!option (OPTSAVEADDRESS)) {
887 if ((p = strpbrk (d, "%@")))
896 void mutt_safe_path (char *s, size_t l, ADDRESS * a)
900 mutt_save_path (s, l, a);
902 if (*p == '/' || ISSPACE (*p) || !IsPrint ((unsigned char) *p))
906 /* counts how many characters in s can be skipped while none of the
907 * characters of c appears */
908 int mutt_skipchars (const char *s, const char *c)
914 register const char *t = c;
924 return (str_len (p));
927 void mutt_FormatString (char *dest, /* output buffer */
928 size_t destlen, /* output buffer len */
929 const char *src, /* template string */
930 format_t * callback, /* callback for processing */
931 unsigned long data, /* callback data */
933 { /* callback flags */
934 char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
935 char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
936 size_t wlen, count, len, col, wid;
939 destlen--; /* save room for the terminal \0 */
940 wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
943 while (*src && wlen < destlen) {
954 flags |= M_FORMAT_OPTIONAL;
958 flags &= ~M_FORMAT_OPTIONAL;
960 /* eat the format string */
963 while (count < sizeof (prefix) &&
964 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-'))
973 break; /* bad format */
975 ch = *src++; /* save the character to switch on */
977 if (flags & M_FORMAT_OPTIONAL) {
979 break; /* bad format */
982 /* eat the `if' part of the string */
985 while (count < sizeof (ifstring) && *src && *src != '?'
992 /* eat the `else' part of the string (optional) */
994 src++; /* skip the & */
997 while (count < sizeof (elsestring) && *src && *src != '?') {
1004 break; /* bad format */
1006 src++; /* move past the trailing `?' */
1009 /* handle generic cases first */
1011 /* right justify to EOL */
1012 ch = *src++; /* pad char */
1013 /* calculate space left on line. if we've already written more data
1014 than will fit on the line, ignore the rest of the line */
1015 if (DrawFullLine || option (OPTSTATUSONTOP))
1016 count = (COLS < destlen ? COLS : destlen);
1018 count = ((COLS - SW) < destlen ? (COLS - SW) : destlen);
1020 count -= col; /* how many columns left on this line */
1021 mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
1022 wid = str_len (buf);
1024 count -= wid; /* how many chars to pad */
1025 memset (wptr, ch, count);
1029 if (wid + wlen > destlen)
1030 len = destlen - wlen;
1033 memcpy (wptr, buf, len);
1036 col += mutt_strwidth (buf);
1038 break; /* skip rest of input */
1040 else if (ch == '|') {
1045 if (destlen > wlen) {
1046 count = destlen - wlen;
1047 memset (wptr, ch, count);
1050 break; /* skip rest of input */
1056 while (ch == '_' || ch == ':') {
1065 /* use callback function to handle this case */
1067 callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
1080 if ((len = str_len (buf)) + wlen > destlen)
1081 len = (destlen - wlen > 0) ? (destlen - wlen) : 0;
1083 memcpy (wptr, buf, len);
1086 col += mutt_strwidth (buf);
1089 else if (*src == '\\') {
1118 unsigned int bar = mutt_skipchars (src, "%\\");
1119 char *bar2 = mem_malloc (bar + 1);
1121 strfcpy (bar2, src, bar + 1);
1126 col += mutt_strwidth (bar2);
1133 if (flags & M_FORMAT_MAKEPRINT) {
1134 /* Make sure that the string is printable by changing all non-printable
1135 chars to dots, or spaces for non-printable whitespace */
1136 for (cp = dest; *cp; cp++)
1137 if (!IsPrint (*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
1138 *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
1143 /* This function allows the user to specify a command to read stdout from in
1144 place of a normal file. If the last character in the string is a pipe (|),
1145 then we assume it is a commmand to run instead of a normal file. */
1146 FILE *mutt_open_read (const char *path, pid_t * thepid)
1151 int len = str_len (path);
1153 if (path[len - 1] == '|') {
1154 /* read from a pipe */
1156 char *s = str_dup (path);
1160 *thepid = mutt_create_filter (s, NULL, &f, NULL);
1164 if (stat (path, &s) < 0)
1166 if (S_ISDIR (s.st_mode)) {
1170 f = fopen (path, "r");
1176 /* returns 0 if OK to proceed, -1 to abort, 1 to retry */
1177 int mutt_save_confirm (const char *s, struct stat *st)
1179 char tmp[_POSIX_PATH_MAX];
1184 magic = mx_get_magic (s);
1187 if (magic == M_POP) {
1188 mutt_error _("Can't save message to POP mailbox.");
1195 if (magic == M_NNTP) {
1196 mutt_error _("Can't save message to newsserver.");
1202 if (magic > 0 && !mx_access (s, W_OK)) {
1203 if (option (OPTCONFIRMAPPEND) &&
1204 (!TrashPath || (str_cmp (s, TrashPath) != 0))) {
1205 /* if we're appending to the trash, there's no point in asking */
1206 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
1207 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
1214 if (stat (s, st) != -1) {
1216 mutt_error (_("%s is not a mailbox!"), s);
1222 if (magic != M_IMAP)
1223 #endif /* execute the block unconditionally if we don't use imap */
1228 if (errno == ENOENT) {
1229 if (option (OPTCONFIRMCREATE)) {
1230 snprintf (tmp, sizeof (tmp), _("Create %s?"), s);
1231 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
1244 CLEARLINE (LINES - 1);
1248 void mutt_display_sanitize (char *s)
1256 void mutt_sleep (short s)
1264 /* Decrease a file's modification time by 1 second */
1265 time_t mutt_decrease_mtime (const char *f, struct stat *st)
1267 struct utimbuf utim;
1272 if (stat (f, &_st) == -1)
1277 if ((mtime = st->st_mtime) == time (NULL)) {
1279 utim.actime = mtime;
1280 utim.modtime = mtime;
1287 /* sets mtime of 'to' to mtime of 'from' */
1288 void mutt_set_mtime (const char* from, const char* to) {
1289 struct utimbuf utim;
1292 if (stat (from, &st) != -1) {
1293 utim.actime = st.st_mtime;
1294 utim.modtime = st.st_mtime;
1299 const char *mutt_make_version (int full)
1301 static char vstring[STRING];
1304 snprintf (vstring, sizeof (vstring), "Mutt-ng %s-r%s (based "
1305 "on Mutt 1.5.11/%s)", MUTT_VERSION, MUTT_REVISION,
1308 snprintf (vstring, sizeof (vstring), "mutt-ng/%s-r%s",
1309 MUTT_VERSION, MUTT_REVISION);
1313 void mutt_free_spam_list (SPAM_LIST ** list)
1321 *list = (*list)->next;
1323 mem_free(&p->template);
1328 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
1330 static regmatch_t *pmatch = NULL;
1331 static int nmatch = 0;
1340 for (; l; l = l->next) {
1341 /* If this pattern needs more matches, expand pmatch. */
1342 if (l->nmatch > nmatch) {
1343 mem_realloc (&pmatch, l->nmatch * sizeof (regmatch_t));
1347 /* Does this pattern match? */
1349 (l->rx->rx, s, (size_t) l->nmatch, (regmatch_t *) pmatch,
1351 debug_print (5, ("%s matches %s\n%d subst", s, l->rx->pattern, l->rx->rx->re_nsub));
1353 /* Copy template into text, with substitutions. */
1354 for (p = l->template; *p;) {
1356 n = atoi (++p); /* find pmatch index */
1357 while (isdigit ((unsigned char) *p))
1358 ++p; /* skip subst token */
1359 for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
1360 text[tlen++] = s[i];
1363 text[tlen++] = *p++;
1367 debug_print (5, ("\"%s\"\n", text));
1375 int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
1377 if (h1->received != h2->received ||
1378 h1->date_sent != h2->date_sent ||
1379 h1->content->length != h2->content->length ||
1380 h1->lines != h2->lines ||
1381 h1->zhours != h2->zhours ||
1382 h1->zminutes != h2->zminutes ||
1383 h1->zoccident != h2->zoccident ||
1384 h1->mime != h2->mime ||
1385 !mutt_cmp_env (h1->env, h2->env) ||
1386 !mutt_cmp_body (h1->content, h2->content))
1392 if (h1 == NULL && h2 == NULL)
1399 /* return 1 if address lists are strictly identical */
1400 int mutt_cmp_addr (const ADDRESS * a, const ADDRESS * b)
1403 if (str_cmp (a->mailbox, b->mailbox) ||
1404 str_cmp (a->personal, b->personal))
1416 int mutt_cmp_list (const LIST * a, const LIST * b)
1419 if (str_cmp (a->data, b->data))
1431 int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
1434 if (str_cmp (e1->message_id, e2->message_id) ||
1435 str_cmp (e1->subject, e2->subject) ||
1436 !mutt_cmp_list (e1->references, e2->references) ||
1437 !mutt_cmp_addr (e1->from, e2->from) ||
1438 !mutt_cmp_addr (e1->sender, e2->sender) ||
1439 !mutt_cmp_addr (e1->reply_to, e2->reply_to) ||
1440 !mutt_cmp_addr (e1->to, e2->to) ||
1441 !mutt_cmp_addr (e1->cc, e2->cc) ||
1442 !mutt_cmp_addr (e1->return_path, e2->return_path))
1448 if (e1 == NULL && e2 == NULL)
1455 int mutt_cmp_param (const PARAMETER * p1, const PARAMETER * p2)
1458 if (str_cmp (p1->attribute, p2->attribute) ||
1459 str_cmp (p1->value, p2->value))
1471 int mutt_cmp_body (const BODY * b1, const BODY * b2)
1473 if (b1->type != b2->type ||
1474 b1->encoding != b2->encoding ||
1475 str_cmp (b1->subtype, b2->subtype) ||
1476 str_cmp (b1->description, b2->description) ||
1477 !mutt_cmp_param (b1->parameter, b2->parameter) ||
1478 b1->length != b2->length)