NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
rfc3676.h File Reference

RFC3676 Format Flowed routines. More...

#include <stdbool.h>
+ Include dependency graph for rfc3676.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int rfc3676_handler (struct Body *a, struct State *s)
 Body handler implementing RFC3676 for format=flowed - Implements handler_t. More...
 
void mutt_rfc3676_space_stuff (struct Email *e)
 Perform RFC3676 space stuffing on an Email. More...
 
void mutt_rfc3676_space_unstuff (struct Email *e)
 Remove RFC3676 space stuffing. More...
 

Variables

bool C_ReflowSpaceQuotes
 Config: Insert spaces into reply quotes for 'format=flowed' messages. More...
 
short C_ReflowWrap
 Config: Maximum paragraph width for reformatting 'format=flowed' text. More...
 

Detailed Description

RFC3676 Format Flowed routines.

Authors
  • Andreas Krennmair
  • Peter J. Holzer
  • Rocco Rutte

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 rfc3676.h.

Function Documentation

◆ rfc3676_handler()

int rfc3676_handler ( struct Body a,
struct State s 
)

Body handler implementing RFC3676 for format=flowed - Implements handler_t.

Return values
0Always

Definition at line 317 of file rfc3676.c.

318 {
319  char *buf = NULL;
320  unsigned int quotelevel = 0;
321  bool delsp = false;
322  size_t sz = 0;
323  struct FlowedState fst = { 0 };
324 
325  /* respect DelSp of RFC3676 only with f=f parts */
326  char *t = mutt_param_get(&a->parameter, "delsp");
327  if (t)
328  {
329  delsp = (mutt_str_strcasecmp(t, "yes") == 0);
330  t = NULL;
331  fst.delsp = true;
332  }
333 
334  mutt_debug(LL_DEBUG3, "f=f: DelSp: %s\n", delsp ? "yes" : "no");
335 
336  while ((buf = mutt_file_read_line(buf, &sz, s->fp_in, NULL, 0)))
337  {
338  const size_t buf_len = mutt_str_strlen(buf);
339  const unsigned int newql = get_quote_level(buf);
340 
341  /* end flowed paragraph (if we're within one) if quoting level
342  * changes (should not but can happen, see RFC3676, sec. 4.5.) */
343  if (newql != quotelevel)
344  flush_par(s, &fst);
345 
346  quotelevel = newql;
347  int buf_off = newql;
348 
349  /* respect sender's space-stuffing by removing one leading space */
350  if (buf[buf_off] == ' ')
351  buf_off++;
352 
353  /* test for signature separator */
354  const unsigned int sigsep = (mutt_str_strcmp(buf + buf_off, "-- ") == 0);
355 
356  /* a fixed line either has no trailing space or is the
357  * signature separator */
358  const bool fixed = (buf_len == buf_off) || (buf[buf_len - 1] != ' ') || sigsep;
359 
360  /* print fixed-and-standalone, fixed-and-empty and sigsep lines as
361  * fixed lines */
362  if ((fixed && ((fst.width == 0) || (buf_len == 0))) || sigsep)
363  {
364  /* if we're within a flowed paragraph, terminate it */
365  flush_par(s, &fst);
366  print_fixed_line(buf + buf_off, s, quotelevel, &fst);
367  continue;
368  }
369 
370  /* for DelSp=yes, we need to strip one SP prior to CRLF on flowed lines */
371  if (delsp && !fixed)
372  buf[buf_len - 1] = '\0';
373 
374  print_flowed_line(buf + buf_off, s, quotelevel, &fst, fixed);
375  }
376 
377  flush_par(s, &fst);
378 
379  FREE(&buf);
380  return 0;
381 }
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
Definition: file.c:664
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
FILE * fp_in
File to read from.
Definition: state.h:46
static int get_quote_level(const char *line)
Get the quote level of a line.
Definition: rfc3676.c:67
static void print_fixed_line(const char *line, struct State *s, int ql, struct FlowedState *fst)
Print a fixed format line.
Definition: rfc3676.c:302
size_t width
Definition: rfc3676.c:57
State of a Format-Flowed line of text.
Definition: rfc3676.c:55
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define FREE(x)
Definition: memory.h:40
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
static void flush_par(struct State *s, struct FlowedState *fst)
Write out the paragraph.
Definition: rfc3676.c:173
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
static void print_flowed_line(char *line, struct State *s, int ql, struct FlowedState *fst, bool term)
Print a format-flowed line.
Definition: rfc3676.c:224
bool delsp
Definition: rfc3676.c:59
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
Log at debug level 3.
Definition: logging.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_rfc3676_space_stuff()

void mutt_rfc3676_space_stuff ( struct Email e)

Perform RFC3676 space stuffing on an Email.

Parameters
eEmail

Note: we don't check the option C_TextFlowed because we want to stuff based the actual content type. The option only decides whether to set format=flowed on new messages.

Definition at line 468 of file rfc3676.c.

469 {
470  if (!e || !e->content || !e->content->filename)
471  return;
472 
473  if ((e->content->type == TYPE_TEXT) &&
474  (mutt_str_strcasecmp("plain", e->content->subtype) == 0))
475  {
476  const char *format = mutt_param_get(&e->content->parameter, "format");
477  if (mutt_str_strcasecmp("flowed", format) == 0)
478  rfc3676_space_stuff(e, false);
479  }
480 }
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
struct Body * content
List of MIME parts.
Definition: email.h:90
char * subtype
content-type subtype
Definition: body.h:37
Type: &#39;text/*&#39;.
Definition: mime.h:38
unsigned int type
content-type primary type
Definition: body.h:65
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
static void rfc3676_space_stuff(struct Email *e, bool unstuff)
Perform required RFC3676 space stuffing.
Definition: rfc3676.c:396
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_rfc3676_space_unstuff()

void mutt_rfc3676_space_unstuff ( struct Email e)

Remove RFC3676 space stuffing.

Parameters
eEmail

Definition at line 486 of file rfc3676.c.

487 {
488  if (!e || !e->content || !e->content->filename)
489  return;
490 
491  if ((e->content->type == TYPE_TEXT) &&
492  !mutt_str_strcasecmp("plain", e->content->subtype))
493  {
494  const char *format = mutt_param_get(&e->content->parameter, "format");
495  if (mutt_str_strcasecmp("flowed", format) == 0)
496  rfc3676_space_stuff(e, true);
497  }
498 }
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
struct Body * content
List of MIME parts.
Definition: email.h:90
char * subtype
content-type subtype
Definition: body.h:37
Type: &#39;text/*&#39;.
Definition: mime.h:38
unsigned int type
content-type primary type
Definition: body.h:65
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
static void rfc3676_space_stuff(struct Email *e, bool unstuff)
Perform required RFC3676 space stuffing.
Definition: rfc3676.c:396
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_ReflowSpaceQuotes

bool C_ReflowSpaceQuotes

Config: Insert spaces into reply quotes for 'format=flowed' messages.

Definition at line 47 of file rfc3676.c.

◆ C_ReflowWrap

short C_ReflowWrap

Config: Maximum paragraph width for reformatting 'format=flowed' text.

Definition at line 48 of file rfc3676.c.