Coverage Report

Created: 2023-06-07 06:15

/src/neomutt/pop/config.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file
3
 * Config used by libpop
4
 *
5
 * @authors
6
 * Copyright (C) 2020 Richard Russon <rich@flatcap.org>
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/**
24
 * @page pop_config Config used by libpop
25
 *
26
 * Config used by libpop
27
 */
28
29
#include "config.h"
30
#include <stddef.h>
31
#include <config/lib.h>
32
#include <stdbool.h>
33
#include <stdint.h>
34
#include "private.h"
35
#include "mutt/lib.h"
36
#include "conn/lib.h"
37
38
/**
39
 * pop_auth_validator - Validate the "pop_authenticators" config variable - Implements ConfigDef::validator() - @ingroup cfg_def_validator
40
 */
41
static int pop_auth_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
42
                              intptr_t value, struct Buffer *err)
43
9.42k
{
44
9.42k
  const struct Slist *pop_auth_methods = (const struct Slist *) value;
45
9.42k
  if (!pop_auth_methods || (pop_auth_methods->count == 0))
46
9.42k
    return CSR_SUCCESS;
47
48
0
  struct ListNode *np = NULL;
49
0
  STAILQ_FOREACH(np, &pop_auth_methods->head, entries)
50
0
  {
51
0
    if (pop_auth_is_valid(np->data))
52
0
      continue;
53
#ifdef USE_SASL_CYRUS
54
    if (sasl_auth_validator(np->data))
55
      continue;
56
#endif
57
0
    buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
58
0
    return CSR_ERR_INVALID;
59
0
  }
60
61
0
  return CSR_SUCCESS;
62
0
}
63
64
/**
65
 * PopVars - Config definitions for the POP library
66
 */
67
static struct ConfigDef PopVars[] = {
68
  // clang-format off
69
  { "pop_auth_try_all", DT_BOOL, true, 0, NULL,
70
    "(pop) Try all available authentication methods"
71
  },
72
  { "pop_authenticators", DT_SLIST|SLIST_SEP_COLON, 0, 0, pop_auth_validator,
73
    "(pop) List of allowed authentication methods (colon-separated)"
74
  },
75
  { "pop_check_interval", DT_NUMBER|DT_NOT_NEGATIVE, 60, 0, NULL,
76
    "(pop) Interval between checks for new mail"
77
  },
78
  { "pop_delete", DT_QUAD, MUTT_ASKNO, 0, NULL,
79
    "(pop) After downloading POP messages, delete them on the server"
80
  },
81
  { "pop_host", DT_STRING, 0, 0, NULL,
82
    "(pop) Url of the POP server"
83
  },
84
  { "pop_last", DT_BOOL, false, 0, NULL,
85
    "(pop) Use the 'LAST' command to fetch new mail"
86
  },
87
  { "pop_oauth_refresh_command", DT_STRING|DT_COMMAND|DT_SENSITIVE, 0, 0, NULL,
88
    "(pop) External command to generate OAUTH refresh token"
89
  },
90
  { "pop_pass", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
91
    "(pop) Password of the POP server"
92
  },
93
  { "pop_reconnect", DT_QUAD, MUTT_ASKYES, 0, NULL,
94
    "(pop) Reconnect to the server is the connection is lost"
95
  },
96
  { "pop_user", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
97
    "(pop) Username of the POP server"
98
  },
99
100
  { "pop_checkinterval", DT_SYNONYM, IP "pop_check_interval", IP "2021-02-11" },
101
  { NULL },
102
  // clang-format on
103
};
104
105
/**
106
 * config_init_pop - Register pop config variables - Implements ::module_init_config_t - @ingroup cfg_module_api
107
 */
108
bool config_init_pop(struct ConfigSet *cs)
109
9.42k
{
110
9.42k
  return cs_register_variables(cs, PopVars, DT_NO_FLAGS);
111
9.42k
}