NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
body.h File Reference
#include <stdio.h>
+ Include dependency graph for body.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int mutt_write_mime_body (struct Body *a, FILE *fp, struct ConfigSubset *sub)
 Write a MIME part. More...
 

Detailed Description

Convenience wrapper for the send headers

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

Function Documentation

◆ mutt_write_mime_body()

int mutt_write_mime_body ( struct Body a,
FILE *  fp,
struct ConfigSubset sub 
)

Write a MIME part.

Parameters
aBody to use
fpFile to write to
subConfig Subset
Return values
0Success
-1Failure

Definition at line 314 of file body.c.

315 {
316  FILE *fp_in = NULL;
317  struct FgetConv *fc = NULL;
318 
319  if (a->type == TYPE_MULTIPART)
320  {
321  /* First, find the boundary to use */
322  const char *p = mutt_param_get(&a->parameter, "boundary");
323  if (!p)
324  {
325  mutt_debug(LL_DEBUG1, "no boundary parameter found\n");
326  mutt_error(_("No boundary parameter found [report this error]"));
327  return -1;
328  }
329  char boundary[128];
330  mutt_str_copy(boundary, p, sizeof(boundary));
331 
332  for (struct Body *t = a->parts; t; t = t->next)
333  {
334  fprintf(fp, "\n--%s\n", boundary);
335  if (mutt_write_mime_header(t, fp, sub) == -1)
336  return -1;
337  fputc('\n', fp);
338  if (mutt_write_mime_body(t, fp, sub) == -1)
339  return -1;
340  }
341  fprintf(fp, "\n--%s--\n", boundary);
342  return ferror(fp) ? -1 : 0;
343  }
344 
345  /* This is pretty gross, but it's the best solution for now... */
346  if (((WithCrypto & APPLICATION_PGP) != 0) && (a->type == TYPE_APPLICATION) &&
347  mutt_str_equal(a->subtype, "pgp-encrypted") && !a->filename)
348  {
349  fputs("Version: 1\n", fp);
350  return 0;
351  }
352 
353  fp_in = fopen(a->filename, "r");
354  if (!fp_in)
355  {
356  mutt_debug(LL_DEBUG1, "%s no longer exists\n", a->filename);
357  mutt_error(_("%s no longer exists"), a->filename);
358  return -1;
359  }
360 
361  if ((a->type == TYPE_TEXT) && (!a->noconv))
362  {
363  char send_charset[128];
364  fc = mutt_ch_fgetconv_open(fp_in, a->charset,
365  mutt_body_get_charset(a, send_charset, sizeof(send_charset)),
367  }
368  else
369  fc = mutt_ch_fgetconv_open(fp_in, 0, 0, MUTT_ICONV_NO_FLAGS);
370 
372  if (a->encoding == ENC_QUOTED_PRINTABLE)
374  else if (a->encoding == ENC_BASE64)
376  else if ((a->type == TYPE_TEXT) && (!a->noconv))
377  encode_8bit(fc, fp);
378  else
379  mutt_file_copy_stream(fp_in, fp);
381 
383  mutt_file_fclose(&fp_in);
384 
385  if (SigInt == 1)
386  {
387  SigInt = 0;
388  return -1;
389  }
390  return ferror(fp) ? -1 : 0;
391 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:
ENC_QUOTED_PRINTABLE
@ ENC_QUOTED_PRINTABLE
Quoted-printable text.
Definition: mime.h:51
Body::noconv
bool noconv
Don't do character set conversion.
Definition: body.h:73
SigInt
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:74
_
#define _(a)
Definition: message.h:28
mutt_file_fclose
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
Body::next
struct Body * next
next attachment in the list
Definition: body.h:53
Body
The body of an email.
Definition: body.h:34
MUTT_ICONV_NO_FLAGS
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition: charset.h:73
encode_8bit
static void encode_8bit(struct FgetConv *fc, FILE *fp_out)
Write the data as raw 8-bit data.
Definition: body.c:146
LL_DEBUG1
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
Body::encoding
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:66
Body::subtype
char * subtype
content-type subtype
Definition: body.h:37
FgetConv::p
char * p
Definition: charset.h:48
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
write_as_text_part
static bool write_as_text_part(struct Body *b)
Should the Body be written as a text MIME part.
Definition: body.c:300
mutt_file_copy_stream
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:271
mutt_write_mime_body
int mutt_write_mime_body(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition: body.c:314
mutt_sig_allow_interrupt
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition: signal.c:238
APPLICATION_PGP
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:97
mutt_body_get_charset
char * mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
Get a body's character set.
Definition: body.c:131
Body::parts
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
Body::charset
char * charset
Send mode: charset of attached file as stored on disk.
Definition: body.h:49
mutt_debug
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
encode_base64
static void encode_base64(struct FgetConv *fc, FILE *fp_out, int istext)
Base64-encode some data.
Definition: body.c:118
WithCrypto
#define WithCrypto
Definition: lib.h:123
mutt_param_get
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
FgetConv::fp
FILE * fp
Definition: charset.h:44
TYPE_APPLICATION
@ TYPE_APPLICATION
Type: 'application/*'.
Definition: mime.h:33
mutt_ch_fgetconv_close
void mutt_ch_fgetconv_close(struct FgetConv **fc)
Close an fgetconv handle.
Definition: charset.c:888
ENC_BASE64
@ ENC_BASE64
Base-64 encoded text.
Definition: mime.h:52
TYPE_TEXT
@ TYPE_TEXT
Type: 'text/*'.
Definition: mime.h:38
Body::type
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
mutt_write_mime_header
int mutt_write_mime_header(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Create a MIME header.
Definition: header.c:764
Body::parameter
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
mutt_ch_fgetconv_open
struct FgetConv * mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags)
Prepare a file for charset conversion.
Definition: charset.c:858
FgetConv
Cursor for converting a file's encoding.
Definition: charset.h:42
TYPE_MULTIPART
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
encode_quoted
static void encode_quoted(struct FgetConv *fc, FILE *fp_out, bool istext)
Encode text as quoted printable.
Definition: body.c:167
Body::filename
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
mutt_error
#define mutt_error(...)
Definition: logging.h:84
mutt_str_copy
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:716