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 static sigjmp_buf _cmd1_pipestop
;
46 static sigjmp_buf _cmd1_pipejmp
;
48 static void _cmd1_onpipe(int signo
);
49 static void _cmd1_brokpipe(int signo
);
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
, size_t msgno
, FILE *f
,
63 static void __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
,
64 FILE *f
, bool_t threaded
, char const *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 int _dispc(struct message
*mp
, char const *a
);
71 static int _scroll1(char *arg
, int onlynew
);
73 /* Show the requested messages */
74 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
75 bool_t dodecode
, char *cmd
, off_t
*tstats
);
77 /* Pipe the requested messages */
78 static int _pipe1(char *str
, int doign
);
81 _cmd1_onpipe(int signo
)
83 NYD_X
; /* Signal handler */
85 siglongjmp(_cmd1_pipejmp
, 1);
89 _cmd1_brokpipe(int signo
)
91 NYD_X
; /* Signal handler */
93 siglongjmp(_cmd1_pipestop
, 1);
97 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
99 char const *cpre
= "", *csuf
= "";
103 if (colour_table
!= NULL
) {
104 struct str
const *sp
;
106 if ((sp
= colour_get(COLOURSPEC_MSGINFO
)) != NULL
)
108 csuf
= colour_get(COLOURSPEC_RESET
)->s
;
111 fprintf(obuf
, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
112 cpre
, msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
, csuf
);
117 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]) /* TODO line pool */
125 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
126 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
127 extract_date_from_from_(hline
, hlen
, date
);
134 _print_head(size_t yetprinted
, size_t msgno
, FILE *f
, bool_t threaded
)
137 char attrlist
[attrlen
+1], *cp
;
141 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
142 if (strlen(cp
) == attrlen
) {
143 memcpy(attrlist
, cp
, attrlen
+1);
147 "The value of *attrlist* is not of the correct length\n"));
149 if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) ||
150 getenv("SYSV3") != NULL
) {
151 char const bsdattr
[attrlen
+1] = "NU *HMFAT+-$";
152 memcpy(attrlist
, bsdattr
, sizeof bsdattr
);
154 char const pattr
[attrlen
+1] = "NUROSPMFAT+-$";
155 memcpy(attrlist
, pattr
, sizeof pattr
);
158 if ((fmt
= ok_vlook(headline
)) == NULL
) {
159 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
160 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
161 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
164 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
169 __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
, FILE *f
,
170 bool_t threaded
, char const *attrlist
)
172 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
173 char const *datefmt
, *date
, *name
, *fp
;
174 int i
, n
, s
, wleft
, subjlen
;
182 _LOOP_MASK
= (1<<3) - 1,
187 mp
= message
+ msgno
- 1;
191 datefmt
= ok_vlook(datefield
);
193 if (datefmt
!= NULL
) {
194 fp
= hfield1("date", mp
);/* TODO use m_date field! */
200 date
= fakedate(datet
);
201 fp
= ok_vlook(datefield_markout_older
);
202 i
= (*datefmt
!= '\0');
204 i
|= (*fp
!= '\0') ? 2 | 4 : 2; /* XXX no magics */
206 /* May we strftime(3)? */
208 memcpy(&time_current
.tc_local
, localtime(&datet
),
209 sizeof time_current
.tc_local
);
211 if ((i
& 2) && (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
212 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
213 (datet
+ _6M
< time_current
.tc_time
))) {
215 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
216 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
217 memcpy(datebuf
+ 4, date
+ 4, 7);
218 datebuf
[4 + 7] = ' ';
219 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
220 datebuf
[4 + 7 + 1 + 4] = '\0';
223 } else if ((i
& 1) == 0)
225 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
226 /* TODO eliminate this path, query the FROM_ date in setptr(),
227 * TODO all other codepaths do so by themselves ALREADY ?????
228 * TODO assert(mp->m_time != 0);, then
229 * TODO ALSO changes behaviour of datefield_markout_older */
230 _parse_from_(mp
, datebuf
);
233 date
= fakedate(datet
);
237 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
238 if ((cp
= hfield1("to", mp
)) != NULL
) {
248 name
= ok_blook(showname
) ? realname(name
) : prstr(skin(name
));
252 /* Detect the width of the non-format characters in *headline*;
253 * like that we can simply use putc() in the next loop, since we have
254 * already calculated their column widths (TODO it's sick) */
255 wleft
= subjlen
= scrnwidth
;
257 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
263 if (digitchar(*fp
)) {
266 n
= 10*n
+ *fp
- '0';
267 while (++fp
, digitchar(*fp
));
277 if (mb_cur_max
> 1) {
279 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) == -1)
281 else if ((n
= wcwidth(wc
)) == -1)
293 /* Walk *headline*, producing output TODO not (really) MB safe */
294 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
296 if ((c
= *fp
& 0xFF) != '%')
305 } else if (*fp
== '+')
307 if (digitchar(*fp
)) {
309 n
= 10*n
+ *fp
- '0';
310 while (++fp
, digitchar(*fp
));
316 switch ((c
= *fp
& 0xFF)) {
328 if (UICMP(32, ABS(n
), >, wleft
))
329 n
= (n
< 0) ? -wleft
: wleft
;
331 snprintf(buf
, sizeof buf
, "%u.%u",
332 (mp
->m_spamscore
>> 8), (mp
->m_spamscore
& 0xFF));
333 n
= fprintf(f
, "%*s", n
, buf
);
334 wleft
= (n
>= 0) ? wleft
- n
: 0;
341 c
= _dispc(mp
, attrlist
);
343 if (UICMP(32, ABS(n
), >, wleft
))
344 n
= (n
< 0) ? -wleft
: wleft
;
345 n
= fprintf(f
, "%*c", n
, c
);
346 wleft
= (n
>= 0) ? wleft
- n
: 0;
349 if (datefmt
!= NULL
) {
350 i
= strftime(datebuf
, sizeof datebuf
, datefmt
,
351 &time_current
.tc_local
);
356 "Ignored date format, it excesses the target buffer "
357 "(%lu bytes)\n"), (ul_it
)sizeof datebuf
);
362 if (UICMP(32, ABS(n
), >, wleft
))
363 n
= (n
< 0) ? -wleft
: wleft
;
364 n
= fprintf(f
, "%*.*s", n
, n
, date
);
365 wleft
= (n
>= 0) ? wleft
- n
: 0;
370 if (UICMP(32, ABS(n
), >, wleft
))
371 n
= (n
< 0) ? -wleft
: wleft
;
372 n
= fprintf(f
, "%*u", n
, (threaded
== 1 ? mp
->m_level
: 0));
373 wleft
= (n
>= 0) ? wleft
- n
: 0;
384 n
= (n
< 0) ? -wleft
: wleft
;
386 if (flags
& _ISTO
) /* XXX tr()! */
388 n
= fprintf(f
, "%s%s", ((flags
& _ISTO
) ? "To " : ""),
389 colalign(name
, i
, n
, &wleft
));
392 else if (flags
& _ISTO
)
397 n
= __putindent(f
, mp
, MIN(wleft
, scrnwidth
- 60));
398 wleft
= (n
>= 0) ? wleft
- n
: 0;
404 if (UICMP(32, ABS(n
), >, wleft
))
405 n
= (n
< 0) ? -wleft
: wleft
;
407 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
408 wleft
= (n
>= 0) ? wleft
- n
: 0;
420 for (i
= msgCount
; i
> 999; i
/= 10)
423 if (UICMP(32, ABS(n
), >, wleft
))
424 n
= (n
< 0) ? -wleft
: wleft
;
425 n
= fprintf(f
, "%*lu", n
, (ul_it
)msgno
);
426 wleft
= (n
>= 0) ? wleft
- n
: 0;
431 if (UICMP(32, ABS(n
), >, wleft
))
432 n
= (n
< 0) ? -wleft
: wleft
;
433 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
434 wleft
= (n
>= 0) ? wleft
- n
: 0;
446 if (UICMP(32, ABS(n
), >, subjlen
))
447 n
= (n
< 0) ? -subjlen
: subjlen
;
449 n
-= (n
< 0) ? -2 : 2;
452 if (subjline
== NULL
)
453 subjline
= __subject(mp
, (threaded
&& (flags
& _IFMT
)),
455 if (subjline
== (char*)-1) {
456 n
= fprintf(f
, "%*s", n
, "");
457 wleft
= (n
>= 0) ? wleft
- n
: 0;
459 n
= fprintf(f
, ((flags
& _SFMT
) ? "\"%s\"" : "%s"),
460 colalign(subjline
, ABS(n
), n
, &wleft
));
469 for (i
= msgCount
; i
> 999; i
/= 10)
472 if (UICMP(32, ABS(n
), >, wleft
))
473 n
= (n
< 0) ? -wleft
: wleft
;
474 n
= fprintf(f
, "%*lu", n
,
475 (threaded
? (ul_it
)mp
->m_threadpos
: (ul_it
)msgno
));
476 wleft
= (n
>= 0) ? wleft
- n
: 0;
482 if (UICMP(32, ABS(n
), >, wleft
))
483 n
= (n
< 0) ? -wleft
: wleft
;
484 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
485 wleft
= (n
>= 0) ? wleft
- n
: 0;
499 if (subjline
!= NULL
&& subjline
!= (char*)-1)
505 __subject_trim(char *s
)
510 } const *pp
, ignored
[] = { /* TODO make ignore list configurable */
511 { 3, "re:" }, { 4, "fwd:" },
512 { 3, "aw:" }, { 5, "antw:" },
519 while (spacechar(*s
))
521 /* TODO While it is maybe ok not to MIME decode these (for purpose), we
522 * TODO should skip =?..?= at the beginning? */
523 for (pp
= ignored
; pp
->len
> 0; ++pp
)
524 if (is_asccaseprefix(pp
->dat
, s
)) {
535 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
537 /* XXX NOTE: because of efficiency reasons we simply ignore any encoded
538 * XXX parts and use ASCII case-insensitive comparison */
541 char *rv
= (char*)-1, *ms
, *mso
, *os
;
544 if ((ms
= hfield1("subject", mp
)) == NULL
)
547 if (!threaded
|| mp
->m_level
== 0)
550 /* In a display thread - check wether this message uses the same
551 * Subject: as it's parent or elder neighbour, suppress printing it if
552 * this is the case. To extend this a bit, ignore any leading Re: or
553 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
554 mso
= __subject_trim(ms
);
555 for (xmp
= mp
; (xmp
= prev_in_thread(xmp
)) != NULL
&& yetprinted
-- > 0;)
556 if (visible(xmp
) && (os
= hfield1("subject", xmp
)) != NULL
&&
557 !asccasecmp(mso
, __subject_trim(os
)))
562 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
570 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
573 int *us
, indlvl
, indw
, i
, important
= MNEW
| MFLAGGED
;
577 if (mp
->m_level
== 0 || maxwidth
== 0) {
582 cs
= ac_alloc(mp
->m_level
);
583 us
= ac_alloc(mp
->m_level
* sizeof *us
);
586 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
587 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
588 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
590 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
593 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
594 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
596 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
601 for (i
= mp
->m_level
- 2; i
>= 0; --i
) {
603 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
608 if (mq
->m_parent
&& (mq
->m_parent
->m_flag
& important
))
621 for (indlvl
= indw
= 0; (ui8_t
)indlvl
< mp
->m_level
&& indw
< maxwidth
;
623 if (indw
< maxwidth
- 1)
624 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0xFF, fp
);
626 indw
+= (int)putuc(0x21B8, '^', fp
);
628 indw
+= (/*putuc(0x261E, fp)*/putc('>', fp
) != EOF
);
638 _dispc(struct message
*mp
, char const *a
)
643 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MREAD
)
645 if ((mp
->m_flag
& (MREAD
| MNEW
)) == (MREAD
| MNEW
))
647 if (mp
->m_flag
& MANSWERED
)
649 if (mp
->m_flag
& MDRAFTED
)
651 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MNEW
)
653 if (!(mp
->m_flag
& (MREAD
| MNEW
)))
655 if (mp
->m_flag
& MSPAM
)
657 if (mp
->m_flag
& MSAVED
)
659 if (mp
->m_flag
& MPRESERVE
)
661 if (mp
->m_flag
& (MBOX
| MBOXED
))
663 if (mp
->m_flag
& MFLAGGED
)
665 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
667 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
674 _scroll1(char *arg
, int onlynew
)
679 cur
[0] = onlynew
? -1 : 0;
682 case '1': case '2': case '3': case '4': case '5':
683 case '6': case '7': case '8': case '9': case '0':
685 goto jscroll_forward
;
688 goto jscroll_forward
;
690 _screen
= msgCount
/ size
;
691 goto jscroll_forward
;
696 _screen
+= atoi(arg
+ 1);
698 if (_screen
* size
> msgCount
) {
699 _screen
= msgCount
/ size
;
700 printf(_("On last screenful of messages\n"));
708 _screen
-= atoi(arg
+ 1);
711 printf(_("On first screenful of messages\n"));
718 fprintf(stderr
, _("Unrecognized scrolling command \"%s\"\n"), arg
);
722 size
= c_headers(cur
);
729 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
730 bool_t dodecode
, char *cmd
, off_t
*tstats
)
736 FILE * volatile obuf
;
737 bool_t
volatile hadsig
= FAL0
, isrelax
= FAL0
;
740 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
741 ? SEND_MBOX
: dodecode
743 ? SEND_TODISP
: SEND_TODISP_ALL
);
744 bool_t
const volatile formfeed
= (dopipe
&& ok_blook(page
));
747 if (sigsetjmp(_cmd1_pipestop
, 1)) {
753 if ((cp
= ok_vlook(SHELL
)) == NULL
)
755 if ((obuf
= Popen(cmd
, "w", cp
, NULL
, 1)) == NULL
) {
759 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
760 } else if ((options
& OPT_TTYOUT
) &&
761 (dopage
|| (cp
= ok_vlook(crt
)) != NULL
)) {
762 char const *pager
= NULL
;
766 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
767 mp
= message
+ *ip
- 1;
768 if (!(mp
->m_have
& HAVE_BODY
))
769 if (get_body(mp
) != OKAY
) {
773 nlines
+= mp
->m_lines
+ 1; /* Message info XXX and PARTS... */
777 /* `>=' not `<': we return to the prompt */
778 if (dopage
|| UICMP(z
, nlines
, >=,
779 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
780 char const *env_add
[2];
781 pager
= get_pager(env_add
+ 0);
783 obuf
= Popen(pager
, "w", NULL
, env_add
, 1);
789 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
792 if (action
!= SEND_MBOX
)
793 colour_table_create(pager
!= NULL
); /* (salloc()s!) */
797 else if ((options
& OPT_TTYOUT
) && action
!= SEND_MBOX
)
798 colour_table_create(FAL0
); /* (salloc()s!) */
801 /*TODO unless we have our signal manager special care must be taken */
804 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
805 mp
= message
+ *ip
- 1;
812 if (action
!= SEND_MBOX
)
813 _show_msg_overview(obuf
, mp
, *ip
);
815 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
817 if (formfeed
) /* TODO a nicer way to separate piped messages! */
820 tstats
[0] += mstats
[0];
821 tstats
[1] += mstats
[1];
828 if (obuf
!= stdout
) {
829 /* Ignore SIGPIPE so it can't cause a duplicate close */
830 safe_signal(SIGPIPE
, SIG_IGN
);
831 if (hadsig
&& isrelax
)
833 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
835 safe_signal(SIGPIPE
, dflpipe
);
845 _pipe1(char *str
, int doign
)
853 if ((cmd
= laststring(str
, &needs_list
, TRU1
)) == NULL
) {
855 if (cmd
== NULL
|| *cmd
== '\0') {
856 fputs(_("variable cmd not set\n"), stderr
);
861 msgvec
= salloc((msgCount
+ 2) * sizeof *msgvec
);
864 *msgvec
= first(0, MMNORM
);
870 puts(_("No messages to pipe."));
874 } else if (getmsglist(str
, msgvec
, 0) < 0)
881 printf("No applicable messages.\n");
885 printf(_("Pipe to: \"%s\"\n"), cmd
);
886 stats
[0] = stats
[1] = 0;
887 if ((rv
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
888 printf("\"%s\" ", cmd
);
890 printf("%lu", (long)stats
[0]);
893 printf("/%lu\n", (long)stats
[1]);
901 c_cmdnotsupp(void *v
) /* TODO -> lex.c */
905 fprintf(stderr
, _("The requested feature is not compiled in\n"));
914 int *msgvec
= v
, g
, k
, n
, mesg
, size
, lastg
= 1;
915 struct message
*mp
, *mq
, *lastmq
= NULL
;
916 enum mflag fl
= MNEW
| MFLAGGED
;
919 time_current_update(&time_current
, FAL0
);
923 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
932 if (mb
.mb_threaded
== 0) {
935 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
939 if (mp
->m_flag
& fl
) {
943 if ((n
> 0 && PTRCMP(mp
, ==, message
+ n
- 1)) ||
944 (n
== 0 && g
== k
) || (n
== -2 && g
== k
+ size
&& lastmq
) ||
945 (n
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
949 if (lastmq
&& (n
== -2 ||
950 (n
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
956 mesg
= (int)PTR2SIZE(mp
- message
);
957 if (PTRCMP(dot
, !=, message
+ n
- 1)) {
958 for (mq
= mp
; PTRCMP(mq
, <, message
+ msgCount
); ++mq
)
965 if (mb
.mb_type
== MB_IMAP
)
966 imap_getheaders(mesg
+ 1, mesg
+ size
);
969 for (; PTRCMP(mp
, <, message
+ msgCount
); ++mp
) {
973 if (UICMP(32, flag
++, >=, size
))
975 _print_head(0, mesg
, stdout
, 0);
979 } else { /* threaded */
982 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
984 (mp
->m_collapsed
<= 0 || PTRCMP(mp
, ==, message
+ n
- 1))) {
987 if (mp
->m_flag
& fl
) {
991 if ((n
> 0 && PTRCMP(mp
, ==, message
+ n
- 1)) ||
992 (n
== 0 && g
== k
) || (n
== -2 && g
== k
+ size
&& lastmq
) ||
993 (n
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
997 if (lastmq
&& (n
== -2 ||
998 (n
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
1004 if (PTRCMP(dot
, !=, message
+ n
- 1)) {
1005 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
1006 if (visible(mq
) && mq
->m_collapsed
<= 0) {
1014 (mp
->m_collapsed
<= 0 || PTRCMP(mp
, ==, message
+ n
- 1))) {
1015 if (UICMP(32, flag
++, >=, size
))
1017 _print_head(flag
- 1, PTR2SIZE(mp
- message
+ 1), stdout
,
1021 mp
= next_in_thread(mp
);
1027 printf(_("No more mail.\n"));
1038 rv
= _scroll1(v
, 0);
1049 rv
= _scroll1(v
, 1);
1057 int *msgvec
= v
, *ip
, n
;
1059 FILE * volatile obuf
;
1062 time_current_update(&time_current
, FAL0
);
1065 /* TODO unfixable memory leaks still */
1066 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
1067 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
)
1069 if (n
> (*cp
== '\0' ? screensize() : atoi(cp
)) + 3) {
1071 if (sigsetjmp(_cmd1_pipejmp
, 1))
1073 p
= get_pager(NULL
);
1074 if ((obuf
= Popen(p
, "w", NULL
, NULL
, 1)) == NULL
) {
1079 safe_signal(SIGPIPE
, &_cmd1_onpipe
);
1083 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
) /* TODO join into _print_head() */
1084 _print_head((size_t)n
++, (size_t)*ip
, obuf
, mb
.mb_threaded
);
1086 setdot(message
+ *ip
- 1);
1089 if (obuf
!= stdout
) {
1090 safe_signal(SIGPIPE
, SIG_IGN
);
1092 safe_signal(SIGPIPE
, dflpipe
);
1099 print_headers(size_t bottom
, size_t topx
, bool_t only_marked
)
1105 if (mb
.mb_type
== MB_IMAP
)
1106 imap_getheaders(bottom
, topx
);
1108 time_current_update(&time_current
, FAL0
);
1110 for (printed
= 0; bottom
<= topx
; ++bottom
) {
1111 struct message
*mp
= message
+ bottom
- 1;
1113 if (!(mp
->m_flag
& MMARK
))
1115 } else if (!visible(mp
))
1117 _print_head(printed
++, bottom
, stdout
, FAL0
);
1127 printf("%d\n", (int)PTR2SIZE(dot
- message
+ 1));
1135 int *msgvec
= v
, rv
;
1138 rv
= _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1146 int *msgvec
= v
, rv
;
1149 rv
= _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1157 int *msgvec
= v
, rv
;
1160 rv
= _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1168 int *msgvec
= v
, rv
;
1171 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1179 int *msgvec
= v
, rv
;
1182 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1194 rv
= _pipe1(str
, 1);
1206 rv
= _pipe1(str
, 0);
1214 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1216 char *cp
, *linebuf
= NULL
;
1217 size_t linesize
= 0;
1222 cp
= ok_vlook(toplines
);
1225 if (topl
< 0 || topl
> 10000)
1230 if (options
& OPT_TTYOUT
)
1231 colour_table_create(FAL0
); /* (salloc()s) */
1234 for (ip
= msgvec
; *ip
!= 0 && UICMP(z
, PTR2SIZE(ip
- msgvec
), <, msgCount
);
1236 mp
= message
+ *ip
- 1;
1239 did_print_dot
= TRU1
;
1242 _show_msg_overview(stdout
, mp
, *ip
);
1243 if (mp
->m_flag
& MNOFROM
)
1244 /* XXX c_top(): coloured output? */
1245 printf("From %s %s\n", fakefrom(mp
), fakedate(mp
->m_time
));
1246 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1251 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
); ++lines
) {
1252 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1256 for (cp
= linebuf
; *cp
!= '\0' && blankchar(*cp
); ++cp
)
1258 empty_last
= (*cp
== '\0');
1262 if (linebuf
!= NULL
)
1271 int *msgvec
= v
, *ip
;
1274 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1275 setdot(message
+ *ip
- 1);
1276 dot
->m_flag
|= MTOUCH
;
1277 dot
->m_flag
&= ~MPRESERVE
;
1278 did_print_dot
= TRU1
;
1287 int *msgvec
= v
, *ip
;
1290 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1291 setdot(message
+ *ip
- 1);
1292 dot
->m_flag
|= MTOUCH
| MBOX
;
1293 dot
->m_flag
&= ~MPRESERVE
;
1294 did_print_dot
= TRU1
;
1303 char dirname
[PATH_MAX
], *name
, **argv
= v
;
1309 name
= expand(*argv
);
1312 } else if (!getfold(dirname
, sizeof dirname
)) {
1313 fprintf(stderr
, _("No value set for \"folder\"\n"));
1318 if (which_protocol(name
) == PROTO_IMAP
) {
1320 imap_folders(name
, *argv
== NULL
);
1322 rv
= c_cmdnotsupp(NULL
);
1325 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1327 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);