NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
state.h File Reference

Keep track when processing files. More...

#include <stdint.h>
#include <stdio.h>
#include <wchar.h>
+ Include dependency graph for state.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  State
 Keep track when processing files. More...
 

Macros

#define MUTT_STATE_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_DISPLAY   (1 << 0)
 Output is displayed to the user. More...
 
#define MUTT_VERIFY   (1 << 1)
 Perform signature verification. More...
 
#define MUTT_PENDINGPREFIX   (1 << 2)
 Prefix to write, but character must follow. More...
 
#define MUTT_WEED   (1 << 3)
 Weed headers even when not in display mode. More...
 
#define MUTT_CHARCONV   (1 << 4)
 Do character set conversions. More...
 
#define MUTT_PRINTING   (1 << 5)
 Are we printing? - MUTT_DISPLAY "light". More...
 
#define MUTT_REPLYING   (1 << 6)
 Are we replying? More...
 
#define MUTT_FIRSTDONE   (1 << 7)
 The first attachment has been done. More...
 
#define state_set_prefix(state)   ((state)->flags |= MUTT_PENDINGPREFIX)
 
#define state_reset_prefix(state)   ((state)->flags &= ~MUTT_PENDINGPREFIX)
 
#define state_puts(STATE, STR)   fputs(STR, (STATE)->fp_out)
 
#define state_putc(STATE, STR)   fputc(STR, (STATE)->fp_out)
 

Typedefs

typedef uint8_t StateFlags
 Flags for State->flags, e.g. MUTT_DISPLAY. More...
 

Functions

void state_attach_puts (struct State *s, const char *t)
 Write a string to the state. More...
 
void state_mark_attach (struct State *s)
 Write a unique marker around content. More...
 
void state_mark_protected_header (struct State *s)
 Write a unique marker around protected headers. More...
 
void state_prefix_put (struct State *s, const char *buf, size_t buflen)
 Write a prefixed fixed-string to the State. More...
 
void state_prefix_putc (struct State *s, char c)
 Write a prefixed character to the state. More...
 
int state_printf (struct State *s, const char *fmt,...)
 Write a formatted string to the State. More...
 
int state_putws (struct State *s, const wchar_t *ws)
 Write a wide string to the state. More...
 
const char * state_attachment_marker (void)
 Get a unique (per-run) ANSI string to mark PGP messages in an email. More...
 
const char * state_protected_header_marker (void)
 Get a unique (per-run) ANSI string to mark protected headers in an email. More...
 

Detailed Description

Keep track when processing files.

Authors
  • Richard Russon

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/.

Definition in file state.h.

Macro Definition Documentation

◆ MUTT_STATE_NO_FLAGS

#define MUTT_STATE_NO_FLAGS   0

No flags are set.

Definition at line 31 of file state.h.

◆ MUTT_DISPLAY

#define MUTT_DISPLAY   (1 << 0)

Output is displayed to the user.

Definition at line 32 of file state.h.

◆ MUTT_VERIFY

#define MUTT_VERIFY   (1 << 1)

Perform signature verification.

Definition at line 33 of file state.h.

◆ MUTT_PENDINGPREFIX

#define MUTT_PENDINGPREFIX   (1 << 2)

Prefix to write, but character must follow.

Definition at line 34 of file state.h.

◆ MUTT_WEED

#define MUTT_WEED   (1 << 3)

Weed headers even when not in display mode.

Definition at line 35 of file state.h.

◆ MUTT_CHARCONV

#define MUTT_CHARCONV   (1 << 4)

Do character set conversions.

Definition at line 36 of file state.h.

◆ MUTT_PRINTING

#define MUTT_PRINTING   (1 << 5)

Are we printing? - MUTT_DISPLAY "light".

Definition at line 37 of file state.h.

◆ MUTT_REPLYING

#define MUTT_REPLYING   (1 << 6)

Are we replying?

Definition at line 38 of file state.h.

◆ MUTT_FIRSTDONE

#define MUTT_FIRSTDONE   (1 << 7)

The first attachment has been done.

Definition at line 39 of file state.h.

◆ state_set_prefix

#define state_set_prefix (   state)    ((state)->flags |= MUTT_PENDINGPREFIX)

Definition at line 53 of file state.h.

◆ state_reset_prefix

#define state_reset_prefix (   state)    ((state)->flags &= ~MUTT_PENDINGPREFIX)

Definition at line 54 of file state.h.

◆ state_puts

#define state_puts (   STATE,
  STR 
)    fputs(STR, (STATE)->fp_out)

Definition at line 55 of file state.h.

◆ state_putc

#define state_putc (   STATE,
  STR 
)    fputc(STR, (STATE)->fp_out)

Definition at line 56 of file state.h.

Typedef Documentation

◆ StateFlags

typedef uint8_t StateFlags

Flags for State->flags, e.g. MUTT_DISPLAY.

Definition at line 30 of file state.h.

Function Documentation

◆ state_attach_puts()

void state_attach_puts ( struct State s,
const char *  t 
)

Write a string to the state.

Parameters
sState to write to
tText to write

Definition at line 104 of file state.c.

105 {
106  if (!s || !s->fp_out || !t)
107  return;
108 
109  if (*t != '\n')
111  while (*t)
112  {
113  state_putc(s, *t);
114  if ((*t++ == '\n') && *t)
115  if (*t != '\n')
117  }
118 }
FILE * fp_out
File to write to.
Definition: state.h:47
void state_mark_attach(struct State *s)
Write a unique marker around content.
Definition: state.c:73
#define state_putc(STATE, STR)
Definition: state.h:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_mark_attach()

