#include <utime.h>
#include <lib-mime/mime.h>
-
#include <lib-ui/curses.h>
#include <lib-ui/enter.h>
-
#include <lib-sys/unix.h>
+#include <lib-mx/mx.h>
#include "alias.h"
#include "mutt.h"
-#include "mx.h"
#include "attach.h"
#include "version.h"
#include <imap/imap.h>
-#include <imap/mx_imap.h>
#include <lib-crypt/crypt.h>
return 0;
}
-/* prepend the path part of *path to *lnk */
-void mutt_expand_link (char *newpath, const char *path, const char *lnk)
-{
- const char *lb = NULL;
- ssize_t len;
-
- /* lnk is full path */
- if (*lnk == '/') {
- m_strcpy(newpath, _POSIX_PATH_MAX, lnk);
- return;
- }
-
- if ((lb = strrchr (path, '/')) == NULL) {
- /* no path in lnk */
- m_strcpy(newpath, _POSIX_PATH_MAX, lnk);
- return;
- }
-
- len = lb - path + 1;
- memcpy (newpath, path, len);
- m_strcpy(newpath + len, _POSIX_PATH_MAX - len, lnk);
-}
-
-char *mutt_expand_path (char *s, ssize_t slen)
-{
- return _mutt_expand_path (s, slen, 0);
-}
-
-char *_mutt_expand_path (char *s, ssize_t slen, int rx)
+ssize_t _mutt_expand_path(char *s, ssize_t slen, int rx)
{
- char p[_POSIX_PATH_MAX] = "";
- char q[_POSIX_PATH_MAX] = "";
- char tmp[_POSIX_PATH_MAX];
- char *t;
+ char p[_POSIX_PATH_MAX] = "";
+ char tmp[_POSIX_PATH_MAX];
+ const char *tail = "";
+
+ do {
+ const address_t *alias;
+
+ switch (*s) {
+ case '~':
+ if (s[1] == '/' || s[1] == '\0') {
+ m_strcpy(p, sizeof(p), Homedir);
+ tail = s + 1;
+ } else {
+ struct passwd *pw;
+ tail = m_strchrnul(s + 1, '/');
- const char *tail = "";
+ m_strncpy(tmp, sizeof(tmp), s + 1, tail - s - 1);
- int recurse = 0;
+ if ((pw = getpwnam(tmp))) {
+ m_strcpy(p, sizeof(p), pw->pw_dir);
+ } else {
+ /* user not found! */
+ tail = s;
+ }
+ }
+ break;
+
+ case '=':
+ case '+':
+ /* if folder = imap[s]://host/: don't append slash */
+ if (imap_is_magic(NONULL(Maildir), NULL) == M_IMAP
+ && Maildir[m_strlen(Maildir) - 1] == '/') {
+ m_strcpy(p, sizeof(p), Maildir);
+ } else {
+ snprintf(p, sizeof(p), "%s/", NONULL(Maildir));
+ }
- do {
- recurse = 0;
+ tail = s + 1;
+ break;
+
+ /* elm compatibility, @ expands alias to user name */
+
+ case '@':
+ if ((alias = alias_lookup(s + 1))) {
+ HEADER h;
+ header_init(&h);
+ h.env = envelope_new();
+ h.env->from = h.env->to = (address_t *)alias;
+ mutt_default_save(p, sizeof (p), &h);
+ h.env->from = h.env->to = NULL;
+ header_wipe(&h);
+
+ if (*p != '@') {
+ /* recurse iff the result do not starts with '@' */
+ m_strcpy(s, slen, p);
+ continue;
+ }
+ }
+ break;
+
+ case '>':
+ m_strcpy(p, sizeof(p), Inbox);
+ tail = s + 1;
+ break;
+
+ case '<':
+ m_strcpy(p, sizeof(p), Outbox);
+ tail = s + 1;
+ break;
+
+ case '!':
+ if (s[1] == '!') {
+ m_strcpy(p, sizeof(p), LastFolder);
+ tail = s + 2;
+ } else {
+ m_strcpy(p, sizeof(p), Spoolfile);
+ tail = s + 1;
+ }
+ break;
- switch (*s) {
- case '~':
- {
- if (*(s + 1) == '/' || *(s + 1) == 0) {
- m_strcpy(p, sizeof(p), NONULL(Homedir));
- tail = s + 1;
- }
- else {
- struct passwd *pw;
+ case '-':
+ m_strcpy(p, sizeof(p), NONULL(LastFolder));
+ tail = s + 1;
+ break;
- if ((t = strchr (s + 1, '/')))
- *t = 0;
+ case '^':
+ m_strcpy(p, sizeof(p), NONULL(CurrentFolder));
+ tail = s + 1;
+ break;
- if ((pw = getpwnam (s + 1))) {
- m_strcpy(p, sizeof(p), pw->pw_dir);
- if (t) {
- *t = '/';
- tail = t;
- }
- else
- tail = "";
- }
- else {
- /* user not found! */
- if (t)
- *t = '/';
+ default:
*p = '\0';
tail = s;
- }
}
- }
- break;
-
- case '=':
- case '+':
- {
- /* if folder = imap[s]://host/: don't append slash */
- if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP &&
- Maildir[m_strlen(Maildir) - 1] == '/')
- m_strcpy(p, sizeof(p), NONULL(Maildir));
- else
- snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
-
- tail = s + 1;
- }
- break;
-
- /* elm compatibility, @ expands alias to user name */
-
- case '@':
- {
- HEADER *h;
- /* FIXME: BUG ? */
- address_t *alias;
-
- if ((alias = alias_lookup(s + 1))) {
- h = header_new();
- h->env = envelope_new();
- h->env->from = h->env->to = alias;
- mutt_default_save (p, sizeof (p), h);
- h->env->from = h->env->to = NULL;
- header_delete(&h);
- /* Avoid infinite recursion if the resulting folder starts with '@' */
- if (*p != '@')
- recurse = 1;
-
- tail = "";
- }
- }
- break;
-
- case '>':
- {
- m_strcpy(p, sizeof(p), NONULL(Inbox));
- tail = s + 1;
- }
- break;
-
- case '<':
- {
- m_strcpy(p, sizeof(p), NONULL(Outbox));
- tail = s + 1;
- }
- break;
-
- case '!':
- {
- if (*(s + 1) == '!') {
- m_strcpy(p, sizeof(p), NONULL(LastFolder));
- tail = s + 2;
- }
- else {
- m_strcpy(p, sizeof(p), NONULL(Spoolfile));
- tail = s + 1;
- }
- }
- break;
-
- case '-':
- {
- m_strcpy(p, sizeof(p), NONULL(LastFolder));
- tail = s + 1;
- }
- break;
-
- case '^':
- {
- m_strcpy(p, sizeof(p), NONULL(CurrentFolder));
- tail = s + 1;
- }
- break;
-
- default:
- {
- *p = '\0';
- tail = s;
- }
- }
+ } while (0);
- if (rx && *p && !recurse) {
- rx_sanitize_string (q, sizeof (q), p);
- snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
+ if (rx) {
+ char q[_POSIX_PATH_MAX];
+ rx_sanitize_string(q, sizeof(q), p);
+ snprintf(tmp, sizeof(tmp), "%s%s", q, tail);
+ } else {
+ snprintf(tmp, sizeof(tmp), "%s%s", p, tail);
}
- else
- snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
-
- m_strcpy(s, slen, tmp);
- }
- while (recurse);
- return (s);
-}
-
-/* move all the headers from extra not present in base into base */
-void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
-{
- /* copies each existing element if necessary, and sets the element
- * to NULL in the source so that envelope_delete doesn't leave us
- * with dangling pointers. */
-#define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
- MOVE_ELEM(return_path);
- MOVE_ELEM(from);
- MOVE_ELEM(to);
- MOVE_ELEM(cc);
- MOVE_ELEM(bcc);
- MOVE_ELEM(sender);
- MOVE_ELEM(reply_to);
- MOVE_ELEM(mail_followup_to);
- MOVE_ELEM(list_post);
- MOVE_ELEM(message_id);
- MOVE_ELEM(supersedes);
- MOVE_ELEM(date);
- MOVE_ELEM(x_label);
- if (!base->refs_changed) {
- MOVE_ELEM(references);
- }
- if (!base->irt_changed) {
- MOVE_ELEM(in_reply_to);
- }
- /* real_subj is subordinate to subject */
- if (!base->subject) {
- base->subject = (*extra)->subject;
- base->real_subj = (*extra)->real_subj;
- (*extra)->subject = NULL;
- (*extra)->real_subj = NULL;
- }
- /* spam and user headers should never be hashed, and the new envelope may
- * have better values. Use new versions regardless. */
- mutt_buffer_free (&base->spam);
- string_list_wipe(&base->userhdrs);
- MOVE_ELEM(spam);
- MOVE_ELEM(userhdrs);
-#undef MOVE_ELEM
-
- envelope_delete(extra);
+ return m_strcpy(s, slen, tmp);
}
void mutt_mktemp (char *s)
return mtime;
}
-/* sets mtime of 'to' to mtime of 'from' */
-void mutt_set_mtime (const char* from, const char* to) {
- struct utimbuf utim;
- struct stat st;
-
- if (stat (from, &st) != -1) {
- utim.actime = st.st_mtime;
- utim.modtime = st.st_mtime;
- utime (to, &utim);
- }
-}
-
const char *mutt_make_version (int full)
{
static char vstring[STRING];
return 0;
}
-int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
- if (h1 && h2) {
- if (h1->received != h2->received ||
- h1->date_sent != h2->date_sent ||
- h1->content->length != h2->content->length ||
- h1->lines != h2->lines ||
- h1->zhours != h2->zhours ||
- h1->zminutes != h2->zminutes ||
- h1->zoccident != h2->zoccident ||
- h1->mime != h2->mime ||
- !mutt_cmp_env (h1->env, h2->env) ||
- !mutt_cmp_body (h1->content, h2->content))
- return (0);
- else
- return (1);
- }
- else {
- if (h1 == NULL && h2 == NULL)
- return (1);
- else
- return (0);
- }
-}
-
/* return 1 if address lists are strictly identical */
-int mutt_cmp_addr (const address_t * a, const address_t * b)
+static int mutt_cmp_addr (const address_t * a, const address_t * b)
{
while (a && b) {
if (m_strcmp(a->mailbox, b->mailbox) ||
return (1);
}
-int mutt_cmp_list (const string_list_t * a, const string_list_t * b)
+static int mutt_cmp_list (const string_list_t * a, const string_list_t * b)
{
while (a && b) {
if (m_strcmp(a->data, b->data))
return (1);
}
-int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
+static int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
{
if (e1 && e2) {
if (m_strcmp(e1->message_id, e2->message_id) ||
}
}
-int mutt_cmp_body (const BODY * b1, const BODY * b2)
+static int mutt_cmp_body (const BODY * b1, const BODY * b2)
{
if (b1->type != b2->type ||
b1->encoding != b2->encoding ||
return (0);
return (1);
}
+int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
+ if (h1 && h2) {
+ if (h1->received != h2->received ||
+ h1->date_sent != h2->date_sent ||
+ h1->content->length != h2->content->length ||
+ h1->lines != h2->lines ||
+ h1->zhours != h2->zhours ||
+ h1->zminutes != h2->zminutes ||
+ h1->zoccident != h2->zoccident ||
+ h1->mime != h2->mime ||
+ !mutt_cmp_env (h1->env, h2->env) ||
+ !mutt_cmp_body (h1->content, h2->content))
+ return (0);
+ else
+ return (1);
+ }
+ else {
+ if (h1 == NULL && h2 == NULL)
+ return (1);
+ else
+ return (0);
+ }
+}
+
int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags)
{