1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: pipe.c 155 2006-09-29 23:28:46Z hubert@u.washington.edu $";
5 * ========================================================================
6 * Copyright 2006-2007 University of Washington
7 * Copyright 2013-2015 Eduardo Chappa
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * ========================================================================
19 #include "../pith/headers.h"
20 #include "../pith/pipe.h"
21 #include "../pith/stream.h"
22 #include "../pith/status.h"
29 * Support structure and functions to support piping raw message texts...
31 static struct raw_pipe_data
{
33 unsigned long msgno
, len
;
34 long char_limit
, flags
;
40 raw_pipe_getc(unsigned char *c
)
42 static char *free_this
= NULL
;
45 * What is this if doing?
47 * If((just_starting && unsuccessful_fetch_header)
48 * || (no_chars_available && haven't_fetched_body
49 * && (not_supposed_to_fetch
50 * || (supposed_to_fetch_all && unsuccessful_fetch_text)
51 * || (supposed_to_partial_fetch && unsuccessful_partial_fetch))
52 * || (no_chars_available))
55 * otherwise, fall through and return next character
58 && !(raw_pipe
.cur
= mail_fetch_header(raw_pipe
.stream
, raw_pipe
.msgno
,
62 || ((raw_pipe
.len
<= 0L) && !raw_pipe
.body
63 && (raw_pipe
.char_limit
== 0L
64 || (raw_pipe
.char_limit
< 0L
65 && !(raw_pipe
.cur
= raw_pipe
.body
=
66 pine_mail_fetch_text(raw_pipe
.stream
,
71 || (raw_pipe
.char_limit
> 0L
72 && !(raw_pipe
.cur
= raw_pipe
.body
=
73 pine_mail_partial_fetch_wrapper(raw_pipe
.stream
,
78 (unsigned long) raw_pipe
.char_limit
,
80 || (raw_pipe
.len
<= 0L)){
83 fs_give((void **) &free_this
);
88 if(raw_pipe
.char_limit
> 0L
90 && raw_pipe
.len
> raw_pipe
.char_limit
)
91 raw_pipe
.len
= raw_pipe
.char_limit
;
93 if(raw_pipe
.len
> 0L){
94 *c
= (unsigned char) *raw_pipe
.cur
++;
105 * Set up for using raw_pipe_getc
109 * char_limit Set to -1 means whole thing
110 * 0 means headers only
111 * > 0 means headers plus char_limit body chars
112 * flags -- passed to fetch functions
115 prime_raw_pipe_getc(MAILSTREAM
*stream
, long int msgno
, long int char_limit
, long int flags
)
117 raw_pipe
.stream
= stream
;
118 raw_pipe
.msgno
= (unsigned long) msgno
;
119 raw_pipe
.char_limit
= char_limit
;
121 raw_pipe
.flags
= flags
;
123 raw_pipe
.body
= NULL
;
127 /*----------------------------------------------------------------------
128 Actually open the pipe used to write piped data down
131 Returns: TRUE if success, otherwise FALSE
135 cmd_pipe_open(char *cmd
, char **result
, int flags
, gf_io_t
*pc
)
140 if((pipe
= open_system_pipe(cmd
, result
, NULL
, flags
, 0,
141 pipe_callback
, pipe_report_error
)) != NULL
)
142 gf_set_writec(pc
, pipe
, 0L, PipeStar
, (flags
& PIPE_RAW
) ? 0 : WRITE_TO_LOCALE
);
144 /* TRANSLATORS: The argument is the command name being piped to. */
145 snprintf(err
, sizeof(err
), _("Error opening pipe: %s"), cmd
? cmd
: "?");
146 q_status_message(SM_ORDER
| SM_DING
, 3, 3, err
) ;