void state_mark_attach ( struct State s)

Write a unique marker around content.

Parameters
sState to write to

Definition at line 73 of file state.c.

74 {
75  if (!s || !s->fp_out)
76  return;
77  const char *const c_pager = cs_subset_string(NeoMutt->sub, "pager");
78  if ((s->flags & MUTT_DISPLAY) &&
79  (!c_pager || mutt_str_equal(c_pager, "builtin")))
80  {
82  }
83 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#define state_puts(STATE, STR)
Definition: state.h:55
const char * state_attachment_marker(void)
Get a unique (per-run) ANSI string to mark PGP messages in an email.
Definition: state.c:44
FILE * fp_out
File to write to.
Definition: state.h:47
Container for Accounts, Notifications.
Definition: neomutt.h:36
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_mark_protected_header()

void state_mark_protected_header ( struct State s)

Write a unique marker around protected headers.

Parameters
sState to write to

Definition at line 89 of file state.c.

90 {
91  const char *const c_pager = cs_subset_string(NeoMutt->sub, "pager");
92  if ((s->flags & MUTT_DISPLAY) &&
93  (!c_pager || mutt_str_equal(c_pager, "builtin")))
94  {
96  }
97 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#define state_puts(STATE, STR)
Definition: state.h:55
Container for Accounts, Notifications.
Definition: neomutt.h:36
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
const char * state_protected_header_marker(void)
Get a unique (per-run) ANSI string to mark protected headers in an email.
Definition: state.c:59
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_prefix_put()

void state_prefix_put ( struct State s,
const char *  buf,
size_t  buflen 
)

Write a prefixed fixed-string to the State.

Parameters
sState to write to
bufString to write
buflenLength of string

Definition at line 205 of file state.c.

206 {
207  if (s->prefix)
208  {
209  while (buflen--)
210  state_prefix_putc(s, *buf++);
211  }
212  else
213  fwrite(buf, buflen, 1, s->fp_out);
214 }
char * prefix
String to add to the beginning of each output line.
Definition: state.h:48
FILE * fp_out
File to write to.
Definition: state.h:47
void state_prefix_putc(struct State *s, char c)
Write a prefixed character to the state.
Definition: state.c:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_prefix_putc()

void state_prefix_putc ( struct State s,
char  c 
)

Write a prefixed character to the state.

Parameters
sState to write to
cCharacter to write

Definition at line 165 of file state.c.

166 {
167  if (s->flags & MUTT_PENDINGPREFIX)
168  {
170  if (s->prefix)
171  state_puts(s, s->prefix);
172  }
173 
174  state_putc(s, c);
175 
176  if (c == '\n')
177  state_set_prefix(s);
178 }
#define state_puts(STATE, STR)
Definition: state.h:55
#define MUTT_PENDINGPREFIX
Prefix to write, but character must follow.
Definition: state.h:34
char * prefix
String to add to the beginning of each output line.
Definition: state.h:48
#define state_reset_prefix(state)
Definition: state.h:54
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
#define state_set_prefix(state)
Definition: state.h:53
#define state_putc(STATE, STR)
Definition: state.h:56
+ Here is the caller graph for this function:

◆ state_printf()

int state_printf ( struct State s,
const char *  fmt,
  ... 
)

Write a formatted string to the State.

Parameters
sState to write to
fmtprintf format string
...Arguments to formatting string
Return values
numNumber of characters written

Definition at line 187 of file state.c.

188 {
189  int rc;
190  va_list ap;
191 
192  va_start(ap, fmt);
193  rc = vfprintf(s->fp_out, fmt, ap);
194  va_end(ap);
195 
196  return rc;
197 }
FILE * fp_out
File to write to.
Definition: state.h:47
+ Here is the caller graph for this function:

◆ state_putws()

int state_putws ( struct State s,
const wchar_t *  ws 
)

Write a wide string to the state.

Parameters
sState to write to
wsWide string to write
Return values
0Success
-1Error

Definition at line 147 of file state.c.

148 {
149  const wchar_t *p = ws;
150 
151  while (p && (*p != L'\0'))
152  {
153  if (state_putwc(s, *p) < 0)
154  return -1;
155  p++;
156  }
157  return 0;
158 }
static int state_putwc(struct State *s, wchar_t wc)
Write a wide character to the state.
Definition: state.c:127
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_attachment_marker()

const char* state_attachment_marker ( void  )

Get a unique (per-run) ANSI string to mark PGP messages in an email.

Return values
sMarker

Definition at line 44 of file state.c.

45 {
46  static char marker[256] = { 0 };
47  if (!marker[0])
48  {
49  snprintf(marker, sizeof(marker), "\033]9;%" PRIu64 "\a", mutt_rand64());
50  }
51  return marker;
52 }
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:130
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_protected_header_marker()

const char* state_protected_header_marker ( void  )

Get a unique (per-run) ANSI string to mark protected headers in an email.

Return values
sMarker

Definition at line 59 of file state.c.

60 {
61  static char marker[256] = { 0 };
62  if (!marker[0])
63  {
64  snprintf(marker, sizeof(marker), "\033]8;%lld\a", (long long) mutt_date_epoch());
65  }
66  return marker;
67 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
+ Here is the call graph for this function:
+ Here is the caller graph for this function: