Beispiel #1
0
char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
{
  regmatch_t pat_match[1];
  size_t pwnl;
  int idx;
  char *p;

  if (!pw || !pw->pw_gecos)
    return NULL;

  memset (dest, 0, destlen);

  if (GecosMask.rx) {
    if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
      strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so,
               MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
  }
  else if ((p = strchr (pw->pw_gecos, ',')))
    strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
  else
    strfcpy (dest, pw->pw_gecos, destlen);

  pwnl = str_len (pw->pw_name);

  for (idx = 0; dest[idx]; idx++) {
    if (dest[idx] == '&') {
      memmove (&dest[idx + pwnl], &dest[idx + 1],
               MAX (destlen - idx - pwnl - 1, 0));
      memcpy (&dest[idx], pw->pw_name, MIN (destlen - idx - 1, pwnl));
      dest[idx] = toupper ((unsigned char) dest[idx]);
    }
  }

  return dest;
}
Beispiel #2
0
static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, 
		    char *newdir, size_t ndlen)
{
  const char *basename;
  char parent[_POSIX_PATH_MAX];
  char *p;
  int rv;

  strfcpy (parent, NONULL (path), sizeof (parent));
  
  if ((p = strrchr (parent, '/')))
  {
    *p = '\0';
    basename = p + 1;
  }
  else
  {
    strfcpy (parent, ".", sizeof (parent));
    basename = path;
  }

  do 
  {
    snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX");
    mktemp (newdir);
  } 
  while ((rv = mkdir (newdir, 0700)) == -1 && errno == EEXIST);
  
  if (rv == -1)
    return -1;
  
  snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename));
  return 0;  
}
Beispiel #3
0
/* mutt_account_getpass: fetch password into ACCOUNT, if necessary */
int mutt_account_getpass(ACCOUNT* account)
{
	char prompt[SHORT_STRING];

	if (account->flags & M_ACCT_PASS)
		return 0;
#if USE_IMAP
	else if ((account->type == M_ACCT_TYPE_IMAP) && ImapPass)
		strfcpy(account->pass, ImapPass, sizeof(account->pass));
#endif
#if USE_SMTP
	else if ((account->type == M_ACCT_TYPE_SMTP) && SmtpPass)
		strfcpy(account->pass, SmtpPass, sizeof(account->pass));
#endif
	else if (bit_val(options, OPTNOCURSES))
		return -1;
	else
	{
		snprintf(prompt, sizeof(prompt), ("Password for %s@%s: "),
			 account->flags & M_ACCT_LOGIN ? account->login : account->user,
			 account->host);
		account->pass[0] = '\0';
		if (mutt_get_password(prompt, account->pass, sizeof account->pass))
			return -1;
	}
	account->flags |= M_ACCT_PASS;
	return 0;
}
Beispiel #4
0
static int
parse_color_pair(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err)
{
  if (! MoreArgs (s))
  {
    strfcpy (err->data, _("color: too few arguments"), err->dsize);
    return (-1);
  }

  mutt_extract_token (buf, s, 0);

  if (parse_color_name (buf->data, fg, attr, A_BOLD, err) != 0)
    return (-1);

  if (! MoreArgs (s))
  {
    strfcpy (err->data, _("color: too few arguments"), err->dsize);
    return (-1);
  }
  
  mutt_extract_token (buf, s, 0);

  if (parse_color_name (buf->data, bg, attr, A_BLINK, err) != 0)
    return (-1);
  
  return 0;
}
/* Modified by blong to accept a "suggestion" for file name.  If
 * that file exists, then construct one with unique name but 
 * keep any extension.  This might fail, I guess.
 * Renamed to mutt_adv_mktemp so I only have to change where it's
 * called, and not all possible cases.
 */
void mutt_adv_mktemp (char *s, size_t l)
{
  char buf[_POSIX_PATH_MAX];
  char tmp[_POSIX_PATH_MAX];
  char *period;
  size_t sl;
  struct stat sb;
  
  strfcpy (buf, NONULL (Tempdir), sizeof (buf));
  mutt_expand_path (buf, sizeof (buf));
  if (s[0] == '\0')
  {
    snprintf (s, l, "%s/muttXXXXXX", buf);
    mktemp (s);
  }
  else
  {
    strfcpy (tmp, s, sizeof (tmp));
    mutt_sanitize_filename (tmp, 1);
    snprintf (s, l, "%s/%s", buf, tmp);
    if (lstat (s, &sb) == -1 && errno == ENOENT)
      return;
    if ((period = strrchr (tmp, '.')) != NULL)
      *period = 0;
    snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
    mktemp (s);
    if (period != NULL)
    {
      *period = '.';
      sl = mutt_strlen(s);
      strfcpy(s + sl, period, l - sl);
    }
  }
}
Beispiel #6
0
static void include_header (int quote, FILE * ifp,
			    struct header * hdr, FILE * ofp,
			    char *_prefix)
{
	int chflags = CH_DECODE;
	char prefix[SHORT_STRING];

	if (bit_val(options, OPTWEED))
		chflags |= CH_WEED | CH_REORDER;

	if (quote)
	{
		if (_prefix)
			strfcpy (prefix, _prefix, sizeof (prefix));
		else if (!bit_val(options, OPTTEXTFLOWED))
			_mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix),
					   Context, hdr, 0);
		else
			strfcpy (prefix, ">", sizeof (prefix));

		chflags |= CH_PREFIX;
	}

	mutt_copy_header (ifp, hdr, ofp, chflags, quote ? prefix : NULL);
}
Beispiel #7
0
int mutt_account_getlogin (ACCOUNT* account)
{
  /* already set */
  if (account->flags & M_ACCT_LOGIN)
    return 0;
#ifdef USE_IMAP
  else if (account->type == M_ACCT_TYPE_IMAP)
  {
    if (ImapLogin)
    {
      strfcpy (account->login, ImapLogin, sizeof (account->login));
      account->flags |= M_ACCT_LOGIN;
    }
  }
#endif

  if (!(account->flags & M_ACCT_LOGIN))
  {
    mutt_account_getuser (account);
    strfcpy (account->login, account->user, sizeof (account->login));
  }

  account->flags |= M_ACCT_LOGIN;

  return 0;
}
Beispiel #8
0
void
rfc822_cat (char *buf, size_t buflen, const char *value, const char *specials)
{
  if (strpbrk (value, specials))
  {
    char tmp[256], *pc = tmp;
    size_t tmplen = sizeof (tmp) - 3;

    *pc++ = '"';
    for (; *value && tmplen > 1; value++)
    {
      if (*value == '\\' || *value == '"')
      {
	*pc++ = '\\';
	tmplen--;
      }
      *pc++ = *value;
      tmplen--;
    }
    *pc++ = '"';
    *pc = 0;
    strfcpy (buf, tmp, buflen);
  }
  else
    strfcpy (buf, value, buflen);
}
Beispiel #9
0
static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, 
		    char *newdir, size_t ndlen)
{
  const char *basename;
  char parent[_POSIX_PATH_MAX];
  char *p;

  strfcpy (parent, NONULL (path), sizeof (parent));
  
  if ((p = strrchr (parent, '/')))
  {
    *p = '\0';
    basename = p + 1;
  }
  else
  {
    strfcpy (parent, ".", sizeof (parent));
    basename = path;
  }

  snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX");
  if (mkdtemp(newdir) == NULL)
  {
      dprint(1, (debugfile, "mutt_mkwrapdir: mkdtemp() failed\n"));
      return -1;
  }
  
  if (snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename)) >= nflen)
  {
      rmdir(newdir);
      dprint(1, (debugfile, "mutt_mkwrapdir: string was truncated\n"));
      return -1;
  }
  return 0;  
}
Beispiel #10
0
/* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */
int mutt_account_getuser (ACCOUNT* account)
{
  char prompt[SHORT_STRING];

  /* already set */
  if (account->flags & M_ACCT_USER)
    return 0;
#ifdef USE_IMAP
  else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser)
    strfcpy (account->user, ImapUser, sizeof (account->user));
#endif
#ifdef USE_POP
  else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
    strfcpy (account->user, PopUser, sizeof (account->user));
#endif
#ifdef USE_NNTP
  else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
    strfcpy (account->user, NntpUser, sizeof (account->user));
