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.
16 #include "mutt_curses.h"
25 #include "imap/mx_imap.h"
28 #include "mutt_crypt.h"
33 #include "lib/debug.h"
44 #include <sys/types.h>
47 BODY *mutt_new_body (void)
49 BODY *p = (BODY *) mem_calloc (1, sizeof (BODY));
51 p->disposition = DISPATTACH;
57 /* Modified by blong to accept a "suggestion" for file name. If
58 * that file exists, then construct one with unique name but
59 * keep any extension. This might fail, I guess.
60 * Renamed to mutt_adv_mktemp so I only have to change where it's
61 * called, and not all possible cases.
63 void mutt_adv_mktemp (char *s, size_t l)
65 char buf[_POSIX_PATH_MAX];
66 char tmp[_POSIX_PATH_MAX];
71 strfcpy (buf, NONULL (Tempdir), sizeof (buf));
72 mutt_expand_path (buf, sizeof (buf));
74 snprintf (s, l, "%s/muttXXXXXX", buf);
78 strfcpy (tmp, s, sizeof (tmp));
79 mutt_sanitize_filename (tmp, 1);
80 snprintf (s, l, "%s/%s", buf, tmp);
81 if (lstat (s, &sb) == -1 && errno == ENOENT)
83 if ((period = strrchr (tmp, '.')) != NULL)
85 snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
90 strfcpy (s + sl, period, l - sl);
95 /* create a send-mode duplicate from a receive-mode body */
97 int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
99 char tmp[_POSIX_PATH_MAX];
102 PARAMETER *par, **ppar;
108 strfcpy (tmp, src->filename, sizeof (tmp));
115 mutt_adv_mktemp (tmp, sizeof (tmp));
116 if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
119 *tgt = mutt_new_body ();
122 memcpy (b, src, sizeof (BODY));
126 b->filename = str_dup (tmp);
127 b->use_disp = use_disp;
130 if (mutt_is_text_part (b))
133 b->xtype = str_dup (b->xtype);
134 b->subtype = str_dup (b->subtype);
135 b->form_name = str_dup (b->form_name);
136 b->filename = str_dup (b->filename);
137 b->d_filename = str_dup (b->d_filename);
138 b->description = str_dup (b->description);
141 * we don't seem to need the HEADER structure currently.
142 * XXX - this may change in the future
148 /* copy parameters */
149 for (par = b->parameter, ppar = &b->parameter; par;
150 ppar = &(*ppar)->next, par = par->next) {
151 *ppar = mutt_new_parameter ();
152 (*ppar)->attribute = str_dup (par->attribute);
153 (*ppar)->value = str_dup (par->value);
156 mutt_stamp_attachment (b);
163 void mutt_free_body (BODY ** p)
172 mutt_free_parameter (&b->parameter);
173 if (b->unlink && b->filename) {
174 debug_print (1, ("unlinking %s.\n", b->filename));
175 unlink (b->filename);
177 else if (b->filename)
178 debug_print (1, ("not unlinking %s.\n", b->filename));
180 mem_free (&b->filename);
181 mem_free (&b->content);
182 mem_free (&b->xtype);
183 mem_free (&b->subtype);
184 mem_free (&b->description);
185 mem_free (&b->form_name);
188 /* Don't free twice (b->hdr->content = b->parts) */
189 b->hdr->content = NULL;
190 mutt_free_header (&b->hdr);
194 mutt_free_body (&b->parts);
202 void mutt_free_parameter (PARAMETER ** p)
208 mem_free (&t->attribute);
209 mem_free (&t->value);
217 LIST *mutt_add_list (LIST * head, const char *data) {
218 size_t len = str_len (data);
219 return (mutt_add_list_n (head, data, len ? len + 1 : 0));
222 LIST *mutt_add_list_n (LIST *head, const void *data, size_t len) {
225 for (tmp = head; tmp && tmp->next; tmp = tmp->next);
228 tmp->next = mem_malloc (sizeof (LIST));
231 head = tmp = mem_malloc (sizeof (LIST));
233 tmp->data = mem_malloc (len);
235 memcpy (tmp->data, data, len);
240 void mutt_free_list (LIST ** list)
248 *list = (*list)->next;
254 HEADER *mutt_dup_header (HEADER * h)
258 hnew = mutt_new_header ();
259 memcpy (hnew, h, sizeof (HEADER));
263 void mutt_free_header (HEADER ** h)
267 mutt_free_envelope (&(*h)->env);
268 mutt_free_body (&(*h)->content);
269 mem_free (&(*h)->maildir_flags);
270 mem_free (&(*h)->tree);
271 mem_free (&(*h)->path);
273 mutt_free_list (&(*h)->chain);
275 #if defined USE_POP || defined USE_IMAP || defined USE_NNTP
276 mem_free (&(*h)->data);
281 /* returns true if the header contained in "s" is in list "t" */
282 int mutt_matches_ignore (const char *s, LIST * t)
284 for (; t; t = t->next) {
285 if (!ascii_strncasecmp (s, t->data, str_len (t->data))
292 /* prepend the path part of *path to *link */
293 void mutt_expand_link (char *newpath, const char *path, const char *link)
295 const char *lb = NULL;
298 /* link is full path */
300 strfcpy (newpath, link, _POSIX_PATH_MAX);
304 if ((lb = strrchr (path, '/')) == NULL) {
305 /* no path in link */
306 strfcpy (newpath, link, _POSIX_PATH_MAX);
311 memcpy (newpath, path, len);
312 strfcpy (newpath + len, link, _POSIX_PATH_MAX - len);
315 char *mutt_expand_path (char *s, size_t slen)
317 return _mutt_expand_path (s, slen, 0);
320 char *_mutt_expand_path (char *s, size_t slen, int rx)
322 char p[_POSIX_PATH_MAX] = "";
323 char q[_POSIX_PATH_MAX] = "";
324 char tmp[_POSIX_PATH_MAX];
337 if (*(s + 1) == '/' || *(s + 1) == 0) {
338 strfcpy (p, NONULL (Homedir), sizeof (p));
344 if ((t = strchr (s + 1, '/')))
347 if ((pw = getpwnam (s + 1))) {
348 strfcpy (p, pw->pw_dir, sizeof (p));
357 /* user not found! */
371 /* if folder = imap[s]://host/: don't append slash */
372 if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP &&
373 Maildir[str_len (Maildir) - 1] == '/')
374 strfcpy (p, NONULL (Maildir), sizeof (p));
377 snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
383 /* elm compatibility, @ expands alias to user name */
390 if ((alias = mutt_lookup_alias (s + 1))) {
391 h = mutt_new_header ();
392 h->env = mutt_new_envelope ();
393 h->env->from = h->env->to = alias;
394 mutt_default_save (p, sizeof (p), h);
395 h->env->from = h->env->to = NULL;
396 mutt_free_header (&h);
397 /* Avoid infinite recursion if the resulting folder starts with '@' */
408 strfcpy (p, NONULL (Inbox), sizeof (p));
415 strfcpy (p, NONULL (Outbox), sizeof (p));
422 if (*(s + 1) == '!') {
423 strfcpy (p, NONULL (LastFolder), sizeof (p));
427 strfcpy (p, NONULL (Spoolfile), sizeof (p));
435 strfcpy (p, NONULL (LastFolder), sizeof (p));
442 strfcpy (p, NONULL (CurrentFolder), sizeof (p));
454 if (rx && *p && !recurse) {
455 mutt_rx_sanitize_string (q, sizeof (q), p);
456 snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
459 snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
461 strfcpy (s, tmp, slen);
468 /* Extract the real name from /etc/passwd's GECOS field.
469 * When set, honor the regular expression in GecosMask,
470 * otherwise assume that the GECOS field is a
471 * comma-separated list.
472 * Replace "&" by a capitalized version of the user's login
476 char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
478 regmatch_t pat_match[1];
483 if (!pw || !pw->pw_gecos)
486 memset (dest, 0, destlen);
489 if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
490 strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so,
491 MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
493 else if ((p = strchr (pw->pw_gecos, ',')))
494 strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
496 strfcpy (dest, pw->pw_gecos, destlen);
498 pwnl = str_len (pw->pw_name);
500 for (idx = 0; dest[idx]; idx++) {
501 if (dest[idx] == '&') {
502 memmove (&dest[idx + pwnl], &dest[idx + 1],
503 MAX (destlen - idx - pwnl - 1, 0));
504 memcpy (&dest[idx], pw->pw_name, MIN (destlen - idx - 1, pwnl));
505 dest[idx] = toupper ((unsigned char) dest[idx]);
513 char *mutt_get_parameter (const char *s, PARAMETER * p)
515 for (; p; p = p->next)
516 if (ascii_strcasecmp (s, p->attribute) == 0)
522 void mutt_set_parameter (const char *attribute, const char *value,
528 mutt_delete_parameter (attribute, p);
532 for (q = *p; q; q = q->next) {
533 if (ascii_strcasecmp (attribute, q->attribute) == 0) {
534 str_replace (&q->value, value);
539 q = mutt_new_parameter ();
540 q->attribute = str_dup (attribute);
541 q->value = str_dup (value);
546 void mutt_delete_parameter (const char *attribute, PARAMETER ** p)
550 for (q = *p; q; p = &q->next, q = q->next) {
551 if (ascii_strcasecmp (attribute, q->attribute) == 0) {
554 mutt_free_parameter (&q);
560 /* returns 1 if Mutt can't display this type of data, 0 otherwise */
561 int mutt_needs_mailcap (BODY * m)
566 if (!ascii_strcasecmp ("plain", m->subtype) ||
567 !ascii_strcasecmp ("rfc822-headers", m->subtype) ||
568 !ascii_strcasecmp ("enriched", m->subtype))
572 case TYPEAPPLICATION:
573 if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (m))
575 if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime (m))
587 int mutt_is_text_part (BODY * b)
590 char *s = b->subtype;
592 if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b))
598 if (t == TYPEMESSAGE) {
599 if (!ascii_strcasecmp ("delivery-status", s))
603 if ((WithCrypto & APPLICATION_PGP) && t == TYPEAPPLICATION) {
604 if (!ascii_strcasecmp ("pgp-keys", s))
611 void mutt_free_envelope (ENVELOPE ** p)
615 rfc822_free_address (&(*p)->return_path);
616 rfc822_free_address (&(*p)->from);
617 rfc822_free_address (&(*p)->to);
618 rfc822_free_address (&(*p)->cc);
619 rfc822_free_address (&(*p)->bcc);
620 rfc822_free_address (&(*p)->sender);
621 rfc822_free_address (&(*p)->reply_to);
622 rfc822_free_address (&(*p)->mail_followup_to);
624 mem_free (&(*p)->list_post);
625 mem_free (&(*p)->subject);
626 /* real_subj is just an offset to subject and shouldn't be freed */
627 mem_free (&(*p)->message_id);
628 mem_free (&(*p)->supersedes);
629 mem_free (&(*p)->date);
630 mem_free (&(*p)->x_label);
631 mem_free (&(*p)->organization);
633 mem_free (&(*p)->newsgroups);
634 mem_free (&(*p)->xref);
635 mem_free (&(*p)->followup_to);
636 mem_free (&(*p)->x_comment_to);
639 mutt_buffer_free (&(*p)->spam);
640 mutt_free_list (&(*p)->references);
641 mutt_free_list (&(*p)->in_reply_to);
642 mutt_free_list (&(*p)->userhdrs);
646 /* move all the headers from extra not present in base into base */
647 void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
649 /* copies each existing element if necessary, and sets the element
650 * to NULL in the source so that mutt_free_envelope doesn't leave us
651 * with dangling pointers. */
652 #define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
653 MOVE_ELEM(return_path);
660 MOVE_ELEM(mail_followup_to);
661 MOVE_ELEM(list_post);
662 MOVE_ELEM(message_id);
663 MOVE_ELEM(supersedes);
666 if (!base->refs_changed) {
667 MOVE_ELEM(references);
669 if (!base->irt_changed) {
670 MOVE_ELEM(in_reply_to);
672 /* real_subj is subordinate to subject */
673 if (!base->subject) {
674 base->subject = (*extra)->subject;
675 base->real_subj = (*extra)->real_subj;
676 (*extra)->subject = NULL;
677 (*extra)->real_subj = NULL;
679 /* spam and user headers should never be hashed, and the new envelope may
680 * have better values. Use new versions regardless. */
681 mutt_buffer_free (&base->spam);
682 mutt_free_list (&base->userhdrs);
687 mutt_free_envelope(extra);
690 void _mutt_mktemp (char *s, const char *src, int line)
693 snprintf (s, _POSIX_PATH_MAX, "%s/muttng-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
694 NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++,
695 (unsigned int) rand(), (unsigned int) rand());
696 debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s));
700 void mutt_free_alias (ALIAS ** p)
708 rfc822_free_address (&t->addr);
713 /* collapse the pathname using ~ or = when possible */
714 void mutt_pretty_mailbox (char *s)
720 scheme = url_check_scheme (s);
723 if (scheme == U_IMAP || scheme == U_IMAPS) {
724 imap_pretty_mailbox (s);
729 /* if s is an url, only collapse path component */
730 if (scheme != U_UNKNOWN) {
731 p = strchr (s, ':') + 1;
732 if (!strncmp (p, "//", 2))
733 q = strchr (p + 2, '/');
735 q = strchr (p, '\0');
739 /* first attempt to collapse the pathname */
741 if (*p == '/' && p[1] == '/') {
745 else if (p[0] == '/' && p[1] == '.' && p[2] == '/') {
754 if (str_ncmp (s, Maildir, (len = str_len (Maildir))) == 0 &&
757 memmove (s, s + len, str_len (s + len) + 1);
759 else if (str_ncmp (s, Homedir, (len = str_len (Homedir))) == 0 &&
762 memmove (s, s + len - 1, str_len (s + len - 1) + 1);
766 void mutt_pretty_size (char *s, size_t len, long n)
769 strfcpy (s, "0K", len);
770 else if (n < 10189) /* 0.1K - 9.9K */
771 snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
772 else if (n < 1023949) { /* 10K - 999K */
773 /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
774 snprintf (s, len, "%ldK", (n + 51) / 1024);
776 else if (n < 10433332) /* 1.0M - 9.9M */
777 snprintf (s, len, "%3.1fM", n / 1048576.0);
780 /* (10433332 + 52428) / 1048576 = 10 */
781 snprintf (s, len, "%ldM", (n + 52428) / 1048576);
785 void mutt_expand_file_fmt (char *dest, size_t destlen, const char *fmt,
788 char tmp[LONG_STRING];
790 mutt_quote_filename (tmp, sizeof (tmp), src);
791 mutt_expand_fmt (dest, destlen, fmt, tmp);
794 void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt,
802 slen = str_len (src);
805 for (p = fmt, d = dest; destlen && *p; p++) {
814 strfcpy (d, src, destlen + 1);
815 d += destlen > slen ? slen : destlen;
816 destlen -= destlen > slen ? slen : destlen;
833 if (!found && destlen > 0) {
834 str_cat (dest, destlen, " ");
835 str_cat (dest, destlen, src);
840 /* return 0 on success, -1 on abort, 1 on error */
841 int mutt_check_overwrite (const char *attname, const char *path,
842 char *fname, size_t flen, int *append,
846 char tmp[_POSIX_PATH_MAX];
849 strfcpy (fname, path, flen);
850 if (access (fname, F_OK) != 0)
852 if (stat (fname, &st) != 0)
854 if (S_ISDIR (st.st_mode)) {
856 switch (mutt_multi_choice
857 (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
860 str_replace (directory, fname);
863 mem_free (directory);
866 mem_free (directory);
869 mem_free (directory);
875 mutt_yesorno (_("File is a directory, save under it?"),
877 return (rc == M_NO) ? 1 : -1;
879 if (!attname || !attname[0]) {
881 if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
882 M_FILE | M_CLEAR) != 0 || !tmp[0])
884 mutt_concat_path (fname, path, tmp, flen);
887 mutt_concat_path (fname, path, mutt_basename (attname), flen);
890 if (*append == 0 && access (fname, F_OK) == 0) {
891 switch (mutt_multi_choice
892 (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
900 *append = M_SAVE_APPEND;
902 case 1: /* overwrite */
903 *append = M_SAVE_OVERWRITE;
910 void mutt_save_path (char *d, size_t dsize, ADDRESS * a)
912 if (a && a->mailbox) {
913 strfcpy (d, a->mailbox, dsize);
914 if (!option (OPTSAVEADDRESS)) {
917 if ((p = strpbrk (d, "%@")))
926 void mutt_safe_path (char *s, size_t l, ADDRESS * a)
930 mutt_save_path (s, l, a);
932 if (*p == '/' || ISSPACE (*p) || !IsPrint ((unsigned char) *p))
936 /* counts how many characters in s can be skipped while none of the
937 * characters of c appears */
938 int mutt_skipchars (const char *s, const char *c)
944 register const char *t = c;
954 return (str_len (p));
957 void mutt_FormatString (char *dest, /* output buffer */
958 size_t destlen, /* output buffer len */
959 const char *src, /* template string */
960 format_t * callback, /* callback for processing */
961 unsigned long data, /* callback data */
963 { /* callback flags */
964 char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
965 char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
966 size_t wlen, count, len, col, wid;
969 destlen--; /* save room for the terminal \0 */
970 wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
973 while (*src && wlen < destlen) {
984 flags |= M_FORMAT_OPTIONAL;
988 flags &= ~M_FORMAT_OPTIONAL;
990 /* eat the format string */
993 while (count < sizeof (prefix) &&
994 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-'))
1003 break; /* bad format */
1005 ch = *src++; /* save the character to switch on */
1007 if (flags & M_FORMAT_OPTIONAL) {
1009 break; /* bad format */
1012 /* eat the `if' part of the string */
1015 while (count < sizeof (ifstring) && *src && *src != '?'
1022 /* eat the `else' part of the string (optional) */
1024 src++; /* skip the & */
1027 while (count < sizeof (elsestring) && *src && *src != '?') {
1034 break; /* bad format */
1036 src++; /* move past the trailing `?' */
1039 /* handle generic cases first */
1041 /* right justify to EOL */
1042 ch = *src++; /* pad char */
1043 /* calculate space left on line. if we've already written more data
1044 than will fit on the line, ignore the rest of the line */
1045 if (DrawFullLine || option (OPTSTATUSONTOP))
1046 count = (COLS < destlen ? COLS : destlen);
1049 ((COLS - SidebarWidth) <
1050 destlen ? (COLS - SidebarWidth) : destlen);
1052 count -= col; /* how many columns left on this line */
1053 mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
1054 wid = str_len (buf);
1056 count -= wid; /* how many chars to pad */
1057 memset (wptr, ch, count);
1061 if (wid + wlen > destlen)
1062 len = destlen - wlen;
1065 memcpy (wptr, buf, len);
1068 col += mutt_strwidth (buf);
1070 break; /* skip rest of input */
1072 else if (ch == '|') {
1077 if (destlen > wlen) {
1078 count = destlen - wlen;
1079 memset (wptr, ch, count);
1082 break; /* skip rest of input */
1088 while (ch == '_' || ch == ':') {
1097 /* use callback function to handle this case */
1099 callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
1112 if ((len = str_len (buf)) + wlen > destlen)
1113 len = (destlen - wlen > 0) ? (destlen - wlen) : 0;
1115 memcpy (wptr, buf, len);
1118 col += mutt_strwidth (buf);
1121 else if (*src == '\\') {
1150 unsigned int bar = mutt_skipchars (src, "%\\");
1151 char *bar2 = mem_malloc (bar + 1);
1153 strfcpy (bar2, src, bar + 1);
1158 col += mutt_strwidth (bar2);
1165 if (flags & M_FORMAT_MAKEPRINT) {
1166 /* Make sure that the string is printable by changing all non-printable
1167 chars to dots, or spaces for non-printable whitespace */
1168 for (cp = dest; *cp; cp++)
1169 if (!IsPrint (*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
1170 *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
1175 /* This function allows the user to specify a command to read stdout from in
1176 place of a normal file. If the last character in the string is a pipe (|),
1177 then we assume it is a commmand to run instead of a normal file. */
1178 FILE *mutt_open_read (const char *path, pid_t * thepid)
1183 int len = str_len (path);
1185 if (path[len - 1] == '|') {
1186 /* read from a pipe */
1188 char *s = str_dup (path);
1192 *thepid = mutt_create_filter (s, NULL, &f, NULL);
1196 if (stat (path, &s) < 0)
1198 if (S_ISDIR (s.st_mode)) {
1202 f = fopen (path, "r");
1208 /* returns 0 if OK to proceed, -1 to abort, 1 to retry */
1209 int mutt_save_confirm (const char *s, struct stat *st)
1211 char tmp[_POSIX_PATH_MAX];
1216 magic = mx_get_magic (s);
1219 if (magic == M_POP) {
1220 mutt_error _("Can't save message to POP mailbox.");
1227 if (magic == M_NNTP) {
1228 mutt_error _("Can't save message to newsserver.");
1234 if (magic > 0 && !mx_access (s, W_OK)) {
1235 if (option (OPTCONFIRMAPPEND) &&
1236 (!TrashPath || (str_cmp (s, TrashPath) != 0))) {
1237 /* if we're appending to the trash, there's no point in asking */
1238 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
1239 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
1246 if (stat (s, st) != -1) {
1248 mutt_error (_("%s is not a mailbox!"), s);
1254 if (magic != M_IMAP)
1255 #endif /* execute the block unconditionally if we don't use imap */
1260 if (errno == ENOENT) {
1261 if (option (OPTCONFIRMCREATE)) {
1262 snprintf (tmp, sizeof (tmp), _("Create %s?"), s);
1263 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
1276 CLEARLINE (LINES - 1);
1280 void mutt_display_sanitize (char *s)
1288 void mutt_sleep (short s)
1296 /* Decrease a file's modification time by 1 second */
1298 time_t mutt_decrease_mtime (const char *f, struct stat *st)
1300 struct utimbuf utim;
1305 if (stat (f, &_st) == -1)
1310 if ((mtime = st->st_mtime) == time (NULL)) {
1312 utim.actime = mtime;
1313 utim.modtime = mtime;
1320 const char *mutt_make_version (void)
1322 static char vstring[STRING];
1324 snprintf (vstring, sizeof (vstring), "Mutt-ng %s (%s) based on Mutt 1.5.9",
1325 MUTT_VERSION, ReleaseDate);
1329 void mutt_free_spam_list (SPAM_LIST ** list)
1337 *list = (*list)->next;
1339 mem_free(&p->template);
1344 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
1346 static regmatch_t *pmatch = NULL;
1347 static int nmatch = 0;
1356 for (; l; l = l->next) {
1357 /* If this pattern needs more matches, expand pmatch. */
1358 if (l->nmatch > nmatch) {
1359 mem_realloc (&pmatch, l->nmatch * sizeof (regmatch_t));
1363 /* Does this pattern match? */
1365 (l->rx->rx, s, (size_t) l->nmatch, (regmatch_t *) pmatch,
1367 debug_print (5, ("%s matches %s\n%d subst", s, l->rx->pattern, l->rx->rx->re_nsub));
1369 /* Copy template into text, with substitutions. */
1370 for (p = l->template; *p;) {
1372 n = atoi (++p); /* find pmatch index */
1373 while (isdigit (*p))
1374 ++p; /* skip subst token */
1375 for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
1376 text[tlen++] = s[i];
1379 text[tlen++] = *p++;
1383 debug_print (5, ("\"%s\"\n", text));
1391 int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
1393 if (h1->received != h2->received ||
1394 h1->date_sent != h2->date_sent ||
1395 h1->content->length != h2->content->length ||
1396 h1->lines != h2->lines ||
1397 h1->zhours != h2->zhours ||
1398 h1->zminutes != h2->zminutes ||
1399 h1->zoccident != h2->zoccident ||
1400 h1->mime != h2->mime ||
1401 !mutt_cmp_env (h1->env, h2->env) ||
1402 !mutt_cmp_body (h1->content, h2->content))
1408 if (h1 == NULL && h2 == NULL)
1415 /* return 1 if address lists are strictly identical */
1416 int mutt_cmp_addr (const ADDRESS * a, const ADDRESS * b)
1419 if (str_cmp (a->mailbox, b->mailbox) ||
1420 str_cmp (a->personal, b->personal))
1432 int mutt_cmp_list (const LIST * a, const LIST * b)
1435 if (str_cmp (a->data, b->data))
1447 int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
1450 if (str_cmp (e1->message_id, e2->message_id) ||
1451 str_cmp (e1->subject, e2->subject) ||
1452 !mutt_cmp_list (e1->references, e2->references) ||
1453 !mutt_cmp_addr (e1->from, e2->from) ||
1454 !mutt_cmp_addr (e1->sender, e2->sender) ||
1455 !mutt_cmp_addr (e1->reply_to, e2->reply_to) ||
1456 !mutt_cmp_addr (e1->to, e2->to) ||
1457 !mutt_cmp_addr (e1->cc, e2->cc) ||
1458 !mutt_cmp_addr (e1->return_path, e2->return_path))
1464 if (e1 == NULL && e2 == NULL)
1471 int mutt_cmp_param (const PARAMETER * p1, const PARAMETER * p2)
1474 if (str_cmp (p1->attribute, p2->attribute) ||
1475 str_cmp (p1->value, p2->value))
1487 int mutt_cmp_body (const BODY * b1, const BODY * b2)
1489 if (b1->type != b2->type ||
1490 b1->encoding != b2->encoding ||
1491 str_cmp (b1->subtype, b2->subtype) ||
1492 str_cmp (b1->description, b2->description) ||
1493 !mutt_cmp_param (b1->parameter, b2->parameter) ||
1494 b1->length != b2->length)