NeoMutt  2020-06-26-250-g349c94
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...
 
bool mutt_rfc3676_is_format_flowed (struct Body *b)
 Is the Email "format-flowed"? 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...
 
void mutt_rfc3676_space_unstuff_attachment (struct Body *b, const char *filename)
 Unstuff attachments. More...
 
void mutt_rfc3676_space_stuff_attachment (struct Body *b, const char *filename)
 Stuff attachments. 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 316 of file rfc3676.c.

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

◆ mutt_rfc3676_is_format_flowed()

bool mutt_rfc3676_is_format_flowed ( struct Body b)

Is the Email "format-flowed"?

Parameters
bEmail Body to examine
Return values
booltrue, if "format-flowed"

Definition at line 387 of file rfc3676.c.

388 {
389  if (b && (b->type == TYPE_TEXT) && mutt_istr_equal("plain", b->subtype))
390  {
391  const char *format = mutt_param_get(&b->parameter, "format");
392  if (mutt_istr_equal("flowed", format))
393  return true;
394  }
395 
396  return false;
397 }
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:888
char * subtype
content-type subtype
Definition: body.h:37
Type: &#39;text/*&#39;.
Definition: mime.h:38
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
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_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 479 of file rfc3676.c.

480 {
481  if (!e || !e->content || !e->content->filename)
482  return;
483 
486 }
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
bool mutt_rfc3676_is_format_flowed(struct Body *b)
Is the Email "format-flowed"?
Definition: rfc3676.c:387
struct Body * content
List of MIME parts.
Definition: email.h:91
static void rfc3676_space_stuff(const char *filename, bool unstuff)
Perform required RFC3676 space stuffing.
Definition: rfc3676.c:412
+ 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 492 of file rfc3676.c.

493 {
494  if (!e || !e->content || !e->content->filename)
495  return;
496 
499 }
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
bool mutt_rfc3676_is_format_flowed(struct Body *b)
Is the Email "format-flowed"?
Definition: rfc3676.c:387
struct Body * content
List of MIME parts.
Definition: email.h:91
static void rfc3676_space_stuff(const char *filename, bool unstuff)
Perform required RFC3676 space stuffing.
Definition: rfc3676.c:412
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_rfc3676_space_unstuff_attachment()

void mutt_rfc3676_space_unstuff_attachment ( struct Body b,
const char *  filename 
)

Unstuff attachments.

Parameters
bEmail Body (OPTIONAL)
filenameAttachment file

This routine is used when saving/piping/viewing rfc3676 attachments.

If b is provided, the function will verify that the Email is format-flowed. The filename will be unstuffed, not b->filename or b->fp.

Definition at line 511 of file rfc3676.c.

512 {
513  if (!filename)
514  return;
515 
516  if (b && !mutt_rfc3676_is_format_flowed(b))
517  return;
518 
519  rfc3676_space_stuff(filename, true);
520 }
bool mutt_rfc3676_is_format_flowed(struct Body *b)
Is the Email "format-flowed"?
Definition: rfc3676.c:387
static void rfc3676_space_stuff(const char *filename, bool unstuff)
Perform required RFC3676 space stuffing.
Definition: rfc3676.c:412
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_rfc3676_space_stuff_attachment()

void mutt_rfc3676_space_stuff_attachment ( struct Body b,
const char *  filename 
)

Stuff attachments.

Parameters
bEmail Body (OPTIONAL)
filenameAttachment file

This routine is used when filtering rfc3676 attachments.

If b is provided, the function will verify that the Email is format-flowed. The filename will be unstuffed, not b->filename or b->fp.

Definition at line 532 of file rfc3676.c.

533 {
534  if (!filename)
535  return;
536 
537  if (b && !mutt_rfc3676_is_format_flowed(b))
538  return;
539 
540  rfc3676_space_stuff(filename, false);
541 }
bool mutt_rfc3676_is_format_flowed(struct Body *b)
Is the Email "format-flowed"?
Definition: rfc3676.c:387
static void rfc3676_space_stuff(const char *filename, bool unstuff)
Perform required RFC3676 space stuffing.
Definition: rfc3676.c:412
+ 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 46 of file rfc3676.c.

◆ C_ReflowWrap

short C_ReflowWrap

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

Definition at line 47 of file rfc3676.c.