#endif
  else if (option (OPTNOCURSES))
    return -1;
  /* prompt (defaults to unix username), copy into account->user */
  else
  {
    snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host);
    strfcpy (account->user, NONULL (Username), sizeof (account->user));
    if (mutt_get_field_unbuffered (prompt, account->user, sizeof (account->user), 0))
      return -1;
  }

  account->flags |= M_ACCT_USER;

  return 0;
}
Beispiel #11
0
/* mutt_account_getpass: fetch password into ACCOUNT, if necessary */
int mutt_account_getpass(ACCOUNT *account)
{
    char prompt[SHORT_STRING];

    if (account->flags & M_ACCT_PASS)
        return 0;

#ifdef USE_POP
    else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
        strfcpy(account->pass, PopPass, sizeof(account->pass));
#endif /* ifdef USE_POP */
#ifdef USE_SMTP
    else if ((account->type == M_ACCT_TYPE_SMTP) && SmtpPass)
        strfcpy(account->pass, SmtpPass, sizeof(account->pass));
#endif /* ifdef USE_SMTP */
    else if (globals.has_option(OPTNOCURSES))
        return -1;
    else {
        snprintf(prompt, sizeof(prompt), _("Password for %s@%s: "),
                 account->flags & M_ACCT_LOGIN ? account->login : account->user,
                 account->host);
        account->pass[0] = '\0';

        if (mutt_get_password(prompt, account->pass, sizeof(account->pass)))
            return -1;
    }

    account->flags |= M_ACCT_PASS;

    return 0;
}
Beispiel #12
0
/* mutt_account_fromurl: fill account with information from url. */
int mutt_account_fromurl(ACCOUNT* account, ciss_url_t* url)
{
	/* must be present */
	if (url->host)
		strfcpy(account->host, url->host, sizeof(account->host));
	else
		return -1;

	if (url->user)
	{
		strfcpy(account->user, url->user, sizeof(account->user));
		account->flags |= M_ACCT_USER;
	}
	if (url->pass)
	{
		strfcpy(account->pass, url->pass, sizeof(account->pass));
		account->flags |= M_ACCT_PASS;
	}
	if (url->port)
	{
		account->port = url->port;
		account->flags |= M_ACCT_PORT;
	}

	return 0;
}
Beispiel #13
0
/* logout from POP server */
void pop_logout (CONTEXT *ctx)
{
  int ret = 0;
  char buf[LONG_STRING];
  POP_DATA *pop_data = (POP_DATA *)ctx->data;

  if (pop_data->status == POP_CONNECTED)
  {
    mutt_message _("Closing connection to POP server...");

    if (ctx->readonly)
    {
      strfcpy (buf, "RSET\r\n", sizeof (buf));
      ret = pop_query (pop_data, buf, sizeof (buf));
    }

    if (ret != -1)
    {
      strfcpy (buf, "QUIT\r\n", sizeof (buf));
      pop_query (pop_data, buf, sizeof (buf));
    }

    mutt_clear_error ();
  }

  pop_data->status = POP_DISCONNECTED;
  return;
}
Beispiel #14
0
int imap_mailbox_rename (const char* url, const char* parent, 
                         const char* subfolder, int subscribe)
{
  IMAP_DATA* idata;
  IMAP_MBOX mx;
  char buf[LONG_STRING];
  short n;
  BUFFER new_url;

  memset (&new_url, 0, sizeof (new_url));
  if (imap_parse_path (url, &mx) < 0)
  {
    dprint (1, (debugfile, "imap_mailbox_rename: Bad path %s\n", url));
    return -1;
  }

  if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW)))
  {
    dprint (1, (debugfile, "imap_mailbox_rename: Couldn't find open connection to %s", mx.account.host));
    goto fail;
  }
  
  strfcpy (buf, parent, sizeof (buf));

  /* append a delimiter if necessary */
  n = mutt_strlen (buf);
  if (n && (n < sizeof (buf) - 1) && (buf[n-1] != idata->delim))
  {
    buf[n++] = idata->delim;
    buf[n] = '\0';
  }
  
  strfcpy (buf + n, subfolder, sizeof (buf) - n);

  imap_subscribe(url, 0);
  if (imap_rename_mailbox (idata, mx.mbox, buf) < 0)
    goto fail;

  if (subscribe) {
    char* slash = strchr(url+8, '/');
    if(slash) {
      mutt_buffer_add(&new_url, url, slash-url+1);
      mutt_buffer_addstr(&new_url, parent);
      mutt_buffer_addch (&new_url, idata->delim);
      mutt_buffer_addstr(&new_url, subfolder);
      if (imap_subscribe(new_url.data, 1) < 0)
        goto fail;
    }
  }

  FREE (&new_url.data);
  FREE (&mx.mbox);
  return 0;

 fail:
  FREE (&new_url.data);
  FREE (&mx.mbox);
  return -1;
}
Beispiel #15
0
Datei: mh.c Projekt: hww3/pexts
int maildir_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
{
  int fd;
  char path[_POSIX_PATH_MAX];
  char suffix[16];
  char subdir[16];

  if (hdr)
  {
    short deleted = hdr->deleted;
    hdr->deleted = 0;
    
    maildir_flags (suffix, sizeof (suffix), hdr);
    
    hdr->deleted = deleted;
  }
  else
    *suffix = '\0';
    
  if (hdr && (hdr->read || hdr->old))
    strfcpy (subdir, "cur", sizeof (subdir));
  else
    strfcpy (subdir, "new", sizeof (subdir));

  FOREVER
  {
    snprintf (path, _POSIX_PATH_MAX, "%s/tmp/%s.%ld.%d_%d.%s%s",
	     dest->path, subdir, time (NULL), getpid (), Counter++,
	     NONULL (Hostname), suffix);

    dprint (2, (debugfile, "maildir_open_new_message (): Trying %s.\n",
		path));

    if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0600)) == -1)
    {
      if (errno != EEXIST)
      {
	mutt_perror (path);
	return -1;
      }
    }
    else
    {
      dprint (2, (debugfile, "maildir_open_new_message (): Success.\n"));
      msg->path = safe_strdup (path);
      break;
    }
  }

  if ((msg->fp = fdopen (fd, "w")) == NULL)
  {
    FREE (&msg->path);
    close (fd);
    unlink (path);
    return (-1);
  }

  return 0;
}
Beispiel #16
0
/*
 * This function calls  funct(*line, *data)  for each received line,
 * funct(NULL, *data)  if  rewind(*data)  needs, exits when fail or done.
 * Returned codes:
 *  0 - successful,
 * -1 - connection lost,
 * -2 - invalid command or execution error,
 * -3 - error in funct(*line, *data)
 */
int pop_fetch_data (POP_DATA *pop_data, char *query, progress_t *progressbar,
		    int (*funct) (char *, void *), void *data)
{
  char buf[LONG_STRING];
  char *inbuf;
  char *p;
  int ret, chunk = 0;
  long pos = 0;
  size_t lenbuf = 0;

  strfcpy (buf, query, sizeof (buf));
  ret = pop_query (pop_data, buf, sizeof (buf));
  if (ret < 0)
    return ret;

  inbuf = safe_malloc (sizeof (buf));

  FOREVER
  {
    chunk = mutt_socket_readln_d (buf, sizeof (buf), pop_data->conn, M_SOCK_LOG_HDR);
    if (chunk < 0)
    {
      pop_data->status = POP_DISCONNECTED;
      ret = -1;
      break;
    }

    p = buf;
    if (!lenbuf && buf[0] == '.')
    {
      if (buf[1] != '.')
	break;
      p++;
    }

    strfcpy (inbuf + lenbuf, p, sizeof (buf));
    pos += chunk;

    /* cast is safe since we break out of the loop when chunk<=0 */
    if ((size_t)chunk >= sizeof (buf))
    {
      lenbuf += strlen (p);
    }
    else
    {
      if (progressbar)
	mutt_progress_update (progressbar, pos, -1);
      if (ret == 0 && funct (inbuf, data) < 0)
	ret = -3;
      lenbuf = 0;
    }

    safe_realloc (&inbuf, lenbuf + sizeof (buf));
  }

  FREE (&inbuf);
  return ret;
}
void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt, const char *src)
{
  const char *p = fmt;
  const char *last = p;
  size_t len;
  size_t slen;
  int found = 0;

  slen = mutt_strlen (src);
  
  while ((p = strchr (p, '%')) != NULL)
  {
    if (p[1] == 's')
    {
      found++;

      len = (size_t) (p - last);
      if (len)
      {
	if (len > destlen - 1)
	  len = destlen - 1;

	memcpy (dest, last, len);
	dest += len;
	destlen -= len;

	if (destlen <= 0)
	{
	  *dest = 0;
	  break; /* no more space */
	}
      }

      strfcpy (dest, src, destlen);
      if (slen > destlen)
      {
	/* no more room */
	break;
      }
      dest += slen;
      destlen -= slen;

      p += 2;
      last = p;
    }
    else if (p[1] == '%')
      p++;

    p++;
  }

  if (found)
    strfcpy (dest, last, destlen);
  else
    snprintf (dest, destlen, "%s %s", fmt, src);
  
}
Beispiel #18
0
int mutt_parse_score (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
{
  SCORE *ptr, *last;
  char *pattern, *pc;
  struct pattern_t *pat;

  mutt_extract_token (buf, s, 0);
  if (!MoreArgs (s))
  {
    strfcpy (err->data, _("score: too few arguments"), err->dsize);
    return (-1);
  }
  pattern = buf->data;
  memset (buf, 0, sizeof (BUFFER));
  mutt_extract_token (buf, s, 0);
  if (MoreArgs (s))
  {
    FREE (&pattern);
    strfcpy (err->data, _("score: too many arguments"), err->dsize);
    return (-1);
  }

  /* look for an existing entry and update the value, else add it to the end
     of the list */
  for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
    if (mutt_strcmp (pattern, ptr->str) == 0)
      break;
  if (!ptr)
  {
    if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL)
    {
      FREE (&pattern);
      return (-1);
    }
    ptr = safe_calloc (1, sizeof (SCORE));
    if (last)
      last->next = ptr;
    else
      Score = ptr;
    ptr->pat = pat;
    ptr->str = pattern;
  } else
    /* 'buf' arg was cleared and 'pattern' holds the only reference;
     * as here 'ptr' != NULL -> update the value only in which case
     * ptr->str already has the string, so pattern should be freed.
     */
    FREE (&pattern);
  pc = buf->data;
  if (*pc == '=')
  {
    ptr->exact = 1;
    pc++;
  }
  ptr->val = atoi (pc);
  set_option (OPTNEEDRESCORE);
  return 0;
}
Beispiel #19
0
/* The command semantics include the following:
 * %s is the filename that contains the mail body data
 * %t is the content type, like text/plain
 * %{parameter} is replaced by the parameter value from the content-type field
 * \% is %
 * Unsupported rfc1524 parameters: these would probably require some doing
 * by mutt, and can probably just be done by piping the message to metamail
 * %n is the integer number of sub-parts in the multipart
 * %F is "content-type filename" repeated for each sub-part
 *
 * In addition, this function returns a 0 if the command works on a file,
 * and 1 if the command works on a pipe.
 */
