NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
body.h File Reference

Convenience wrapper for the send headers. More...

#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 *b, FILE *fp, struct ConfigSubset *sub)
 Write a MIME part.
 

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 * b,
FILE * fp,
struct ConfigSubset * sub )

Write a MIME part.

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

Definition at line 302 of file body.c.

303{
304 FILE *fp_in = NULL;
305 struct FgetConv *fc = NULL;
306
307 if (b->type == TYPE_MULTIPART)
308 {
309 /* First, find the boundary to use */
310 const char *p = mutt_param_get(&b->parameter, "boundary");
311 if (!p)
312 {
313 mutt_debug(LL_DEBUG1, "no boundary parameter found\n");
314 mutt_error(_("No boundary parameter found [report this error]"));
315 return -1;
316 }
317 char boundary[128] = { 0 };
318 mutt_str_copy(boundary, p, sizeof(boundary));
319
320 for (struct Body *t = b->parts; t; t = t->next)
321 {
322 fprintf(fp, "\n--%s\n", boundary);
323 if (mutt_write_mime_header(t, fp, sub) == -1)
324 return -1;
325 fputc('\n', fp);
326 if (mutt_write_mime_body(t, fp, sub) == -1)
327 return -1;
328 }
329 fprintf(fp, "\n--%s--\n", boundary);
330 return ferror(fp) ? -1 : 0;
331 }
332
333 /* This is pretty gross, but it's the best solution for now... */
334 if (((WithCrypto & APPLICATION_PGP) != 0) && (b->type == TYPE_APPLICATION) &&
335 mutt_str_equal(b->subtype, "pgp-encrypted") && !b->filename)
336 {
337 fputs("Version: 1\n", fp);
338 return 0;
339 }
340
341 fp_in = mutt_file_fopen(b->filename, "r");
342 if (!fp_in)
343 {
344 mutt_debug(LL_DEBUG1, "%s no longer exists\n", NONULL(b->filename));
345 mutt_error(_("%s no longer exists"), NONULL(b->filename));
346 return -1;
347 }
348
349 if ((b->type == TYPE_TEXT) && (!b->noconv))
350 {
351 char send_charset[128] = { 0 };
352 fc = mutt_ch_fgetconv_open(fp_in, b->charset,
353 mutt_body_get_charset(b, send_charset, sizeof(send_charset)),
355 }
356 else
357 {
359 }
360
364 else if (b->encoding == ENC_BASE64)
366 else if ((b->type == TYPE_TEXT) && (!b->noconv))
367 encode_8bit(fc, fp);
368 else
371
373 mutt_file_fclose(&fp_in);
374
375 if (SigInt)
376 {
377 SigInt = false;
378 return -1;
379 }
380 return ferror(fp) ? -1 : 0;
381}
char * mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
Get a body's character set.
Definition body.c:133
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition file.c:224
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ ENC_BASE64
Base-64 encoded text.
Definition mime.h:52
@ ENC_QUOTED_PRINTABLE
Quoted-printable text.
Definition mime.h:51
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition mime.h:33
@ TYPE_TEXT
Type: 'text/*'.
Definition mime.h:38
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:919
void mutt_ch_fgetconv_close(struct FgetConv **ptr)
Close an fgetconv handle.
Definition charset.c:948
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition charset.h:66
#define _(a)
Definition message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
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:586
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition lib.h:98
#define WithCrypto
Definition lib.h:124
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition parameter.c:85
static void encode_quoted(struct FgetConv *fc, FILE *fp_out, bool istext)
Encode text as quoted printable.
Definition body.c:149
static bool write_as_text_part(struct Body *b)
Should the Body be written as a text MIME part.
Definition body.c:288
static void encode_base64(struct FgetConv *fc, FILE *fp_out, int istext)
Base64-encode some data.
Definition body.c:102
int mutt_write_mime_body(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition body.c:302
static void encode_8bit(struct FgetConv *fc, FILE *fp_out)
Write the data as raw 8-bit data.
Definition body.c:128
int mutt_write_mime_header(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Create a MIME header.
Definition header.c:757
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition signal.c:68
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition signal.c:315
#define NONULL(x)
Definition string2.h:44
The body of an email.
Definition body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition body.h:73
bool noconv
Don't do character set conversion.
Definition body.h:46
char * charset
Send mode: charset of attached file as stored on disk.
Definition body.h:79
struct ParameterList parameter
Parameters of the content-type.
Definition body.h:63
struct Body * next
next attachment in the list
Definition body.h:72
char * subtype
content-type subtype
Definition body.h:61
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition body.h:41
unsigned int type
content-type primary type, ContentType
Definition body.h:40
char * filename
When sending a message, this is the file to which this structure refers.
Definition body.h:59
Cursor for converting a file's encoding.
Definition charset.h:45
FILE * fp
File to read from.
Definition charset.h:46
char * p
Current position in output buffer.
Definition charset.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function: