1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Message, message array, and related operations.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #define n_FILE message
38 #ifndef HAVE_AMALGAMATION
42 /* Slots in ::message */
43 static size_t _message_space
;
45 static enum okay
get_header(struct message
*mp
);
48 get_header(struct message
*mp
)
74 setinput(struct mailbox
*mp
, struct message
*m
, enum needspec need
)
82 ok
= (m
->m_have
& HAVE_HEADER
) ? OKAY
: get_header(m
);
85 ok
= (m
->m_have
& HAVE_BODY
) ? OKAY
: get_body(m
);
95 if (fseek(mp
->mb_itf
, (long)mailx_positionof(m
->m_block
, m
->m_offset
),
97 n_perr(_("fseek"), 0);
98 n_panic(_("temporary file seek"));
107 get_body(struct message
*mp
)
113 switch (mb
.mb_type
) {
136 if (message
!= NULL
) {
146 message_append(struct message
*mp
)
149 if (UICMP(z
, msgCount
+ 1, >=, _message_space
)) {
150 /* XXX remove _message_space magics (or use s_Vector) */
151 _message_space
= (_message_space
>= 128 && _message_space
<= 1000000)
152 ? _message_space
<< 1 : _message_space
+ 64;
153 message
= srealloc(message
, _message_space
* sizeof *message
);
157 message
[msgCount
- 1] = *mp
;
159 memset(message
+ msgCount
- 1, 0, sizeof *message
);
165 message_append_null(void)
169 message_append(NULL
);
171 message
[msgCount
].m_size
= 0;
172 message
[msgCount
].m_lines
= 0;
177 message_match(struct message
*mp
, struct search_expr
const *sep
,
181 size_t *linesize
, cnt
;
186 if ((fp
= Ftmp(NULL
, "mpmatch", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) == NULL
)
189 if (sendmp(mp
, fp
, NULL
, NULL
, SEND_TOSRCH
, NULL
) < 0)
194 line
= &termios_state
.ts_linebuf
; /* XXX line pool */
195 linesize
= &termios_state
.ts_linesize
; /* XXX line pool */
198 while (fgetline(line
, linesize
, &cnt
, NULL
, fp
, 0))
202 while (fgetline(line
, linesize
, &cnt
, NULL
, fp
, 0)) {
204 if (sep
->ss_sexpr
== NULL
) {
205 if (regexec(&sep
->ss_regex
, *line
, 0,NULL
, 0) == REG_NOMATCH
)
209 if (!substr(*line
, sep
->ss_sexpr
))
223 setdot(struct message
*mp
)
228 pstate
&= ~PS_DID_PRINT_DOT
;
237 touch(struct message
*mp
)
240 mp
->m_flag
|= MTOUCH
;
241 if (!(mp
->m_flag
& MREAD
))
242 mp
->m_flag
|= MREAD
| MSTATUS
;