int rfc1524_expand_command (BODY * a, char *filename, char *_type,
                            char *command, int clen)
{
  int x = 0, y = 0;
  int needspipe = TRUE;
  char buf[LONG_STRING];
  char type[LONG_STRING];

  strfcpy (type, _type, sizeof (type));

  if (option (OPTMAILCAPSANITIZE))
    mutt_sanitize_filename (type, 0);

  while (command[x] && x < clen && y < sizeof (buf)) {
    if (command[x] == '\\') {
      x++;
      buf[y++] = command[x++];
    }
    else if (command[x] == '%') {
      x++;
      if (command[x] == '{') {
        char param[STRING];
        char pvalue[STRING];
        char *_pvalue;
        int z = 0;

        x++;
        while (command[x] && command[x] != '}' && z < sizeof (param))
          param[z++] = command[x++];
        param[z] = '\0';

        _pvalue = mutt_get_parameter (param, a->parameter);
        strfcpy (pvalue, NONULL (_pvalue), sizeof (pvalue));
        if (option (OPTMAILCAPSANITIZE))
          mutt_sanitize_filename (pvalue, 0);

        y += mutt_quote_filename (buf + y, sizeof (buf) - y, pvalue);
      }
      else if (command[x] == 's' && filename != NULL) {
        y += mutt_quote_filename (buf + y, sizeof (buf) - y, filename);
        needspipe = FALSE;
      }
      else if (command[x] == 't') {
        y += mutt_quote_filename (buf + y, sizeof (buf) - y, type);
      }
      x++;
    }
    else
      buf[y++] = command[x++];
  }
  buf[y] = '\0';
  strfcpy (command, buf, clen);

  return needspipe;
}
Beispiel #20
0
/**
 * @brief Send now playing to scrobbler.
 *
 * @param artist
 * @param title
 * @param album
 * @param track
 * @param ttime
 */
