File: expando_command.c

package info (click to toggle)
neomutt 20250510%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,372 kB
  • sloc: ansic: 171,730; sh: 5,357; perl: 1,121; tcl: 1,065; python: 443; makefile: 48
file content (110 lines) | stat: -rw-r--r-- 3,674 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 * @file
 * Ncrypt Expando definitions
 *
 * @authors
 * Copyright (C) 2024 Richard Russon <rich@flatcap.org>
 *
 * @copyright
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @page ncrypt_expando_command Ncrypt Expando definitions
 *
 * Ncrypt Expando definitions
 */

#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "expando_command.h"
#include "expando/lib.h"
#include "pgp.h"

/**
 * pgp_command_file_message - PGP Command: Filename of message - Implements ::get_string_t - @ingroup expando_get_string_api
 */
static void pgp_command_file_message(const struct ExpandoNode *node, void *data,
                                     MuttFormatFlags flags, struct Buffer *buf)
{
  const struct PgpCommandContext *cctx = data;

  const char *s = cctx->fname;
  buf_strcpy(buf, s);
}

/**
 * pgp_command_file_signature - PGP Command: Filename of signature - Implements ::get_string_t - @ingroup expando_get_string_api
 */
static void pgp_command_file_signature(const struct ExpandoNode *node, void *data,
                                       MuttFormatFlags flags, struct Buffer *buf)
{
  const struct PgpCommandContext *cctx = data;

  const char *s = cctx->sig_fname;
  buf_strcpy(buf, s);
}

/**
 * pgp_command_key_ids - PGP Command: key IDs - Implements ::get_string_t - @ingroup expando_get_string_api
 */
static void pgp_command_key_ids(const struct ExpandoNode *node, void *data,
                                MuttFormatFlags flags, struct Buffer *buf)
{
  const struct PgpCommandContext *cctx = data;

  const char *s = cctx->ids;
  buf_strcpy(buf, s);
}

/**
 * pgp_command_need_pass - PGP Command: PGPPASSFD=0 if passphrase is needed - Implements ::get_string_t - @ingroup expando_get_string_api
 */
static void pgp_command_need_pass(const struct ExpandoNode *node, void *data,
                                  MuttFormatFlags flags, struct Buffer *buf)
{
  const struct PgpCommandContext *cctx = data;

  const char *s = cctx->need_passphrase ? "PGPPASSFD=0" : "";
  buf_strcpy(buf, s);
}

/**
 * pgp_command_sign_as - PGP Command: $pgp_sign_as or $pgp_default_key - Implements ::get_string_t - @ingroup expando_get_string_api
 */
static void pgp_command_sign_as(const struct ExpandoNode *node, void *data,
                                MuttFormatFlags flags, struct Buffer *buf)
{
  const struct PgpCommandContext *cctx = data;

  const char *s = cctx->signas;
  buf_strcpy(buf, s);
}

/**
 * PgpCommandRenderCallbacks - Callbacks for PGP Command Expandos
 *
 * @sa PgpCommandFormatDef, ExpandoDataPgpCmd
 */
const struct ExpandoRenderCallback PgpCommandRenderCallbacks[] = {
  // clang-format off
  { ED_PGP_CMD, ED_PGC_FILE_MESSAGE,   pgp_command_file_message,   NULL },
  { ED_PGP_CMD, ED_PGC_FILE_SIGNATURE, pgp_command_file_signature, NULL },
  { ED_PGP_CMD, ED_PGC_KEY_IDS,        pgp_command_key_ids,        NULL },
  { ED_PGP_CMD, ED_PGC_NEED_PASS,      pgp_command_need_pass,      NULL },
  { ED_PGP_CMD, ED_PGC_SIGN_AS,        pgp_command_sign_as,        NULL },
  { -1, -1, NULL, NULL },
  // clang-format on
};