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 University of Washington
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* ========================================================================
18
#include "../pith/headers.h"
19
#include "../pith/pipe.h"
20
#include "../pith/stream.h"
21
#include "../pith/status.h"
28
* Support structure and functions to support piping raw message texts...
30
static struct raw_pipe_data {
32
unsigned long msgno, len;
33
long char_limit, flags;
39
raw_pipe_getc(unsigned char *c)
41
static char *free_this = NULL;
44
* What is this if doing?
46
* If((just_starting && unsuccessful_fetch_header)
47
* || (no_chars_available && haven't_fetched_body
48
* && (not_supposed_to_fetch
49
* || (supposed_to_fetch_all && unsuccessful_fetch_text)
50
* || (supposed_to_partial_fetch && unsuccessful_partial_fetch))
51
* || (no_chars_available))
54
* otherwise, fall through and return next character
57
&& !(raw_pipe.cur = mail_fetch_header(raw_pipe.stream, raw_pipe.msgno,
61
|| ((raw_pipe.len <= 0L) && !raw_pipe.body
62
&& (raw_pipe.char_limit == 0L
63
|| (raw_pipe.char_limit < 0L
64
&& !(raw_pipe.cur = raw_pipe.body =
65
pine_mail_fetch_text(raw_pipe.stream,
70
|| (raw_pipe.char_limit > 0L
71
&& !(raw_pipe.cur = raw_pipe.body =
72
pine_mail_partial_fetch_wrapper(raw_pipe.stream,
77
(unsigned long) raw_pipe.char_limit,
79
|| (raw_pipe.len <= 0L)){
82
fs_give((void **) &free_this);
87
if(raw_pipe.char_limit > 0L
89
&& raw_pipe.len > raw_pipe.char_limit)
90
raw_pipe.len = raw_pipe.char_limit;
92
if(raw_pipe.len > 0L){
93
*c = (unsigned char) *raw_pipe.cur++;
104
* Set up for using raw_pipe_getc
108
* char_limit Set to -1 means whole thing
109
* 0 means headers only
110
* > 0 means headers plus char_limit body chars
111
* flags -- passed to fetch functions
114
prime_raw_pipe_getc(MAILSTREAM *stream, long int msgno, long int char_limit, long int flags)
116
raw_pipe.stream = stream;
117
raw_pipe.msgno = (unsigned long) msgno;
118
raw_pipe.char_limit = char_limit;
120
raw_pipe.flags = flags;
122
raw_pipe.body = NULL;
126
/*----------------------------------------------------------------------
127
Actually open the pipe used to write piped data down
130
Returns: TRUE if success, otherwise FALSE
134
cmd_pipe_open(char *cmd, char **result, int flags, gf_io_t *pc)
139
if(pipe = open_system_pipe(cmd, result, NULL, flags, 0,
140
pipe_callback, pipe_report_error))
141
gf_set_writec(pc, pipe, 0L, PipeStar, WRITE_TO_LOCALE);
143
/* TRANSLATORS: The argument is the command name being piped to. */
144
snprintf(err, sizeof(err), _("Error opening pipe: %s"), cmd ? cmd : "?");
145
q_status_message(SM_ORDER | SM_DING, 3, 3, err) ;