static void scrob_nowplay(int sock, const char *artist, const char *title,
                          const char *album, const char *track, const int ttime)
{
        char snd[1024];
        char sttime[32];

        DEBUGF(("Sending now playing (%s - %s) to (%s)!\n",
                artist, title, scrob_nowplayurl));

        snprintf(sttime, sizeof(sttime), "%d", ttime);

        /* Assemble request string. */
        strfcpy(snd, "s=", sizeof(snd));
        strfcat(snd, scrob_sessionid, sizeof(snd));

        strfcat(snd, "&a=", sizeof(snd));
        strfcat(snd, scrob_urlenc(artist), sizeof(snd));

        strfcat(snd, "&t=", sizeof(snd));
        strfcat(snd, scrob_urlenc(title), sizeof(snd));

        strfcat(snd, "&b=", sizeof(snd));
        strfcat(snd, scrob_urlenc(album), sizeof(snd));

        strfcat(snd, "&l=", sizeof(snd));
        strfcat(snd, sttime, sizeof(snd));

        strfcat(snd, "&n=", sizeof(snd));
        strfcat(snd, scrob_urlenc(track), sizeof(snd));

        strfcat(snd, "&m=", sizeof(snd));

        scrob_send_submission(sock, snd, scrob_nowplayurl);
}
Beispiel #21
0
static int
check_attachments(ATTACHPTR **idx, short idxlen)
{
  int i, r;
  struct stat st;
  char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];

  for (i = 0; i < idxlen; i++)
  {
    strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
    if(stat(idx[i]->content->filename, &st) != 0)
    {
      mutt_pretty_mailbox(pretty, sizeof (pretty));
      mutt_error(_("%s [#%d] no longer exists!"),
		 pretty, i+1);
      return -1;
    }
    
    if(idx[i]->content->stamp < st.st_mtime)
    {
      mutt_pretty_mailbox(pretty, sizeof (pretty));
      snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
	       pretty, i+1);
      
      if((r = mutt_yesorno(msg, M_YES)) == M_YES)
	mutt_update_encoding(idx[i]->content);
      else if(r == -1)
	return -1;
    }
  }

  return 0;
}
Beispiel #22
0
Datei: mh.c Projekt: hww3/pexts
static int maildir_parse_dir(CONTEXT *ctx, struct maildir ***last,
			     const char *subdir, int *count)
{
  DIR *dirp;
  struct dirent *de;
  char buf[_POSIX_PATH_MAX];
  int is_old = 0;
  
  if(subdir)
  {
    snprintf(buf, sizeof(buf), "%s/%s", ctx->path, subdir);
    is_old = (mutt_strcmp("cur", subdir) == 0) && option(OPTMARKOLD);
  }
  else
    strfcpy(buf, ctx->path, sizeof(buf));
  
  if((dirp = opendir(buf)) == NULL)
    return -1;

  while ((de = readdir (dirp)) != NULL)
  {
    
    if ((ctx->magic == M_MH && !mh_valid_message(de->d_name)) || (ctx->magic == M_MAILDIR && *de->d_name == '.'))
      continue;
    
    /* FOO - really ignore the return value? */

    dprint(2, (debugfile, "%s:%d: parsing %s\n", __FILE__, __LINE__, de->d_name));
    maildir_parse_entry(ctx, last, subdir, de->d_name, count, is_old);
  }

  closedir(dirp);
  return 0;
}
Beispiel #23
0
int mix_send_message (LIST *chain, const char *tempfile)
{
  char cmd[HUGE_STRING];
  char tmp[HUGE_STRING];
  char cd_quoted[STRING];
  int i;

  snprintf (cmd, sizeof (cmd), "cat %s | %s -m ", tempfile, Mixmaster);
  
  for (i = 0; chain; chain = chain->next, i = 1)
  {
    strfcpy (tmp, cmd, sizeof (tmp));
    mutt_quote_filename (cd_quoted, sizeof (cd_quoted), (char *) chain->data);
    snprintf (cmd, sizeof (cmd), "%s%s%s", tmp, i ? "," : " -l ", cd_quoted);
  }

  if (!option (OPTNOCURSES))
    mutt_endwin (NULL);
  
  if ((i = mutt_system (cmd)))
  {
    fprintf (stderr, _("Error sending message, child exited %d.\n"), i);
    if (!option (OPTNOCURSES))
    {
      mutt_any_key_to_continue (NULL);
      mutt_error _("Error sending message.");
    }
  }

  unlink (tempfile);
  return i;
}
Beispiel #24
0
static void make_from_addr(ENVELOPE *hdr, char *buf, size_t len, int do_lists)
{
    int me;

    me = mutt_addr_is_user(hdr->from);

    if (do_lists
        || me) {
        if (check_for_mailing_list_addr(hdr->to, buf, len))
            return;

        if (check_for_mailing_list_addr(hdr->cc, buf, len))
            return;
    }

    if (me
        && hdr->to)
        snprintf(buf, len, "%s", hdr->to->mailbox);
    else if (me
             && hdr->cc)
        snprintf(buf, len, "%s", hdr->cc->mailbox);
    else if (hdr->from)
        strfcpy(buf, hdr->from->mailbox, len);
    else
        *buf = 0;
}
Beispiel #25
0
static void make_from(ENVELOPE *hdr, char *buf, size_t len, int do_lists)
{
    int me;

    me = mutt_addr_is_user(hdr->from);

    if (do_lists
        || me) {
        if (check_for_mailing_list(hdr->to, "To ", buf, len))
            return;

        if (check_for_mailing_list(hdr->cc, "Cc ", buf, len))
            return;
    }

    if (me
        && hdr->to)
        snprintf(buf, len, "To %s", mutt_get_name(hdr->to));
    else if (me
             && hdr->cc)
        snprintf(buf, len, "Cc %s", mutt_get_name(hdr->cc));
    else if (me
             && hdr->bcc)
        snprintf(buf, len, "Bcc %s", mutt_get_name(hdr->bcc));
    else if (hdr->from)
        strfcpy(buf, mutt_get_name(hdr->from), len);
    else
        *buf = 0;
}
Beispiel #26
0
static int
parse_attr_spec(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err)
{
  
  if(fg) *fg = -1; 
  if(bg) *bg = -1;

  if (! MoreArgs (s))
  {
    strfcpy (err->data, _("mono: too few arguments"), err->dsize);
    return (-1);
  }

  mutt_extract_token (buf, s, 0);

  if (ascii_strcasecmp ("bold", buf->data) == 0)
    *attr |= A_BOLD;
  else if (ascii_strcasecmp ("underline", buf->data) == 0)
    *attr |= A_UNDERLINE;
  else if (ascii_strcasecmp ("none", buf->data) == 0)
    *attr = A_NORMAL;
  else if (ascii_strcasecmp ("reverse", buf->data) == 0)
    *attr |= A_REVERSE;
  else if (ascii_strcasecmp ("standout", buf->data) == 0)
    *attr |= A_STANDOUT;
  else if (ascii_strcasecmp ("normal", buf->data) == 0)
    *attr = A_NORMAL; /* needs use = instead of |= to clear other bits */
  else
  {
    snprintf (err->data, err->dsize, _("%s: no such attribute"), buf->data);
    return (-1);
  }
  
  return 0;
}
Beispiel #27
0
/*
 * Fix up the imap path.  This is necessary because the rest of mutt
 * assumes a hierarchy delimiter of '/', which is not necessarily true
 * in IMAP.  Additionally, the filesystem converts multiple hierarchy
 * delimiters into a single one, ie "///" is equal to "/".  IMAP servers
 * are not required to do this.
 * Moreover, IMAP servers may dislike the path ending with the delimiter.
 */
