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 int __putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
69 static int _dispc(struct message
*mp
, char const *a
);
70 static int _scroll1(char *arg
, int onlynew
);
72 /* Show the requested messages */
73 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
74 bool_t dodecode
, char *cmd
, off_t
*tstats
);
76 /* Pipe the requested messages */
77 static int _pipe1(char *str
, int doign
);
80 _cmd1_onpipe(int signo
)
82 NYD_X
; /* Signal handler */
84 siglongjmp(_cmd1_pipejmp
, 1);
88 _cmd1_brokpipe(int signo
)
90 NYD_X
; /* Signal handler */
92 siglongjmp(_cmd1_pipestop
, 1);
96 _show_msg_overview(FILE *obuf
, struct message
*mp
, int msg_no
)
98 char const *cpre
= "", *csuf
= "";
102 if (colour_table
!= NULL
) {
103 struct str
const *sp
;
105 if ((sp
= colour_get(COLOURSPEC_MSGINFO
)) != NULL
)
107 csuf
= colour_get(COLOURSPEC_RESET
)->s
;
110 fprintf(obuf
, _("%s[-- Message %2d -- %lu lines, %lu bytes --]:%s\n"),
111 cpre
, msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
, csuf
);
116 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]) /* TODO line pool */
124 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
125 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
126 extract_date_from_from_(hline
, hlen
, date
);
133 _print_head(size_t yetprinted
, size_t msgno
, FILE *f
, bool_t threaded
)
136 char attrlist
[attrlen
+1], *cp
;
140 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
141 if (strlen(cp
) == attrlen
) {
142 memcpy(attrlist
, cp
, attrlen
+1);
146 "The value of *attrlist* is not of the correct length\n"));
148 if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) ||
149 getenv("SYSV3") != NULL
) {
150 char const bsdattr
[attrlen
+1] = "NU *HMFAT+-$";
151 memcpy(attrlist
, bsdattr
, sizeof bsdattr
);
153 char const pattr
[attrlen
+1] = "NUROSPMFAT+-$";
154 memcpy(attrlist
, pattr
, sizeof pattr
);
157 if ((fmt
= ok_vlook(headline
)) == NULL
) {
158 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
159 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
160 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
163 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
168 __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
, FILE *f
,
169 bool_t threaded
, char const *attrlist
)
171 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
172 char const *datefmt
, *date
, *name
, *fp
;
173 int i
, n
, s
, wleft
, subjlen
;
181 _LOOP_MASK
= (1<<3) - 1,
186 mp
= message
+ msgno
- 1;
190 datefmt
= ok_vlook(datefield
);
192 if (datefmt
!= NULL
) {
193 fp
= hfield1("date", mp
);/* TODO use m_date field! */
199 date
= fakedate(datet
);
200 fp
= ok_vlook(datefield_markout_older
);
201 i
= (*datefmt
!= '\0');
203 i
|= (*fp
!= '\0') ? 2 | 4 : 2; /* XXX no magics */
205 /* May we strftime(3)? */
207 memcpy(&time_current
.tc_local
, localtime(&datet
),
208 sizeof time_current
.tc_local
);
210 if ((i
& 2) && (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
211 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
212 (datet
+ _6M
< time_current
.tc_time
))) {
214 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
215 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
216 memcpy(datebuf
+ 4, date
+ 4, 7);
217 datebuf
[4 + 7] = ' ';
218 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
219 datebuf
[4 + 7 + 1 + 4] = '\0';
222 } else if ((i
& 1) == 0)
224 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
225 /* TODO eliminate this path, query the FROM_ date in setptr(),
226 * TODO all other codepaths do so by themselves ALREADY ?????
227 * TODO assert(mp->m_time != 0);, then
228 * TODO ALSO changes behaviour of datefield_markout_older */
229 _parse_from_(mp
, datebuf
);
232 date
= fakedate(datet
);
236 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
237 if ((cp
= hfield1("to", mp
)) != NULL
) {
247 name
= ok_blook(showname
) ? realname(name
) : prstr(skin(name
));
251 /* Detect the width of the non-format characters in *headline*;
252 * like that we can simply use putc() in the next loop, since we have
253 * already calculated their column widths (TODO it's sick) */
254 wleft
= subjlen
= scrnwidth
;
256 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
262 if (digitchar(*fp
)) {
265 n
= 10*n
+ *fp
- '0';
266 while (++fp
, digitchar(*fp
));
276 if (mb_cur_max
> 1) {
278 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) == -1)
280 else if ((n
= wcwidth(wc
)) == -1)
292 /* Walk *headline*, producing output TODO not (really) MB safe */
293 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
295 if ((c
= *fp
& 0xFF) != '%')
304 } else if (*fp
== '+')
306 if (digitchar(*fp
)) {
308 n
= 10*n
+ *fp
- '0';
309 while (++fp
, digitchar(*fp
));
315 switch ((c
= *fp
& 0xFF)) {
327 if (UICMP(32, ABS(n
), >, wleft
))
328 n
= (n
< 0) ? -wleft
: wleft
;
330 snprintf(buf
, sizeof buf
, "%u.%u",
331 (mp
->m_spamscore
>> 8), (mp
->m_spamscore
& 0xFF));
332 n
= fprintf(f
, "%*s", n
, buf
);
333 wleft
= (n
>= 0) ? wleft
- n
: 0;
340 c
= _dispc(mp
, attrlist
);
342 if (UICMP(32, ABS(n
), >, wleft
))
343 n
= (n
< 0) ? -wleft
: wleft
;
344 n
= fprintf(f
, "%*c", n
, c
);
345 wleft
= (n
>= 0) ? wleft
- n
: 0;
348 if (datefmt
!= NULL
) {
349 i
= strftime(datebuf
, sizeof datebuf
, datefmt
,
350 &time_current
.tc_local
);
355 "Ignored date format, it excesses the target buffer "
356 "(%lu bytes)\n"), (ul_it
)sizeof datebuf
);
361 if (UICMP(32, ABS(n
), >, wleft
))
362 n
= (n
< 0) ? -wleft
: wleft
;
363 n
= fprintf(f
, "%*.*s", n
, n
, date
);
364 wleft
= (n
>= 0) ? wleft
- n
: 0;
369 if (UICMP(32, ABS(n
), >, wleft
))
370 n
= (n
< 0) ? -wleft
: wleft
;
371 n
= fprintf(f
, "%*u", n
, (threaded
== 1 ? mp
->m_level
: 0));
372 wleft
= (n
>= 0) ? wleft
- n
: 0;
383 n
= (n
< 0) ? -wleft
: wleft
;
385 if (flags
& _ISTO
) /* XXX tr()! */
387 n
= fprintf(f
, "%s%s", ((flags
& _ISTO
) ? "To " : ""),
388 colalign(name
, i
, n
, &wleft
));
391 else if (flags
& _ISTO
)
396 n
= __putindent(f
, mp
, MIN(wleft
, scrnwidth
- 60));
397 wleft
= (n
>= 0) ? wleft
- n
: 0;
403 if (UICMP(32, ABS(n
), >, wleft
))
404 n
= (n
< 0) ? -wleft
: wleft
;
406 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
407 wleft
= (n
>= 0) ? wleft
- n
: 0;
419 for (i
= msgCount
; i
> 999; i
/= 10)
422 if (UICMP(32, ABS(n
), >, wleft
))
423 n
= (n
< 0) ? -wleft
: wleft
;
424 n
= fprintf(f
, "%*lu", n
, (ul_it
)msgno
);
425 wleft
= (n
>= 0) ? wleft
- n
: 0;
430 if (UICMP(32, ABS(n
), >, wleft
))
431 n
= (n
< 0) ? -wleft
: wleft
;
432 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
433 wleft
= (n
>= 0) ? wleft
- n
: 0;
445 if (UICMP(32, ABS(n
), >, subjlen
))
446 n
= (n
< 0) ? -subjlen
: subjlen
;
448 n
-= (n
< 0) ? -2 : 2;
451 if (subjline
== NULL
)
452 subjline
= __subject(mp
, (threaded
&& (flags
& _IFMT
)),
454 if (subjline
== (char*)-1) {
455 n
= fprintf(f
, "%*s", n
, "");
456 wleft
= (n
>= 0) ? wleft
- n
: 0;
458 n
= fprintf(f
, ((flags
& _SFMT
) ? "\"%s\"" : "%s"),
459 colalign(subjline
, ABS(n
), n
, &wleft
));
468 for (i
= msgCount
; i
> 999; i
/= 10)
471 if (UICMP(32, ABS(n
), >, wleft
))
472 n
= (n
< 0) ? -wleft
: wleft
;
473 n
= fprintf(f
, "%*lu", n
,
474 (threaded
? (ul_it
)mp
->m_threadpos
: (ul_it
)msgno
));
475 wleft
= (n
>= 0) ? wleft
- n
: 0;
481 if (UICMP(32, ABS(n
), >, wleft
))
482 n
= (n
< 0) ? -wleft
: wleft
;
483 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
484 wleft
= (n
>= 0) ? wleft
- n
: 0;
498 if (subjline
!= NULL
&& subjline
!= (char*)-1)
504 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
506 /* XXX NOTE: because of efficiency reasons we simply ignore any encoded
507 * XXX parts and use ASCII case-insensitive comparison */
510 char *rv
= (char*)-1, *ms
, *mso
, *os
;
513 if ((ms
= hfield1("subject", mp
)) == NULL
)
516 if (!threaded
|| mp
->m_level
== 0)
519 /* In a display thread - check wether this message uses the same
520 * Subject: as it's parent or elder neighbour, suppress printing it if
521 * this is the case. To extend this a bit, ignore any leading Re: or
522 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
523 mso
= subject_re_trim(ms
);
524 for (xmp
= mp
; (xmp
= prev_in_thread(xmp
)) != NULL
&& yetprinted
-- > 0;)
525 if (visible(xmp
) && (os
= hfield1("subject", xmp
)) != NULL
&&
526 !asccasecmp(mso
, subject_re_trim(os
)))
531 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
539 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
542 int *us
, indlvl
, indw
, i
, important
= MNEW
| MFLAGGED
;
546 if (mp
->m_level
== 0 || maxwidth
== 0) {
551 cs
= ac_alloc(mp
->m_level
);
552 us
= ac_alloc(mp
->m_level
* sizeof *us
);
555 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
556 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
557 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
559 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
562 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
563 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
565 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
570 for (i
= mp
->m_level
- 2; i
>= 0; --i
) {
572 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
577 if (mq
->m_parent
&& (mq
->m_parent
->m_flag
& important
))
590 for (indlvl
= indw
= 0; (ui8_t
)indlvl
< mp
->m_level
&& indw
< maxwidth
;
592 if (indw
< maxwidth
- 1)
593 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0xFF, fp
);
595 indw
+= (int)putuc(0x21B8, '^', fp
);
597 indw
+= (/*putuc(0x261E, fp)*/putc('>', fp
) != EOF
);
607 _dispc(struct message
*mp
, char const *a
)
612 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MREAD
)
614 if ((mp
->m_flag
& (MREAD
| MNEW
)) == (MREAD
| MNEW
))
616 if (mp
->m_flag
& MANSWERED
)
618 if (mp
->m_flag
& MDRAFTED
)
620 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MNEW
)
622 if (!(mp
->m_flag
& (MREAD
| MNEW
)))
624 if (mp
->m_flag
& MSPAM
)
626 if (mp
->m_flag
& MSAVED
)
628 if (mp
->m_flag
& MPRESERVE
)
630 if (mp
->m_flag
& (MBOX
| MBOXED
))
632 if (mp
->m_flag
& MFLAGGED
)
634 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
636 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
643 _scroll1(char *arg
, int onlynew
)
648 cur
[0] = onlynew
? -1 : 0;
651 case '1': case '2': case '3': case '4': case '5':
652 case '6': case '7': case '8': case '9': case '0':
654 goto jscroll_forward
;
657 goto jscroll_forward
;
659 _screen
= msgCount
/ size
;
660 goto jscroll_forward
;
665 _screen
+= atoi(arg
+ 1);
667 if (_screen
* size
> msgCount
) {
668 _screen
= msgCount
/ size
;
669 printf(_("On last screenful of messages\n"));
677 _screen
-= atoi(arg
+ 1);
680 printf(_("On first screenful of messages\n"));
687 fprintf(stderr
, _("Unrecognized scrolling command \"%s\"\n"), arg
);
691 size
= c_headers(cur
);
698 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
699 bool_t dodecode
, char *cmd
, off_t
*tstats
)
705 FILE * volatile obuf
;
706 bool_t
volatile hadsig
= FAL0
, isrelax
= FAL0
;
709 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
710 ? SEND_MBOX
: dodecode
712 ? SEND_TODISP
: SEND_TODISP_ALL
);
713 bool_t
const volatile formfeed
= (dopipe
&& ok_blook(page
));
716 if (sigsetjmp(_cmd1_pipestop
, 1)) {
722 if ((cp
= ok_vlook(SHELL
)) == NULL
)
724 if ((obuf
= Popen(cmd
, "w", cp
, NULL
, 1)) == NULL
) {
728 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
729 } else if ((options
& OPT_TTYOUT
) &&
730 (dopage
|| (cp
= ok_vlook(crt
)) != NULL
)) {
731 char const *pager
= NULL
;
735 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
736 mp
= message
+ *ip
- 1;
737 if (!(mp
->m_have
& HAVE_BODY
))
738 if (get_body(mp
) != OKAY
) {
742 nlines
+= mp
->m_lines
+ 1; /* Message info XXX and PARTS... */
746 /* `>=' not `<': we return to the prompt */
747 if (dopage
|| UICMP(z
, nlines
, >=,
748 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
749 char const *env_add
[2];
750 pager
= get_pager(env_add
+ 0);
752 obuf
= Popen(pager
, "w", NULL
, env_add
, 1);
758 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
761 if (action
!= SEND_MBOX
)
762 colour_table_create(pager
!= NULL
); /* (salloc()s!) */
766 else if ((options
& OPT_TTYOUT
) && action
!= SEND_MBOX
)
767 colour_table_create(FAL0
); /* (salloc()s!) */
770 /*TODO unless we have our signal manager special care must be taken */
773 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
774 mp
= message
+ *ip
- 1;
781 if (action
!= SEND_MBOX
)
782 _show_msg_overview(obuf
, mp
, *ip
);
784 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
786 if (formfeed
) /* TODO a nicer way to separate piped messages! */
789 tstats
[0] += mstats
[0];
790 tstats
[1] += mstats
[1];
797 if (obuf
!= stdout
) {
798 /* Ignore SIGPIPE so it can't cause a duplicate close */
799 safe_signal(SIGPIPE
, SIG_IGN
);
800 if (hadsig
&& isrelax
)
802 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
804 safe_signal(SIGPIPE
, dflpipe
);
814 _pipe1(char *str
, int doign
)
822 if ((cmd
= laststring(str
, &needs_list
, TRU1
)) == NULL
) {
824 if (cmd
== NULL
|| *cmd
== '\0') {
825 fputs(_("variable cmd not set\n"), stderr
);
830 msgvec
= salloc((msgCount
+ 2) * sizeof *msgvec
);
833 *msgvec
= first(0, MMNORM
);
839 puts(_("No messages to pipe."));
843 } else if (getmsglist(str
, msgvec
, 0) < 0)
850 printf("No applicable messages.\n");
854 printf(_("Pipe to: \"%s\"\n"), cmd
);
855 stats
[0] = stats
[1] = 0;
856 if ((rv
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
857 printf("\"%s\" ", cmd
);
859 printf("%lu", (long)stats
[0]);
862 printf("/%lu\n", (long)stats
[1]);
870 c_cmdnotsupp(void *v
) /* TODO -> lex.c */
874 fprintf(stderr
, _("The requested feature is not compiled in\n"));
883 int *msgvec
= v
, g
, k
, n
, mesg
, size
, lastg
= 1;
884 struct message
*mp
, *mq
, *lastmq
= NULL
;
885 enum mflag fl
= MNEW
| MFLAGGED
;
888 time_current_update(&time_current
, FAL0
);
892 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
901 if (mb
.mb_threaded
== 0) {
904 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
908 if (mp
->m_flag
& fl
) {
912 if ((n
> 0 && PTRCMP(mp
, ==, message
+ n
- 1)) ||
913 (n
== 0 && g
== k
) || (n
== -2 && g
== k
+ size
&& lastmq
) ||
914 (n
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
918 if (lastmq
&& (n
== -2 ||
919 (n
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
925 mesg
= (int)PTR2SIZE(mp
- message
);
926 if (PTRCMP(dot
, !=, message
+ n
- 1)) {
927 for (mq
= mp
; PTRCMP(mq
, <, message
+ msgCount
); ++mq
)
934 if (mb
.mb_type
== MB_IMAP
)
935 imap_getheaders(mesg
+ 1, mesg
+ size
);
938 for (; PTRCMP(mp
, <, message
+ msgCount
); ++mp
) {
942 if (UICMP(32, flag
++, >=, size
))
944 _print_head(0, mesg
, stdout
, 0);
948 } else { /* threaded */
951 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
953 (mp
->m_collapsed
<= 0 || PTRCMP(mp
, ==, message
+ n
- 1))) {
956 if (mp
->m_flag
& fl
) {
960 if ((n
> 0 && PTRCMP(mp
, ==, message
+ n
- 1)) ||
961 (n
== 0 && g
== k
) || (n
== -2 && g
== k
+ size
&& lastmq
) ||
962 (n
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
966 if (lastmq
&& (n
== -2 ||
967 (n
== -1 && PTRCMP(mp
, ==, message
+ msgCount
)))) {
973 if (PTRCMP(dot
, !=, message
+ n
- 1)) {
974 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
975 if (visible(mq
) && mq
->m_collapsed
<= 0) {
983 (mp
->m_collapsed
<= 0 || PTRCMP(mp
, ==, message
+ n
- 1))) {
984 if (UICMP(32, flag
++, >=, size
))
986 _print_head(flag
- 1, PTR2SIZE(mp
- message
+ 1), stdout
,
990 mp
= next_in_thread(mp
);
996 printf(_("No more mail.\n"));
1007 rv
= _scroll1(v
, 0);
1018 rv
= _scroll1(v
, 1);
1026 int *msgvec
= v
, *ip
, n
;
1028 FILE * volatile obuf
;
1031 time_current_update(&time_current
, FAL0
);
1034 /* TODO unfixable memory leaks still */
1035 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
1036 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
)
1038 if (n
> (*cp
== '\0' ? screensize() : atoi(cp
)) + 3) {
1040 if (sigsetjmp(_cmd1_pipejmp
, 1))
1042 p
= get_pager(NULL
);
1043 if ((obuf
= Popen(p
, "w", NULL
, NULL
, 1)) == NULL
) {
1048 safe_signal(SIGPIPE
, &_cmd1_onpipe
);
1052 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
) /* TODO join into _print_head() */
1053 _print_head((size_t)n
++, (size_t)*ip
, obuf
, mb
.mb_threaded
);
1055 setdot(message
+ *ip
- 1);
1058 if (obuf
!= stdout
) {
1059 safe_signal(SIGPIPE
, SIG_IGN
);
1061 safe_signal(SIGPIPE
, dflpipe
);
1068 print_headers(size_t bottom
, size_t topx
, bool_t only_marked
)
1074 if (mb
.mb_type
== MB_IMAP
)
1075 imap_getheaders(bottom
, topx
);
1077 time_current_update(&time_current
, FAL0
);
1079 for (printed
= 0; bottom
<= topx
; ++bottom
) {
1080 struct message
*mp
= message
+ bottom
- 1;
1082 if (!(mp
->m_flag
& MMARK
))
1084 } else if (!visible(mp
))
1086 _print_head(printed
++, bottom
, stdout
, FAL0
);
1096 printf("%d\n", (int)PTR2SIZE(dot
- message
+ 1));
1104 int *msgvec
= v
, rv
;
1107 rv
= _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1115 int *msgvec
= v
, rv
;
1118 rv
= _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1126 int *msgvec
= v
, rv
;
1129 rv
= _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1137 int *msgvec
= v
, rv
;
1140 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1148 int *msgvec
= v
, rv
;
1151 rv
= _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1163 rv
= _pipe1(str
, 1);
1175 rv
= _pipe1(str
, 0);
1183 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1185 char *cp
, *linebuf
= NULL
;
1186 size_t linesize
= 0;
1191 cp
= ok_vlook(toplines
);
1194 if (topl
< 0 || topl
> 10000)
1199 if (options
& OPT_TTYOUT
)
1200 colour_table_create(FAL0
); /* (salloc()s) */
1203 for (ip
= msgvec
; *ip
!= 0 && UICMP(z
, PTR2SIZE(ip
- msgvec
), <, msgCount
);
1205 mp
= message
+ *ip
- 1;
1208 did_print_dot
= TRU1
;
1211 _show_msg_overview(stdout
, mp
, *ip
);
1212 if (mp
->m_flag
& MNOFROM
)
1213 /* XXX c_top(): coloured output? */
1214 printf("From %s %s\n", fakefrom(mp
), 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
); ++lines
) {
1221 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1225 for (cp
= linebuf
; *cp
!= '\0' && blankchar(*cp
); ++cp
)
1227 empty_last
= (*cp
== '\0');
1231 if (linebuf
!= NULL
)
1240 int *msgvec
= v
, *ip
;
1243 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1244 setdot(message
+ *ip
- 1);
1245 dot
->m_flag
|= MTOUCH
;
1246 dot
->m_flag
&= ~MPRESERVE
;
1247 did_print_dot
= TRU1
;
1256 int *msgvec
= v
, *ip
;
1259 for (ip
= msgvec
; *ip
!= 0; ++ip
) {
1260 setdot(message
+ *ip
- 1);
1261 dot
->m_flag
|= MTOUCH
| MBOX
;
1262 dot
->m_flag
&= ~MPRESERVE
;
1263 did_print_dot
= TRU1
;
1272 char dirname
[PATH_MAX
], *name
, **argv
= v
;
1278 name
= expand(*argv
);
1281 } else if (!getfold(dirname
, sizeof dirname
)) {
1282 fprintf(stderr
, _("No value set for \"folder\"\n"));
1287 if (which_protocol(name
) == PROTO_IMAP
) {
1289 imap_folders(name
, *argv
== NULL
);
1291 rv
= c_cmdnotsupp(NULL
);
1294 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1296 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);