2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2007 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
16 #include "../pith/headers.h"
17 #include "../pith/pipe.h"
18 #include "../pith/stream.h"
19 #include "../pith/status.h"
26 * Support structure and functions to support piping raw message texts...
28 static struct raw_pipe_data
{
30 unsigned long msgno
, len
;
31 long char_limit
, flags
;
37 raw_pipe_getc(unsigned char *c
)
39 static char *free_this
= NULL
;
42 * What is this if doing?
44 * If((just_starting && unsuccessful_fetch_header)
45 * || (no_chars_available && haven't_fetched_body
46 * && (not_supposed_to_fetch
47 * || (supposed_to_fetch_all && unsuccessful_fetch_text)
48 * || (supposed_to_partial_fetch && unsuccessful_partial_fetch))
49 * || (no_chars_available))
52 * otherwise, fall through and return next character
55 && !(raw_pipe
.cur
= mail_fetch_header(raw_pipe
.stream
, raw_pipe
.msgno
,
59 || ((raw_pipe
.len
<= 0L) && !raw_pipe
.body
60 && (raw_pipe
.char_limit
== 0L
61 || (raw_pipe
.char_limit
< 0L
62 && !(raw_pipe
.cur
= raw_pipe
.body
=
63 pine_mail_fetch_text(raw_pipe
.stream
,
68 || (raw_pipe
.char_limit
> 0L
69 && !(raw_pipe
.cur
= raw_pipe
.body
=
70 pine_mail_partial_fetch_wrapper(raw_pipe
.stream
,
75 (unsigned long) raw_pipe
.char_limit
,
77 || (raw_pipe
.len
<= 0L)){
80 fs_give((void **) &free_this
);
85 if(raw_pipe
.char_limit
> 0L
87 && raw_pipe
.len
> raw_pipe
.char_limit
)
88 raw_pipe
.len
= raw_pipe
.char_limit
;
90 if(raw_pipe
.len
> 0L){
91 *c
= (unsigned char) *raw_pipe
.cur
++;
102 * Set up for using raw_pipe_getc
106 * char_limit Set to -1 means whole thing
107 * 0 means headers only
108 * > 0 means headers plus char_limit body chars
109 * flags -- passed to fetch functions
112 prime_raw_pipe_getc(MAILSTREAM
*stream
, long int msgno
, long int char_limit
, long int flags
)
114 raw_pipe
.stream
= stream
;
115 raw_pipe
.msgno
= (unsigned long) msgno
;
116 raw_pipe
.char_limit
= char_limit
;
118 raw_pipe
.flags
= flags
;
120 raw_pipe
.body
= NULL
;
124 /*----------------------------------------------------------------------
125 Actually open the pipe used to write piped data down
128 Returns: TRUE if success, otherwise FALSE
132 cmd_pipe_open(char *cmd
, char **result
, int flags
, gf_io_t
*pc
)
137 if((pipe
= open_system_pipe(cmd
, result
, NULL
, flags
, 0,
138 pipe_callback
, pipe_report_error
)) != NULL
)
139 gf_set_writec(pc
, pipe
, 0L, PipeStar
, (flags
& PIPE_RAW
) ? 0 : WRITE_TO_LOCALE
);
141 /* TRANSLATORS: The argument is the command name being piped to. */
142 snprintf(err
, sizeof(err
), _("Error opening pipe: %s"), cmd
? cmd
: "?");
143 q_status_message(SM_ORDER
| SM_DING
, 3, 3, err
) ;