示例#1
0
文件: envlist.c 项目: darnir/neomutt
/**
 * mutt_envlist_unset - Unset an environment variable
 * @param name Variable to unset
 * @retval true  Success: Variable unset
 * @retval false Error: Variable doesn't exist
 */
bool mutt_envlist_unset(const char *name)
{
  if (!name || !name[0])
    return false;

  char **envp = EnvList;

  int count = 0;
  while (envp && *envp)
  {
    size_t len = mutt_str_startswith(*envp, name, CASE_MATCH);
    if ((len != 0) && ((*envp)[len] == '='))
    {
      /* shuffle down */
      char **save = envp++;
      while (*envp)
      {
        *save++ = *envp++;
        count++;
      }
      *save = NULL;
      mutt_mem_realloc(&EnvList, sizeof(char *) * (count + 1));
      return true;
    }
    envp++;
    count++;
  }
  return false;
}
示例#2
0
文件: curs_lib.c 项目: darnir/neomutt
/**
 * mutt_push_macro_event - Add the character/operation to the macro buffer
 * @param ch Character to add
 * @param op Operation to add
 *
 * Adds the ch/op to the macro buffer.
 * This should be used for macros, push, and exec commands only.
 */
void mutt_push_macro_event(int ch, int op)
{
  struct Event tmp;

  tmp.ch = ch;
  tmp.op = op;

  if (MacroBufferCount >= MacroBufferLen)
    mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event));

  MacroEvents[MacroBufferCount++] = tmp;
}
示例#3
0
文件: curs_lib.c 项目: darnir/neomutt
/**
 * mutt_unget_event - Return a keystroke to the input buffer
 * @param ch Key press
 * @param op Operation, e.g. OP_DELETE
 *
 * This puts events into the `UngetKeyEvents` buffer
 */
void mutt_unget_event(int ch, int op)
{
  struct Event tmp;

  tmp.ch = ch;
  tmp.op = op;

  if (UngetCount >= UngetLen)
    mutt_mem_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event));

  UngetKeyEvents[UngetCount++] = tmp;
}
示例#4
0
文件: mh.c 项目: kdave/neomutt
/**
 * mhs_alloc - Allocate more memory for sequences
 * @param mhs Existing sequences
 * @param i   Number required
 *
 * @note Memory is allocated in blocks of 128.
 */
static void mhs_alloc(struct MhSequences *mhs, int i)
{
  if ((i <= mhs->max) && mhs->flags)
    return;

  const int newmax = i + 128;
  int j = mhs->flags ? mhs->max + 1 : 0;
  mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1));
  while (j <= newmax)
    mhs->flags[j++] = 0;

  mhs->max = newmax;
}
示例#5
0
文件: crypt.c 项目: darnir/neomutt
/**
 * crypt_fetch_signatures - Create an array of an emails parts
 * @param[out] signatures Array of Body parts
 * @param[in]  a          Body part to examine
 * @param[out] n          Cumulative count of parts
 */
static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, int *n)
{
  if (!WithCrypto)
    return;

  for (; a; a = a->next)
  {
    if (a->type == TYPE_MULTIPART)
      crypt_fetch_signatures(signatures, a->parts, n);
    else
    {
      if ((*n % 5) == 0)
        mutt_mem_realloc(signatures, (*n + 6) * sizeof(struct Body **));

      (*signatures)[(*n)++] = a;
    }
  }
}
示例#6
0
文件: envlist.c 项目: darnir/neomutt
/**
 * mutt_envlist_set - Set an environment variable
 * @param name      Name of the variable
 * @param value     New value
 * @param overwrite Should the variable be overwritten?
 * @retval true  Success: variable set, or overwritten
 * @retval false Variable exists and overwrite was false
 *
 * It's broken out because some other parts of neomutt (filter.c) need to
 * set/overwrite environment variables in EnvList before calling exec().
 */
bool mutt_envlist_set(const char *name, const char *value, bool overwrite)
{
  char **envp = EnvList;
  char work[1024];
  int count;

  /* Look for current slot to overwrite */
  count = 0;
  while (envp && *envp)
  {
    size_t len = mutt_str_startswith(*envp, name, CASE_MATCH);
    if ((len != 0) && ((*envp)[len] == '='))
    {
      if (!overwrite)
        return false;
      break;
    }
    envp++;
    count++;
  }

  /* Format var=value string */
  snprintf(work, sizeof(work), "%s=%s", NONULL(name), NONULL(value));

  if (envp && *envp)
  {
    /* slot found, overwrite */
    mutt_str_replace(envp, work);
  }
  else
  {
    /* not found, add new slot */
    mutt_mem_realloc(&EnvList, sizeof(char *) * (count + 2));
    EnvList[count] = mutt_str_strdup(work);
    EnvList[count + 1] = NULL;
  }
  return true;
}
示例#7
0
文件: crypt.c 项目: darnir/neomutt
/**
 * crypt_get_keys - Check we have all the keys we need
 * @param[in]  msg         Message with addresses to match
 * @param[out] keylist     Keys needed
 * @param[in]  oppenc_mode If true, use opportunistic encryption
 * @retval  0 Success
 * @retval -1 Error
 *
 * Do a quick check to make sure that we can find all of the
 * encryption keys if the user has requested this service.
 * Return the list of keys in KEYLIST.
 * If oppenc_mode is true, only keys that can be determined without
 * prompting will be used.
 */
int crypt_get_keys(struct Email *msg, char **keylist, bool oppenc_mode)
{
  struct Address *addrlist = NULL, *last = NULL;
  const char *fqdn = mutt_fqdn(true);
  char *self_encrypt = NULL;

  /* Do a quick check to make sure that we can find all of the encryption
   * keys if the user has requested this service.  */

  if (!WithCrypto)
    return 0;

  if (WithCrypto & APPLICATION_PGP)
    OptPgpCheckTrust = true;

  last = mutt_addr_append(&addrlist, msg->env->to, false);
  last = mutt_addr_append(last ? &last : &addrlist, msg->env->cc, false);
  mutt_addr_append(last ? &last : &addrlist, msg->env->bcc, false);

  if (fqdn)
    mutt_addr_qualify(addrlist, fqdn);
  addrlist = mutt_addrlist_dedupe(addrlist);

  *keylist = NULL;

  if (oppenc_mode || (msg->security & SEC_ENCRYPT))
  {
    if (((WithCrypto & APPLICATION_PGP) != 0) && (msg->security & APPLICATION_PGP))
    {
      *keylist = crypt_pgp_find_keys(addrlist, oppenc_mode);
      if (!*keylist)
      {
        mutt_addr_free(&addrlist);
        return -1;
      }
      OptPgpCheckTrust = false;
      if (C_PgpSelfEncrypt || (C_PgpEncryptSelf == MUTT_YES))
        self_encrypt = C_PgpDefaultKey;
    }
    if (((WithCrypto & APPLICATION_SMIME) != 0) && (msg->security & APPLICATION_SMIME))
    {
      *keylist = crypt_smime_find_keys(addrlist, oppenc_mode);
      if (!*keylist)
      {
        mutt_addr_free(&addrlist);
        return -1;
      }
      if (C_SmimeSelfEncrypt || (C_SmimeEncryptSelf == MUTT_YES))
        self_encrypt = C_SmimeDefaultKey;
    }
  }

  if (!oppenc_mode && self_encrypt && *self_encrypt)
  {
    const size_t keylist_size = mutt_str_strlen(*keylist);
    mutt_mem_realloc(keylist, keylist_size + mutt_str_strlen(self_encrypt) + 2);
    sprintf(*keylist + keylist_size, " %s", self_encrypt);
  }

  mutt_addr_free(&addrlist);

  return 0;
}