char *imap_fix_path (IMAP_DATA * idata, char *mailbox, char *path,
                     size_t plen)
{
  int x = 0;

  if (!mailbox || !*mailbox) {
    strfcpy (path, "INBOX", plen);
    return path;
  }

  while (mailbox && *mailbox && (x < (plen - 1))) {
    if ((*mailbox == '/') || (*mailbox == idata->delim)) {
      while ((*mailbox == '/') || (*mailbox == idata->delim))
        mailbox++;
      path[x] = idata->delim;
    }
    else {
      path[x] = *mailbox;
      mailbox++;
    }
    x++;
  }
  if (x && path[--x] != idata->delim)
    x++;
  path[x] = '\0';
  return path;
}
Beispiel #28
0
Datei: mh.c Projekt: hww3/pexts
static int maildir_sync_message (CONTEXT *ctx, int msgno)
{
  HEADER *h = ctx->hdrs[msgno];

  if (h->attach_del)
  {
    /* when doing attachment deletion, fall back to the MH case. */
    if (mh_rewrite_message (ctx, msgno) != 0)
      return (-1);
  }
  else
  {
    /* we just have to rename the file. */

    char newpath[_POSIX_PATH_MAX];
    char partpath[_POSIX_PATH_MAX];
    char fullpath[_POSIX_PATH_MAX];
    char oldpath[_POSIX_PATH_MAX];
    char suffix[16];
    char *p;
    
    if ((p = strrchr (h->path, '/')) == NULL)
    {
      dprint (1, (debugfile, "maildir_sync_message: %s: unable to find subdir!\n",
		  h->path));
      return (-1);
    }
    p++;
    strfcpy (newpath, p, sizeof (newpath));
    
    /* kill the previous flags */
    if ((p = strchr (newpath, ':')) != NULL) *p = 0;
    
    maildir_flags (suffix, sizeof (suffix), h);
    
    snprintf (partpath, sizeof (partpath), "%s/%s%s",
	      (h->read || h->old) ? "cur" : "new",
	      newpath, suffix);
    snprintf (fullpath, sizeof (fullpath), "%s/%s", ctx->path, partpath);
    snprintf (oldpath, sizeof (oldpath), "%s/%s", ctx->path, h->path);
    
    if (mutt_strcmp (fullpath, oldpath) == 0)
    {
      /* message hasn't really changed */
      return 0;
    }

    /* record that the message is possibly marked as trashed on disk */
    h->trash = h->deleted;
    
    if (rename (oldpath, fullpath) != 0)
    {
      mutt_perror ("rename");
      return (-1);
    }
    mutt_str_replace (&h->path, partpath);
  }
  return (0);
}
int mutt_copy_body (FILE *fp, BODY **tgt, BODY *src)
{
  char tmp[_POSIX_PATH_MAX];
  BODY *b;

  PARAMETER *par, **ppar;
  
  short use_disp;

  if (src->filename)
  {
    use_disp = 1;
    strfcpy (tmp, src->filename, sizeof (tmp));
  }
  else
  {
    use_disp = 0;
    tmp[0] = '\0';
  }

  mutt_adv_mktemp (tmp, sizeof (tmp));
  if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
    return -1;
      
  *tgt = mutt_new_body ();
  b = *tgt;

  memcpy (b, src, sizeof (BODY));
  b->parts = NULL;
  b->next  = NULL;
  b->hdr = NULL;

  b->filename = safe_strdup (tmp);
  b->use_disp = use_disp;
  b->unlink = 1;

  if (mutt_is_text_type (b->type, b->subtype))
    b->noconv = 1;

  b->xtype = safe_strdup (b->xtype);
  b->subtype = safe_strdup (b->subtype);
  b->form_name = safe_strdup (b->form_name);
  b->filename = safe_strdup (b->filename);
  b->d_filename = safe_strdup (b->d_filename);
  b->description = safe_strdup (b->description);

  
  /* copy parameters */
  for (par = b->parameter, ppar = &b->parameter; par; ppar = &(*ppar)->next, par = par->next)
  {
    *ppar = mutt_new_parameter ();
    (*ppar)->attribute = safe_strdup (par->attribute);
    (*ppar)->value = safe_strdup (par->value);
  }

  mutt_stamp_attachment (b);
  
  return 0;
}
Beispiel #30
0
Datei: mh.c Projekt: hww3/pexts
int maildir_commit_message (CONTEXT *ctx, MESSAGE *msg, HEADER *hdr)
{
  char subdir[4];
  char suffix[16];
  char path[_POSIX_PATH_MAX];
  char full[_POSIX_PATH_MAX];
  char *s;

  if (safe_fclose (&msg->fp) != 0)
    return -1;
  
  /* extract the subdir */
  s = strrchr (msg->path, '/') + 1;
  strfcpy (subdir, s, 4);

  /* extract the flags */  
  if ((s = strchr (s, ':')))
    strfcpy (suffix, s, sizeof (suffix));
  else
    suffix[0] = '\0';

  /* construct a new file name. */
  FOREVER
  {
    snprintf (path, _POSIX_PATH_MAX, "%s/%ld.%d_%d.%s%s", subdir,
	      time (NULL), getpid(), Counter++, NONULL (Hostname), suffix);
    snprintf (full, _POSIX_PATH_MAX, "%s/%s", ctx->path, path);

    dprint (2, (debugfile, "maildir_commit_message (): renaming %s to %s.\n",
		msg->path, full));

    if (safe_rename (msg->path, full) == 0)
    {
      if (hdr) 
	mutt_str_replace (&hdr->path, path);
      FREE (&msg->path);
      return 0;
    }
    else if (errno != EEXIST)
    {
      mutt_perror (ctx->path);
      return -1;
    }
  }
}