1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2014 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. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #ifndef HAVE_AMALGAMATION
45 * Print the current active headings.
46 * Don't change dot if invoker didn't give an argument.
51 /* Prepare and print "[Message: xy]:" intro */
52 static void _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
);
54 /* ... And place the extracted date in `date' */
55 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
57 /* Print out the header of a specific message
58 * __hprf: handle *headline*
59 * __subject: Subject:, but return NULL if threaded and Subject: yet seen
60 * __putindent: print out the indenting in threaded display */
61 static void _print_head(size_t yetprinted
, int msgno
, FILE *f
,
63 static void __hprf(size_t yetprinted
, const char *fmt
, int mesg
, FILE *f
,
64 bool_t threaded
, const char *attrlist
);
65 static char * __subject(struct message
*mp
, bool_t threaded
,
67 static char * __subject_trim(char *s
);
68 static int __putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
70 static void _cmd1_onpipe(int signo
);
71 static int _dispc(struct message
*mp
, const char *a
);
72 static int scroll1(char *arg
, int onlynew
);
74 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
75 bool_t dodecode
, char *cmd
, off_t
*tstats
);
76 static int pipe1(char *str
, int doign
);
79 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
81 char const *cpre
= "", *csuf
= "";
84 if (colour_table
!= NULL
) {
87 if ((sp
= colour_get(COLOURSPEC_MSGINFO
)) != NULL
)
89 csuf
= colour_get(COLOURSPEC_RESET
)->s
;
93 "%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
94 cpre
, msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
, csuf
);
98 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
])
105 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
106 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
107 (void)extract_date_from_from_(hline
, hlen
, date
);
113 _print_head(size_t yetprinted
, int msgno
, FILE *f
, bool_t threaded
)
115 char attrlist
[30], *cp
;
118 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
119 size_t i
= strlen(cp
);
120 if (UICMP(32, i
, >, sizeof attrlist
- 1))
121 i
= (int)sizeof attrlist
- 1;
122 memcpy(attrlist
, cp
, i
);
123 } else if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) ||
124 getenv("SYSV3") != NULL
) {
125 char const bsdattr
[] = "NU *HMFAT+-$";
126 memcpy(attrlist
, bsdattr
, sizeof bsdattr
- 1);
128 char const pattr
[] = "NUROSPMFAT+-$";
129 memcpy(attrlist
, pattr
, sizeof pattr
- 1);
132 if ((fmt
= ok_vlook(headline
)) == NULL
) {
133 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
134 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
135 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
138 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
142 __hprf(size_t yetprinted
, char const *fmt
, int msgno
, FILE *f
, bool_t threaded
,
143 char const *attrlist
)
145 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
146 char const *datefmt
, *date
, *name
, *fp
;
147 int B
, c
, i
, n
, s
, wleft
, subjlen
, isto
= 0, isaddr
= 0;
151 mp
= &message
[msgno
- 1];
155 datefmt
= ok_vlook(datefield
);
157 if (datefmt
!= NULL
) {
158 fp
= hfield1("date", mp
);/* TODO use m_date field! */
164 date
= fakedate(datet
);
165 fp
= ok_vlook(datefield_markout_older
);
166 i
= (*datefmt
!= '\0');
168 i
|= (*fp
!= '\0') ? 2 | 4 : 2;
169 /* May we strftime(3)? */
171 memcpy(&time_current
.tc_local
, localtime(&datet
),
172 sizeof time_current
.tc_local
);
174 /* TODO *datefield-markout-older* we accept
175 * TODO one day in the future, should be UTC
176 * TODO offset only? and Stephen Isard had
177 * TODO one week once he proposed the patch! */
178 (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
179 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
180 (datet
+ _6M
< time_current
.tc_time
))) {
182 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
183 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
184 memcpy(datebuf
+ 4, date
+ 4, 7);
185 datebuf
[4 + 7] = ' ';
186 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
187 datebuf
[4 + 7 + 1 + 4] = '\0';
190 } else if ((i
& 1) == 0)
192 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
193 /* TODO eliminate this path, query the FROM_ date in setptr(),
194 * TODO all other codepaths do so by themselves ALREADY ?????
195 * TODO assert(mp->m_time != 0);, then
196 * TODO ALSO changes behaviour of markout-non-current */
197 _parse_from_(mp
, datebuf
);
200 date
= fakedate(datet
);
204 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
205 if ((cp
= hfield1("to", mp
)) != NULL
) {
215 if (ok_blook(showname
))
216 name
= realname(name
);
218 name
= prstr(skin(name
));
224 /* Detect the width of the non-format characters in *headline*;
225 * like that we can simply use putc() in the next loop, since we have
226 * already calculated their column widths (TODO it's sick) */
230 for (fp
= fmt
; *fp
; ++fp
) {
234 } else if (*fp
== '+')
236 if (digitchar(*fp
)) {
239 n
= 10*n
+ *fp
- '0';
240 while (++fp
, digitchar(*fp
));
248 if (mb_cur_max
> 1) {
250 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) < 0)
252 else if ((n
= wcwidth(wc
)) < 0)
264 /* Walk *headline*, producing output */
265 for (fp
= fmt
; *fp
; ++fp
) {
266 if ((c
= *fp
& 0xFF) == '%') {
273 } else if (*fp
== '+')
275 if (digitchar(*fp
)) {
277 n
= 10*n
+ *fp
- '0';
278 while (++fp
, digitchar(*fp
));
284 switch ((c
= *fp
& 0xFF)) {
293 c
= _dispc(mp
, attrlist
);
295 if (UICMP(32, ABS(n
), >, wleft
))
296 n
= (n
< 0) ? -wleft
: wleft
;
297 n
= fprintf(f
, "%*c", n
, c
);
298 wleft
= (n
>= 0) ? wleft
- n
: 0;
304 for (i
=msgCount
; i
>999; i
/=10)
307 if (UICMP(32, ABS(n
), >, wleft
))
308 n
= (n
< 0) ? -wleft
: wleft
;
309 n
= fprintf(f
, "%*d", n
, msgno
);
310 wleft
= (n
>= 0) ? wleft
- n
: 0;
321 n
= (n
< 0) ? -wleft
: wleft
;
323 if (isto
) /* XXX tr()! */
325 n
= fprintf(f
, "%s%s", (isto
? "To " : ""),
326 colalign(name
, i
, n
, &wleft
));
333 if (datefmt
!= NULL
) {
334 i
= strftime(datebuf
, sizeof datebuf
,
336 &time_current
.tc_local
);
340 fprintf(stderr
, tr(174,
341 "Ignored date format, "
345 (ul_it
)sizeof datebuf
);
350 if (UICMP(32, ABS(n
), >, wleft
))
351 n
= (n
< 0) ? -wleft
: wleft
;
352 n
= fprintf(f
, "%*.*s", n
, n
, date
);
353 wleft
= (n
>= 0) ? wleft
- n
: 0;
358 if (UICMP(32, ABS(n
), >, wleft
))
359 n
= (n
< 0) ? -wleft
: wleft
;
361 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
362 wleft
= (n
>= 0) ? wleft
- n
: 0;
373 if (UICMP(32, ABS(n
), >, wleft
))
374 n
= (n
< 0) ? -wleft
: wleft
;
375 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
376 wleft
= (n
>= 0) ? wleft
- n
: 0;
380 n
= __putindent(f
, mp
, MIN(wleft
,
382 wleft
= (n
>= 0) ? wleft
- n
: 0;
395 if (UICMP(32, ABS(n
), >, subjlen
))
396 n
= (n
< 0) ? -subjlen
: subjlen
;
398 n
-= (n
< 0) ? -2 : 2;
401 if (subjline
== NULL
)
402 subjline
= __subject(mp
, threaded
,
404 if (subjline
== (char*)-1) {
405 n
= fprintf(f
, "%*s", n
, "");
406 wleft
= (n
>= 0) ? wleft
-n
: 0;
408 n
= fprintf(f
, (B
? "\"%s\"" : "%s"),
409 colalign(subjline
, ABS(n
), n
,
419 if (UICMP(32, ABS(n
), >, wleft
))
420 n
= (n
< 0) ? -wleft
: wleft
;
421 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
422 wleft
= (n
>= 0) ? wleft
- n
: 0;
431 if (UICMP(32, ABS(n
), >, wleft
))
432 n
= (n
< 0) ? -wleft
: wleft
;
433 n
= fprintf(f
, "%*u", n
,
434 threaded
== 1 ? mp
->m_level
: 0);
435 wleft
= (n
>= 0) ? wleft
- n
: 0;
441 for (i
=msgCount
; i
>999; i
/=10)
444 if (UICMP(32, ABS(n
), >, wleft
))
445 n
= (n
< 0) ? -wleft
: wleft
;
446 n
= fprintf(f
, "%*ld", n
,
447 threaded
? mp
->m_threadpos
: msgno
);
448 wleft
= (n
>= 0) ? wleft
- n
: 0;
454 if (UICMP(32, ABS(n
), >, wleft
))
455 n
= (n
< 0) ? -wleft
: wleft
;
457 snprintf(buf
, sizeof buf
, "%u.%u",
458 (mp
->m_spamscore
>> 8),
459 (mp
->m_spamscore
& 0xFF));
460 n
= fprintf(f
, "%*s", n
, buf
);
461 wleft
= (n
>= 0) ? wleft
- n
: 0;
476 if (subjline
!= NULL
&& subjline
!= (char*)-1)
481 __subject_trim(char *s
)
486 } const *pp
, ignored
[] = { /* TODO make ignore list configurable */
487 { 3, "re:" }, { 4, "fwd:" },
488 { 3, "aw:" }, { 5, "antw:" },
493 while (spacechar(*s
))
495 /* TODO While it is maybe ok not to MIME decode these, we
496 * TODO should skip =?..?= at the beginning? */
497 for (pp
= ignored
; pp
->len
> 0; ++pp
)
498 if (is_asccaseprefix(pp
->dat
, s
)) {
508 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
510 /* XXX NOTE: because of efficiency reasons we simply ignore any encoded
511 * XXX parts and use ASCII case-insensitive comparison */
514 char *rv
= (char*)-1, *ms
, *mso
, *os
;
516 if ((ms
= hfield1("subject", mp
)) == NULL
)
519 if (!threaded
|| mp
->m_level
== 0)
522 /* In a display thread - check wether this message uses the same
523 * Subject: as it's parent or elder neighbour, suppress printing it if
524 * this is the case. To extend this a bit, ignore any leading Re: or
525 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
526 mso
= __subject_trim(ms
);
527 for (xmp
= mp
; (xmp
= prev_in_thread(xmp
)) != NULL
&& yetprinted
-- > 0;)
528 if (visible(xmp
) && (os
= hfield1("subject", xmp
)) != NULL
&&
529 asccasecmp(mso
, __subject_trim(os
)) == 0)
534 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
541 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
544 int *us
, indlvl
, indw
, i
, important
= MNEW
|MFLAGGED
;
547 if (mp
->m_level
== 0 || maxwidth
== 0)
549 cs
= ac_alloc(mp
->m_level
);
550 us
= ac_alloc(mp
->m_level
* sizeof *us
);
553 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
554 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
555 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
557 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
560 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
561 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
563 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
568 for (i
= mp
->m_level
- 2; i
>= 0; i
--) {
570 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
576 mq
->m_parent
->m_flag
&important
)
589 for (indlvl
= indw
= 0; (uc_it
)indlvl
< mp
->m_level
&&
590 indw
< maxwidth
; ++indlvl
) {
591 if (indw
< maxwidth
- 1)
592 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0377, fp
);
594 indw
+= (int)putuc(0x21B8, '^', fp
);
596 indw
+= /*putuc(0x261E, fp)*/putc('>', fp
) != EOF
;
604 ccmdnotsupp(void *v
) /* TODO -> lex.c */
607 fprintf(stderr
, tr(10, "The requested feature is not compiled in\n"));
615 int *msgvec
= v
, g
, k
, n
, mesg
, size
, lastg
= 1;
616 struct message
*mp
, *mq
, *lastmq
= NULL
;
617 enum mflag fl
= MNEW
|MFLAGGED
;
619 time_current_update(&time_current
, FAL0
);
623 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
632 if (mb
.mb_threaded
== 0) {
635 for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
643 if ((n
> 0 && mp
== &message
[n
-1]) ||
644 (n
== 0 && g
== k
) ||
645 (n
== -2 && g
== k
+ size
&&
648 (mp
->m_flag
& fl
) != 0))
652 if (lastmq
&& (n
==-2 || (n
==-1 && mp
== &message
[msgCount
]))) {
658 mesg
= mp
- &message
[0];
659 if (dot
!= &message
[n
-1]) {
660 for (mq
= mp
; mq
< &message
[msgCount
]; mq
++)
667 if (mb
.mb_type
== MB_IMAP
)
668 imap_getheaders(mesg
+1, mesg
+ size
);
671 for (; mp
< &message
[msgCount
]; mp
++) {
675 if (UICMP(32, flag
++, >=, size
))
677 _print_head(0, mesg
, stdout
, 0);
681 } else { /* threaded */
684 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
685 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
686 mp
== &message
[n
-1])) {
693 if ((n
> 0 && mp
== &message
[n
-1]) ||
694 (n
== 0 && g
== k
) ||
695 (n
== -2 && g
== k
+ size
&&
698 (mp
->m_flag
& fl
) != 0))
702 if (lastmq
&& (n
==-2 || (n
==-1 && mp
==&message
[msgCount
]))) {
708 if (dot
!= &message
[n
-1]) {
709 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
710 if (visible(mq
) && mq
->m_collapsed
<= 0) {
717 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
718 mp
== &message
[n
-1])) {
719 if (UICMP(32, flag
++, >=, size
))
721 _print_head(flag
- 1, mp
- &message
[0] + 1,
722 stdout
, mb
.mb_threaded
);
725 mp
= next_in_thread(mp
);
730 printf(tr(6, "No more mail.\n"));
735 * Scroll to the next/previous screen
740 return scroll1(v
, 0);
746 return scroll1(v
, 1);
750 scroll1(char *arg
, int onlynew
)
755 cur
[0] = onlynew
? -1 : 0;
758 case '1': case '2': case '3': case '4': case '5':
759 case '6': case '7': case '8': case '9': case '0':
766 screen
= msgCount
/ size
;
772 screen
+= atoi(arg
+ 1);
774 if (screen
* size
> msgCount
) {
775 screen
= msgCount
/ size
;
776 printf(tr(7, "On last screenful of messages\n"));
784 screen
-= atoi(arg
+ 1);
787 printf(tr(8, "On first screenful of messages\n"));
794 printf(tr(9, "Unrecognized scrolling command \"%s\"\n"), arg
);
797 return(headers(cur
));
801 * Compute screen size.
809 if ((cp
= ok_vlook(screen
)) != NULL
&& (s
= atoi(cp
)) > 0)
811 return scrnheight
- 4;
814 static sigjmp_buf _cmd1_pipejmp
;
818 _cmd1_onpipe(int signo
)
821 siglongjmp(_cmd1_pipejmp
, 1);
825 * Print out the headlines for each message
826 * in the passed message list.
831 int *msgvec
= v
, *ip
, n
;
833 FILE *volatile obuf
= stdout
;
835 time_current_update(&time_current
, FAL0
);
837 /* TODO unfixable memory leaks still */
838 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
839 for (n
= 0, ip
= msgvec
; *ip
; ip
++)
841 if (n
> (*cp
== '\0' ? screensize() : atoi((char*)cp
)) + 3) {
843 if (sigsetjmp(_cmd1_pipejmp
, 1))
846 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
851 safe_signal(SIGPIPE
, _cmd1_onpipe
);
854 for (n
= 0, ip
= msgvec
; *ip
!= 0; ip
++)
855 _print_head((size_t)n
++, *ip
, obuf
, mb
.mb_threaded
);
857 setdot(&message
[*ip
- 1]);
859 if (obuf
!= stdout
) {
860 safe_signal(SIGPIPE
, SIG_IGN
);
862 safe_signal(SIGPIPE
, dflpipe
);
868 _dispc(struct message
*mp
, const char *a
)
875 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MREAD
)
877 if ((mp
->m_flag
& (MREAD
|MNEW
)) == (MREAD
|MNEW
))
879 if (mp
->m_flag
& MANSWERED
)
881 if (mp
->m_flag
& MDRAFTED
)
883 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
885 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
887 if (mp
->m_flag
& MSPAM
)
889 if (mp
->m_flag
& MSAVED
)
891 if (mp
->m_flag
& MPRESERVE
)
893 if (mp
->m_flag
& (MBOX
|MBOXED
))
895 if (mp
->m_flag
& MFLAGGED
)
897 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
899 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
905 print_headers(size_t bottom
, size_t topx
)
910 if (mb
.mb_type
== MB_IMAP
)
911 imap_getheaders(bottom
, topx
);
913 time_current_update(&time_current
, FAL0
);
915 for (printed
= 0; bottom
<= topx
; ++bottom
)
916 if (visible(&message
[bottom
- 1]))
917 _print_head(printed
++, bottom
, stdout
, 0);
921 * Print out the value of dot.
928 printf("%d\n", (int)(dot
- &message
[0] + 1));
933 * Type out the messages requested.
935 static sigjmp_buf pipestop
;
942 siglongjmp(pipestop
, 1);
946 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
947 bool_t dodecode
, char *cmd
, off_t
*tstats
)
949 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
950 ? SEND_MBOX
: dodecode
952 ? SEND_TODISP
: SEND_TODISP_ALL
);
953 bool_t
const formfeed
= (dopipe
&& ok_blook(page
));
958 FILE * volatile obuf
;
961 if (sigsetjmp(pipestop
, 1))
964 if ((cp
= ok_vlook(SHELL
)) == NULL
)
966 if ((obuf
= Popen(cmd
, "w", cp
, 1)) == NULL
) {
970 safe_signal(SIGPIPE
, brokpipe
);
971 } else if ((options
& OPT_TTYOUT
) &&
972 (dopage
|| (cp
= ok_vlook(crt
)) != NULL
)) {
973 char const *pager
= NULL
;
976 for (ip
= msgvec
; *ip
&&
977 PTRCMP(ip
- msgvec
, <, msgCount
);
979 if (!(message
[*ip
- 1].m_have
& HAVE_BODY
)) {
980 if ((get_body(&message
[*ip
- 1])) !=
984 nlines
+= message
[*ip
- 1].m_lines
;
987 if (dopage
|| UICMP(z
, nlines
, >,
988 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
991 if ((cp
= getenv("LESS")) == NULL
) /* XXX not here! */
992 setenv("LESS", "FRXi", 0); /* XXX add env. */
994 obuf
= Popen(pager
, "w", NULL
, 1);
997 unsetenv("LESS"); /* XXX to Popen() etc.?!! */
1004 safe_signal(SIGPIPE
, brokpipe
);
1007 if (action
!= SEND_MBOX
)
1008 colour_table_create(pager
); /* (salloc()s!) */
1012 else if ((options
& OPT_TTYOUT
) && action
!= SEND_MBOX
)
1013 colour_table_create(NULL
); /* (salloc()s!) */
1016 /* This may jump, in which case srelax_rele() wouldn't be called, but
1017 * it shouldn't matter, because we -- then -- directly reenter the
1018 * lex.c:commands() loop, which sreset()s */
1020 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
1021 mp
= &message
[*ip
- 1];
1027 fprintf(obuf
, "\n");
1028 if (action
!= SEND_MBOX
)
1029 _show_msg_overview(obuf
, mp
, *ip
);
1031 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
1036 tstats
[0] += mstats
[0];
1037 tstats
[1] += mstats
[1];
1042 if (obuf
!= stdout
) {
1043 /* Ignore SIGPIPE so it can't cause a duplicate close */
1044 safe_signal(SIGPIPE
, SIG_IGN
);
1045 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
1047 safe_signal(SIGPIPE
, dflpipe
);
1053 * Pipe the messages requested.
1056 pipe1(char *str
, int doign
)
1064 msgvec
= (int *)salloc((msgCount
+ 2) * sizeof *msgvec
);
1065 if ((cmd
= laststring(str
, &f
, 1)) == NULL
) {
1066 cmd
= ok_vlook(cmd
);
1067 if (cmd
== NULL
|| *cmd
== '\0') {
1068 fputs(tr(16, "variable cmd not set\n"), stderr
);
1073 *msgvec
= first(0, MMNORM
);
1077 puts(tr(18, "No messages to pipe."));
1081 } else if (getmsglist(str
, msgvec
, 0) < 0)
1086 printf("No applicable messages.\n");
1089 printf(tr(268, "Pipe to: \"%s\"\n"), cmd
);
1090 stats
[0] = stats
[1] = 0;
1091 if ((ret
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
1092 printf("\"%s\" ", cmd
);
1094 printf("%lu", (long)stats
[0]);
1096 printf(tr(27, "binary"));
1097 printf("/%lu\n", (long)stats
[1]);
1103 * Paginate messages, honor ignored fields.
1110 return _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1114 * Paginate messages, even printing ignored fields.
1121 return _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1125 * Type out messages, honor ignored fields.
1132 return _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1136 * Type out messages, even printing ignored fields.
1143 return _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1147 * Show MIME-encoded message text, including all fields.
1154 return _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1158 * Pipe messages, honor ignored fields.
1164 return(pipe1(str
, 1));
1167 * Pipe messages, not respecting ignored fields.
1173 return(pipe1(str
, 0));
1177 * Print the top so many lines of each desired message.
1178 * The number of lines is taken from the variable "toplines"
1179 * and defaults to 5.
1184 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1186 char *cp
, *linebuf
= NULL
;
1187 size_t linesize
= 0;
1191 cp
= ok_vlook(toplines
);
1194 if (topl
< 0 || topl
> 10000)
1199 if (options
& OPT_TTYOUT
)
1200 colour_table_create(NULL
); /* (salloc()s) */
1203 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
1204 mp
= &message
[*ip
- 1];
1207 did_print_dot
= TRU1
;
1210 _show_msg_overview(stdout
, mp
, *ip
);
1211 if (mp
->m_flag
& MNOFROM
)
1212 /* XXX top(): coloured output? */
1213 printf("From %s %s\n", fakefrom(mp
),
1214 fakedate(mp
->m_time
));
1215 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1220 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
);
1222 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1226 for (cp
= linebuf
; *cp
&& blankchar(*cp
); ++cp
)
1228 empty_last
= (*cp
== '\0');
1232 if (linebuf
!= NULL
)
1238 * Touch all the given messages so that they will
1247 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1248 setdot(&message
[*ip
-1]);
1249 dot
->m_flag
|= MTOUCH
;
1250 dot
->m_flag
&= ~MPRESERVE
;
1252 * POSIX interpretation necessary.
1254 did_print_dot
= TRU1
;
1260 * Make sure all passed messages get mboxed.
1268 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1269 setdot(&message
[*ip
-1]);
1270 dot
->m_flag
|= MTOUCH
|MBOX
;
1271 dot
->m_flag
&= ~MPRESERVE
;
1273 * POSIX interpretation necessary.
1275 did_print_dot
= TRU1
;
1281 * List the folders the user currently has.
1286 char dirname
[MAXPATHLEN
], *name
, **argv
= v
;
1290 name
= expand(*argv
);
1293 } else if (! getfold(dirname
, sizeof dirname
)) {
1294 fprintf(stderr
, tr(20, "No value set for \"folder\"\n"));
1299 if (which_protocol(name
) == PROTO_IMAP
) {
1301 imap_folders(name
, *argv
== NULL
);
1303 return ccmdnotsupp(NULL
);
1306 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1308 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);