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.
15 #include <lib-lib/mem.h>
16 #include <lib-lib/ascii.h>
17 #include <lib-lib/str.h>
18 #include <lib-lib/macros.h>
19 #include <lib-lib/buffer.h>
20 #include <lib-lib/file.h>
24 #include "mutt_curses.h"
35 #include "imap/mx_imap.h"
38 #include "mutt_crypt.h"
40 #include "lib/debug.h"
51 #include <sys/types.h>
54 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
56 BODY *mutt_new_body (void)
58 BODY *p = p_new(BODY, 1);
60 p->disposition = DISPATTACH;
66 /* Modified by blong to accept a "suggestion" for file name. If
67 * that file exists, then construct one with unique name but
68 * keep any extension. This might fail, I guess.
69 * Renamed to mutt_adv_mktemp so I only have to change where it's
70 * called, and not all possible cases.
72 void mutt_adv_mktemp (const char* dir, char *s, size_t l)
74 char buf[_POSIX_PATH_MAX];
75 char tmp[_POSIX_PATH_MAX];
80 strfcpy (buf, dir && *dir ? dir : NONULL (Tempdir), sizeof (buf));
81 mutt_expand_path (buf, sizeof (buf));
83 snprintf (s, l, "%s/muttXXXXXX", buf);
87 strfcpy (tmp, s, sizeof (tmp));
88 mutt_sanitize_filename (tmp, 1);
89 snprintf (s, l, "%s/%s", buf, tmp);
90 if (lstat (s, &sb) == -1 && errno == ENOENT)
92 if ((period = strrchr (tmp, '.')) != NULL)
94 snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
99 strfcpy (s + sl, period, l - sl);
104 /* create a send-mode duplicate from a receive-mode body */
106 int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
108 char tmp[_POSIX_PATH_MAX];
111 PARAMETER *par, **ppar;
117 strfcpy (tmp, src->filename, sizeof (tmp));
124 mutt_adv_mktemp (NULL, tmp, sizeof (tmp));
125 if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
128 *tgt = mutt_new_body ();
131 memcpy (b, src, sizeof (BODY));
135 b->filename = m_strdup(tmp);
136 b->use_disp = use_disp;
139 if (mutt_is_text_part (b))
142 b->xtype = m_strdup(b->xtype);
143 b->subtype = m_strdup(b->subtype);
144 b->form_name = m_strdup(b->form_name);
145 b->filename = m_strdup(b->filename);
146 b->d_filename = m_strdup(b->d_filename);
147 b->description = m_strdup(b->description);
150 * we don't seem to need the HEADER structure currently.
151 * XXX - this may change in the future
157 /* copy parameters */
158 for (par = b->parameter, ppar = &b->parameter; par;
159 ppar = &(*ppar)->next, par = par->next) {
160 *ppar = mutt_new_parameter ();
161 (*ppar)->attribute = m_strdup(par->attribute);
162 (*ppar)->value = m_strdup(par->value);
165 mutt_stamp_attachment (b);
172 void mutt_free_body (BODY ** p)
181 mutt_free_parameter (&b->parameter);
182 if (b->unlink && b->filename) {
183 debug_print (1, ("unlinking %s.\n", b->filename));
184 unlink (b->filename);
186 else if (b->filename)
187 debug_print (1, ("not unlinking %s.\n", b->filename));
189 p_delete(&b->filename);
190 p_delete(&b->content);
192 p_delete(&b->subtype);
193 p_delete(&b->description);
194 p_delete(&b->form_name);
197 /* Don't free twice (b->hdr->content = b->parts) */
198 b->hdr->content = NULL;
199 mutt_free_header (&b->hdr);
203 mutt_free_body (&b->parts);
211 void mutt_free_parameter (PARAMETER ** p)
217 p_delete(&t->attribute);
226 HEADER *mutt_dup_header (HEADER * h)
230 hnew = mutt_new_header ();
231 memcpy (hnew, h, sizeof (HEADER));
235 void mutt_free_header (HEADER ** h)
239 mutt_free_envelope (&(*h)->env);
240 mutt_free_body (&(*h)->content);
241 p_delete(&(*h)->maildir_flags);
242 p_delete(&(*h)->tree);
243 p_delete(&(*h)->path);
245 mutt_free_list (&(*h)->chain);
247 #if defined USE_POP || defined USE_IMAP || defined USE_NNTP
248 p_delete(&(*h)->data);
253 /* returns true if the header contained in "s" is in list "t" */
254 int mutt_matches_ignore (const char *s, LIST * t)
256 for (; t; t = t->next) {
257 if (!ascii_strncasecmp (s, t->data, m_strlen(t->data))
264 /* prepend the path part of *path to *lnk */
265 void mutt_expand_link (char *newpath, const char *path, const char *lnk)
267 const char *lb = NULL;
270 /* lnk is full path */
272 strfcpy (newpath, lnk, _POSIX_PATH_MAX);
276 if ((lb = strrchr (path, '/')) == NULL) {
278 strfcpy (newpath, lnk, _POSIX_PATH_MAX);
283 memcpy (newpath, path, len);
284 strfcpy (newpath + len, lnk, _POSIX_PATH_MAX - len);
287 char *mutt_expand_path (char *s, size_t slen)
289 return _mutt_expand_path (s, slen, 0);
292 char *_mutt_expand_path (char *s, size_t slen, int rx)
294 char p[_POSIX_PATH_MAX] = "";
295 char q[_POSIX_PATH_MAX] = "";
296 char tmp[_POSIX_PATH_MAX];
299 const char *tail = "";
309 if (*(s + 1) == '/' || *(s + 1) == 0) {
310 strfcpy (p, NONULL (Homedir), sizeof (p));
316 if ((t = strchr (s + 1, '/')))
319 if ((pw = getpwnam (s + 1))) {
320 strfcpy (p, pw->pw_dir, sizeof (p));
329 /* user not found! */
343 /* if folder = imap[s]://host/: don't append slash */
344 if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP &&
345 Maildir[m_strlen(Maildir) - 1] == '/')
346 strfcpy (p, NONULL (Maildir), sizeof (p));
349 snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
355 /* elm compatibility, @ expands alias to user name */
362 if ((alias = mutt_lookup_alias (s + 1))) {
363 h = mutt_new_header ();
364 h->env = mutt_new_envelope ();
365 h->env->from = h->env->to = alias;
366 mutt_default_save (p, sizeof (p), h);
367 h->env->from = h->env->to = NULL;
368 mutt_free_header (&h);
369 /* Avoid infinite recursion if the resulting folder starts with '@' */
380 strfcpy (p, NONULL (Inbox), sizeof (p));
387 strfcpy (p, NONULL (Outbox), sizeof (p));
394 if (*(s + 1) == '!') {
395 strfcpy (p, NONULL (LastFolder), sizeof (p));
399 strfcpy (p, NONULL (Spoolfile), sizeof (p));
407 strfcpy (p, NONULL (LastFolder), sizeof (p));
414 strfcpy (p, NONULL (CurrentFolder), sizeof (p));
426 if (rx && *p && !recurse) {
427 mutt_rx_sanitize_string (q, sizeof (q), p);
428 snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
431 snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
433 strfcpy (s, tmp, slen);
440 /* Extract the real name from /etc/passwd's GECOS field.
441 * When set, honor the regular expression in GecosMask,
442 * otherwise assume that the GECOS field is a
443 * comma-separated list.
444 * Replace "&" by a capitalized version of the user's login
448 char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
450 regmatch_t pat_match[1];
455 if (!pw || !pw->pw_gecos)
458 p_clear(dest, destlen);
461 if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
462 strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so,
463 MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
465 else if ((p = strchr (pw->pw_gecos, ',')))
466 strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
468 strfcpy (dest, pw->pw_gecos, destlen);
470 pwnl = m_strlen(pw->pw_name);
472 for (idx = 0; dest[idx]; idx++) {
473 if (dest[idx] == '&') {
474 memmove (&dest[idx + pwnl], &dest[idx + 1],
475 MAX (destlen - idx - pwnl - 1, 0));
476 memcpy (&dest[idx], pw->pw_name, MIN (destlen - idx - 1, pwnl));
477 dest[idx] = toupper ((unsigned char) dest[idx]);
485 char *mutt_get_parameter (const char *s, PARAMETER * p)
487 for (; p; p = p->next)
488 if (ascii_strcasecmp (s, p->attribute) == 0)
494 void mutt_set_parameter (const char *attribute, const char *value,
500 mutt_delete_parameter (attribute, p);
504 for (q = *p; q; q = q->next) {
505 if (ascii_strcasecmp (attribute, q->attribute) == 0) {
506 str_replace (&q->value, value);
511 q = mutt_new_parameter ();
512 q->attribute = m_strdup(attribute);
513 q->value = m_strdup(value);
518 void mutt_delete_parameter (const char *attribute, PARAMETER ** p)
522 for (q = *p; q; p = &q->next, q = q->next) {
523 if (ascii_strcasecmp (attribute, q->attribute) == 0) {
526 mutt_free_parameter (&q);
532 /* returns 1 if Mutt can't display this type of data, 0 otherwise */
533 int mutt_needs_mailcap (BODY * m)
538 if (!ascii_strcasecmp ("plain", m->subtype) ||
539 !ascii_strcasecmp ("rfc822-headers", m->subtype) ||
540 !ascii_strcasecmp ("enriched", m->subtype))
544 case TYPEAPPLICATION:
545 if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (m))
547 if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime (m))
559 int mutt_is_text_part (BODY * b)
562 char *s = b->subtype;
564 if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b))
570 if (t == TYPEMESSAGE) {
571 if (!ascii_strcasecmp ("delivery-status", s))
575 if ((WithCrypto & APPLICATION_PGP) && t == TYPEAPPLICATION) {
576 if (!ascii_strcasecmp ("pgp-keys", s))
583 void mutt_free_envelope (ENVELOPE ** p)
587 rfc822_free_address (&(*p)->return_path);
588 rfc822_free_address (&(*p)->from);
589 rfc822_free_address (&(*p)->to);
590 rfc822_free_address (&(*p)->cc);
591 rfc822_free_address (&(*p)->bcc);
592 rfc822_free_address (&(*p)->sender);
593 rfc822_free_address (&(*p)->reply_to);
594 rfc822_free_address (&(*p)->mail_followup_to);
596 p_delete(&(*p)->list_post);
597 p_delete(&(*p)->subject);
598 /* real_subj is just an offset to subject and shouldn't be freed */
599 p_delete(&(*p)->message_id);
600 p_delete(&(*p)->supersedes);
601 p_delete(&(*p)->date);
602 p_delete(&(*p)->x_label);
603 p_delete(&(*p)->organization);
605 p_delete(&(*p)->newsgroups);
606 p_delete(&(*p)->xref);
607 p_delete(&(*p)->followup_to);
608 p_delete(&(*p)->x_comment_to);
611 mutt_buffer_free (&(*p)->spam);
612 mutt_free_list (&(*p)->references);
613 mutt_free_list (&(*p)->in_reply_to);
614 mutt_free_list (&(*p)->userhdrs);
618 /* move all the headers from extra not present in base into base */
619 void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
621 /* copies each existing element if necessary, and sets the element
622 * to NULL in the source so that mutt_free_envelope doesn't leave us
623 * with dangling pointers. */
624 #define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
625 MOVE_ELEM(return_path);
632 MOVE_ELEM(mail_followup_to);
633 MOVE_ELEM(list_post);
634 MOVE_ELEM(message_id);
635 MOVE_ELEM(supersedes);
638 if (!base->refs_changed) {
639 MOVE_ELEM(references);
641 if (!base->irt_changed) {
642 MOVE_ELEM(in_reply_to);
644 /* real_subj is subordinate to subject */
645 if (!base->subject) {
646 base->subject = (*extra)->subject;
647 base->real_subj = (*extra)->real_subj;
648 (*extra)->subject = NULL;
649 (*extra)->real_subj = NULL;
651 /* spam and user headers should never be hashed, and the new envelope may
652 * have better values. Use new versions regardless. */
653 mutt_buffer_free (&base->spam);
654 mutt_free_list (&base->userhdrs);
659 mutt_free_envelope(extra);
662 void _mutt_mktemp (char *s, const char *src, int line)
665 snprintf (s, _POSIX_PATH_MAX, "%s/muttng-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
666 NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++,
667 (unsigned int) rand(), (unsigned int) rand());
668 debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
672 void mutt_free_alias (ALIAS ** p)
680 rfc822_free_address (&t->addr);
685 /* collapse the pathname using ~ or = when possible */
686 void mutt_pretty_mailbox (char *s)
692 scheme = url_check_scheme (s);
695 if (scheme == U_IMAP || scheme == U_IMAPS) {
696 imap_pretty_mailbox (s);
701 /* if s is an url, only collapse path component */
702 if (scheme != U_UNKNOWN) {
703 p = strchr (s, ':') + 1;
704 if (!strncmp (p, "//", 2))
705 q = strchr (p + 2, '/');
707 q = strchr (p, '\0');
711 /* first attempt to collapse the pathname */
713 if (*p == '/' && p[1] == '/') {
717 else if (p[0] == '/' && p[1] == '.' && p[2] == '/') {
726 if (str_ncmp (s, Maildir, (len = m_strlen(Maildir))) == 0 &&
729 memmove (s, s + len, m_strlen(s + len) + 1);
731 else if (str_ncmp (s, Homedir, (len = m_strlen(Homedir))) == 0 &&
734 memmove (s, s + len - 1, m_strlen(s + len - 1) + 1);
738 void mutt_pretty_size (char *s, size_t len, long n)
741 strfcpy (s, "0K", len);
742 else if (n < 10189) /* 0.1K - 9.9K */
743 snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
744 else if (n < 1023949) { /* 10K - 999K */
745 /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
746 snprintf (s, len, "%ldK", (n + 51) / 1024);
748 else if (n < 10433332) /* 1.0M - 9.9M */
749 snprintf (s, len, "%3.1fM", n / 1048576.0);
752 /* (10433332 + 52428) / 1048576 = 10 */
753 snprintf (s, len, "%ldM", (n + 52428) / 1048576);
757 void mutt_expand_file_fmt (char *dest, size_t destlen, const char *fmt,
760 char tmp[LONG_STRING];
762 mutt_quote_filename (tmp, sizeof (tmp), src);
763 mutt_expand_fmt (dest, destlen, fmt, tmp);
766 void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt,
774 slen = m_strlen(src);
777 for (p = fmt, d = dest; destlen && *p; p++) {
786 strfcpy (d, src, destlen + 1);
787 d += destlen > slen ? slen : destlen;
788 destlen -= destlen > slen ? slen : destlen;
805 if (!found && destlen > 0) {
806 m_strcat(dest, destlen, " ");
807 m_strcat(dest, destlen, src);
812 /* return 0 on success, -1 on abort, 1 on error */
813 int mutt_check_overwrite (const char *attname, const char *path,
814 char *fname, size_t flen, int *append,
818 char tmp[_POSIX_PATH_MAX];
821 strfcpy (fname, path, flen);
822 if (access (fname, F_OK) != 0)
824 if (stat (fname, &st) != 0)
826 if (S_ISDIR (st.st_mode)) {
828 switch (mutt_multi_choice
829 (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
832 str_replace (directory, fname);
847 mutt_yesorno (_("File is a directory, save under it?"),
849 return (rc == M_NO) ? 1 : -1;
851 if (!attname || !attname[0]) {
853 if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
854 M_FILE | M_CLEAR) != 0 || !tmp[0])
856 mutt_concat_path(fname, flen, path, tmp);
859 mutt_concat_path(fname, flen, path, mutt_basename(attname));
862 if (*append == 0 && access (fname, F_OK) == 0) {
863 switch (mutt_multi_choice
864 (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
872 *append = M_SAVE_APPEND;
874 case 1: /* overwrite */
875 *append = M_SAVE_OVERWRITE;
882 void mutt_save_path (char *d, size_t dsize, ADDRESS * a)
884 if (a && a->mailbox) {
885 strfcpy (d, a->mailbox, dsize);
886 if (!option (OPTSAVEADDRESS)) {
889 if ((p = strpbrk (d, "%@")))
898 void mutt_safe_path (char *s, size_t l, ADDRESS * a)
902 mutt_save_path (s, l, a);
904 if (*p == '/' || ISSPACE (*p) || !IsPrint ((unsigned char) *p))
908 /* counts how many characters in s can be skipped while none of the
909 * characters of c appears */
910 int mutt_skipchars (const char *s, const char *c)
916 register const char *t = c;
926 return (m_strlen(p));
929 void mutt_FormatString (char *dest, /* output buffer */
930 size_t destlen, /* output buffer len */
931 const char *src, /* template string */
932 format_t * callback, /* callback for processing */
933 unsigned long data, /* callback data */
935 { /* callback flags */
936 char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
937 char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
938 size_t wlen, count, len, col, wid;
941 destlen--; /* save room for the terminal \0 */
942 wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
945 while (*src && wlen < destlen) {
956 flags |= M_FORMAT_OPTIONAL;
960 flags &= ~M_FORMAT_OPTIONAL;
962 /* eat the format string */
965 while (count < sizeof (prefix) &&
966 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-'))
975 break; /* bad format */
977 ch = *src++; /* save the character to switch on */
979 if (flags & M_FORMAT_OPTIONAL) {
981 break; /* bad format */
984 /* eat the `if' part of the string */
987 while (count < sizeof (ifstring) && *src && *src != '?'
994 /* eat the `else' part of the string (optional) */
996 src++; /* skip the & */
999 while (count < sizeof (elsestring) && *src && *src != '?') {
1006 break; /* bad format */
1008 src++; /* move past the trailing `?' */
1011 /* handle generic cases first */
1013 /* right justify to EOL */
1014 ch = *src++; /* pad char */
1015 /* calculate space left on line. if we've already written more data
1016 than will fit on the line, ignore the rest of the line */
1017 if (DrawFullLine || option (OPTSTATUSONTOP))
1018 count = (COLS < destlen ? COLS : destlen);
1020 count = ((COLS - SW) < destlen ? (COLS - SW) : destlen);
1022 count -= col; /* how many columns left on this line */
1023 mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
1024 wid = m_strlen(buf);
1026 count -= wid; /* how many chars to pad */
1027 memset (wptr, ch, count);
1031 if (wid + wlen > destlen)
1032 len = destlen - wlen;
1035 memcpy (wptr, buf, len);
1038 col += mutt_strwidth (buf);
1040 break; /* skip rest of input */
1042 else if (ch == '|') {
1047 if (destlen > wlen) {
1048 count = destlen - wlen;
1049 memset (wptr, ch, count);
1052 break; /* skip rest of input */
1058 while (ch == '_' || ch == ':') {
1067 /* use callback function to handle this case */
1069 callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
1082 if ((len = m_strlen(buf)) + wlen > destlen)
1083 len = (destlen - wlen > 0) ? (destlen - wlen) : 0;
1085 memcpy (wptr, buf, len);
1088 col += mutt_strwidth (buf);
1091 else if (*src == '\\') {
1120 unsigned int bar = mutt_skipchars (src, "%\\");
1121 char *bar2 = p_dupstr(src, bar);
1127 col += mutt_strwidth (bar2);
1134 if (flags & M_FORMAT_MAKEPRINT) {
1135 /* Make sure that the string is printable by changing all non-printable
1136 chars to dots, or spaces for non-printable whitespace */
1137 for (cp = dest; *cp; cp++)
1138 if (!IsPrint (*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
1139 *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
1144 /* This function allows the user to specify a command to read stdout from in
1145 place of a normal file. If the last character in the string is a pipe (|),
1146 then we assume it is a commmand to run instead of a normal file. */
1147 FILE *mutt_open_read (const char *path, pid_t * thepid)
1149 int len = m_strlen(path);
1152 if (path[len - 1] == '|') {
1153 char *s = m_strdup(path);
1155 /* read from a pipe */
1159 *thepid = mutt_create_filter (s, NULL, &f, NULL);
1162 f = fopen (path, "r");
1171 /* returns 0 if OK to proceed, -1 to abort, 1 to retry */
1172 int mutt_save_confirm (const char *s, struct stat *st)
1174 char tmp[_POSIX_PATH_MAX];
1179 magic = mx_get_magic (s);
1182 if (magic == M_POP) {
1183 mutt_error _("Can't save message to POP mailbox.");
1190 if (magic == M_NNTP) {
1191 mutt_error _("Can't save message to newsserver.");
1197 if (magic > 0 && !mx_access (s, W_OK)) {
1198 if (option (OPTCONFIRMAPPEND) &&
1199 (!TrashPath || (m_strcmp(s, TrashPath) != 0))) {
1200 /* if we're appending to the trash, there's no point in asking */
1201 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
1202 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
1209 if (stat (s, st) != -1) {
1211 mutt_error (_("%s is not a mailbox!"), s);
1217 if (magic != M_IMAP)
1218 #endif /* execute the block unconditionally if we don't use imap */
1223 if (errno == ENOENT) {
1224 if (option (OPTCONFIRMCREATE)) {
1225 snprintf (tmp, sizeof (tmp), _("Create %s?"), s);
1226 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
1239 CLEARLINE (LINES - 1);
1243 void mutt_display_sanitize (char *s)
1251 void mutt_sleep (short s)
1259 /* Decrease a file's modification time by 1 second */
1260 time_t mutt_decrease_mtime (const char *f, struct stat *st)
1262 struct utimbuf utim;
1267 if (stat (f, &_st) == -1)
1272 if ((mtime = st->st_mtime) == time (NULL)) {
1274 utim.actime = mtime;
1275 utim.modtime = mtime;
1282 /* sets mtime of 'to' to mtime of 'from' */
1283 void mutt_set_mtime (const char* from, const char* to) {
1284 struct utimbuf utim;
1287 if (stat (from, &st) != -1) {
1288 utim.actime = st.st_mtime;
1289 utim.modtime = st.st_mtime;
1294 const char *mutt_make_version (int full)
1296 static char vstring[STRING];
1299 snprintf (vstring, sizeof (vstring), "Mutt-ng %s-r%s (based "
1300 "on Mutt 1.5.11/%s)", MUTT_VERSION, MUTT_REVISION,
1303 snprintf (vstring, sizeof (vstring), "mutt-ng/%s-r%s",
1304 MUTT_VERSION, MUTT_REVISION);
1308 void mutt_free_spam_list (SPAM_LIST ** list)
1316 *list = (*list)->next;
1318 p_delete(&p->template);
1323 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
1325 static regmatch_t *pmatch = NULL;
1326 static int nmatch = 0;
1335 for (; l; l = l->next) {
1336 /* If this pattern needs more matches, expand pmatch. */
1337 if (l->nmatch > nmatch) {
1338 p_realloc(&pmatch, l->nmatch);
1342 /* Does this pattern match? */
1344 (l->rx->rx, s, (size_t) l->nmatch, (regmatch_t *) pmatch,
1346 debug_print (5, ("%s matches %s\n%d subst", s, l->rx->pattern, l->rx->rx->re_nsub));
1348 /* Copy template into text, with substitutions. */
1349 for (p = l->template; *p;) {
1351 n = atoi (++p); /* find pmatch index */
1352 while (isdigit ((unsigned char) *p))
1353 ++p; /* skip subst token */
1354 for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
1355 text[tlen++] = s[i];
1358 text[tlen++] = *p++;
1362 debug_print (5, ("\"%s\"\n", text));
1370 int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
1372 if (h1->received != h2->received ||
1373 h1->date_sent != h2->date_sent ||
1374 h1->content->length != h2->content->length ||
1375 h1->lines != h2->lines ||
1376 h1->zhours != h2->zhours ||
1377 h1->zminutes != h2->zminutes ||
1378 h1->zoccident != h2->zoccident ||
1379 h1->mime != h2->mime ||
1380 !mutt_cmp_env (h1->env, h2->env) ||
1381 !mutt_cmp_body (h1->content, h2->content))
1387 if (h1 == NULL && h2 == NULL)
1394 /* return 1 if address lists are strictly identical */
1395 int mutt_cmp_addr (const ADDRESS * a, const ADDRESS * b)
1398 if (m_strcmp(a->mailbox, b->mailbox) ||
1399 m_strcmp(a->personal, b->personal))
1411 int mutt_cmp_list (const LIST * a, const LIST * b)
1414 if (m_strcmp(a->data, b->data))
1426 int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
1429 if (m_strcmp(e1->message_id, e2->message_id) ||
1430 m_strcmp(e1->subject, e2->subject) ||
1431 !mutt_cmp_list (e1->references, e2->references) ||
1432 !mutt_cmp_addr (e1->from, e2->from) ||
1433 !mutt_cmp_addr (e1->sender, e2->sender) ||
1434 !mutt_cmp_addr (e1->reply_to, e2->reply_to) ||
1435 !mutt_cmp_addr (e1->to, e2->to) ||
1436 !mutt_cmp_addr (e1->cc, e2->cc) ||
1437 !mutt_cmp_addr (e1->return_path, e2->return_path))
1443 if (e1 == NULL && e2 == NULL)
1450 int mutt_cmp_param (const PARAMETER * p1, const PARAMETER * p2)
1453 if (m_strcmp(p1->attribute, p2->attribute) ||
1454 m_strcmp(p1->value, p2->value))
1466 int mutt_cmp_body (const BODY * b1, const BODY * b2)
1468 if (b1->type != b2->type ||
1469 b1->encoding != b2->encoding ||
1470 m_strcmp(b1->subtype, b2->subtype) ||
1471 m_strcmp(b1->description, b2->description) ||
1472 !mutt_cmp_param (b1->parameter, b2->parameter) ||
1473 b1->length != b2->length)