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
, tr(17, "%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
])
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
)
136 char attrlist
[30], *cp
;
140 if ((cp
= ok_vlook(attrlist
)) != NULL
) {
141 size_t i
= strlen(cp
);
142 if (UICMP(32, i
, >, sizeof attrlist
- 1))
143 i
= (int)sizeof attrlist
- 1;
144 memcpy(attrlist
, cp
, i
);
145 } else if (ok_blook(bsdcompat
) || ok_blook(bsdflags
) ||
146 getenv("SYSV3") != NULL
) {
147 char const bsdattr
[] = "NU *HMFAT+-$";
148 memcpy(attrlist
, bsdattr
, sizeof bsdattr
- 1);
150 char const pattr
[] = "NUROSPMFAT+-$";
151 memcpy(attrlist
, pattr
, sizeof pattr
- 1);
154 if ((fmt
= ok_vlook(headline
)) == NULL
) {
155 fmt
= ((ok_blook(bsdcompat
) || ok_blook(bsdheadline
))
156 ? "%>%a%m %-20f %16d %3l/%-5o %i%-S"
157 : "%>%a%m %-18f %16d %4l/%-5o %i%-s");
160 __hprf(yetprinted
, fmt
, msgno
, f
, threaded
, attrlist
);
165 __hprf(size_t yetprinted
, char const *fmt
, size_t msgno
, FILE *f
,
166 bool_t threaded
, char const *attrlist
)
168 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
169 char const *datefmt
, *date
, *name
, *fp
;
170 int B
, c
, i
, n
, s
, wleft
, subjlen
, isto
= 0, isaddr
= 0;
175 mp
= &message
[msgno
- 1];
179 datefmt
= ok_vlook(datefield
);
181 if (datefmt
!= NULL
) {
182 fp
= hfield1("date", mp
);/* TODO use m_date field! */
188 date
= fakedate(datet
);
189 fp
= ok_vlook(datefield_markout_older
);
190 i
= (*datefmt
!= '\0');
192 i
|= (*fp
!= '\0') ? 2 | 4 : 2;
194 /* May we strftime(3)? */
196 memcpy(&time_current
.tc_local
, localtime(&datet
),
197 sizeof time_current
.tc_local
);
199 if ((i
& 2) && (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
200 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
201 (datet
+ _6M
< time_current
.tc_time
))) {
203 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
204 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
205 memcpy(datebuf
+ 4, date
+ 4, 7);
206 datebuf
[4 + 7] = ' ';
207 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
208 datebuf
[4 + 7 + 1 + 4] = '\0';
211 } else if ((i
& 1) == 0)
213 } else if (datet
== (time_t)0 && !(mp
->m_flag
& MNOFROM
)) {
214 /* TODO eliminate this path, query the FROM_ date in setptr(),
215 * TODO all other codepaths do so by themselves ALREADY ?????
216 * TODO assert(mp->m_time != 0);, then
217 * TODO ALSO changes behaviour of datefield_markout_older */
218 _parse_from_(mp
, datebuf
);
221 date
= fakedate(datet
);
225 if (name
!= NULL
&& ok_blook(showto
) && is_myname(skin(name
))) {
226 if ((cp
= hfield1("to", mp
)) != NULL
) {
236 name
= ok_blook(showname
) ? realname(name
) : prstr(skin(name
));
240 /* Detect the width of the non-format characters in *headline*;
241 * like that we can simply use putc() in the next loop, since we have
242 * already calculated their column widths (TODO it's sick) */
243 wleft
= subjlen
= scrnwidth
;
245 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
251 if (digitchar(*fp
)) {
254 n
= 10*n
+ *fp
- '0';
255 while (++fp
, digitchar(*fp
));
263 if (mb_cur_max
> 1) {
265 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) < 0)
267 else if ((n
= wcwidth(wc
)) < 0)
279 /* Walk *headline*, producing output */
280 for (fp
= fmt
; *fp
!= '\0'; ++fp
) {
281 if ((c
= *fp
& 0xFF) == '%') {
288 } else if (*fp
== '+')
290 if (digitchar(*fp
)) {
292 n
= 10*n
+ *fp
- '0';
293 while (++fp
, digitchar(*fp
));
299 switch ((c
= *fp
& 0xFF)) {
308 c
= _dispc(mp
, attrlist
);
310 if (UICMP(32, ABS(n
), >, wleft
))
311 n
= (n
< 0) ? -wleft
: wleft
;
312 n
= fprintf(f
, "%*c", n
, c
);
313 wleft
= (n
>= 0) ? wleft
- n
: 0;
319 for (i
= msgCount
; i
> 999; i
/= 10)
322 if (UICMP(32, ABS(n
), >, wleft
))
323 n
= (n
< 0) ? -wleft
: wleft
;
324 n
= fprintf(f
, "%*lu", n
, (ul_it
)msgno
);
325 wleft
= (n
>= 0) ? wleft
- n
: 0;
336 n
= (n
< 0) ? -wleft
: wleft
;
338 if (isto
) /* XXX tr()! */
340 n
= fprintf(f
, "%s%s", (isto
? "To " : ""),
341 colalign(name
, i
, n
, &wleft
));
348 if (datefmt
!= NULL
) {
349 i
= strftime(datebuf
, sizeof datebuf
, datefmt
,
350 &time_current
.tc_local
);
354 fprintf(stderr
, tr(174,
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
;
372 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
373 wleft
= (n
>= 0) ? wleft
- n
: 0;
384 if (UICMP(32, ABS(n
), >, wleft
))
385 n
= (n
< 0) ? -wleft
: wleft
;
386 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
387 wleft
= (n
>= 0) ? wleft
- n
: 0;
391 n
= __putindent(f
, mp
, MIN(wleft
, scrnwidth
- 60));
392 wleft
= (n
>= 0) ? wleft
- n
: 0;
405 if (UICMP(32, ABS(n
), >, subjlen
))
406 n
= (n
< 0) ? -subjlen
: subjlen
;
408 n
-= (n
< 0) ? -2 : 2;
411 if (subjline
== NULL
)
412 subjline
= __subject(mp
, threaded
, yetprinted
);
413 if (subjline
== (char*)-1) {
414 n
= fprintf(f
, "%*s", n
, "");
415 wleft
= (n
>= 0) ? wleft
- n
: 0;
417 n
= fprintf(f
, (B
? "\"%s\"" : "%s"),
418 colalign(subjline
, ABS(n
), n
, &wleft
));
427 if (UICMP(32, ABS(n
), >, wleft
))
428 n
= (n
< 0) ? -wleft
: wleft
;
429 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
430 wleft
= (n
>= 0) ? wleft
- n
: 0;
439 if (UICMP(32, ABS(n
), >, wleft
))
440 n
= (n
< 0) ? -wleft
: wleft
;
441 n
= fprintf(f
, "%*u", n
, (threaded
== 1 ? mp
->m_level
: 0));
442 wleft
= (n
>= 0) ? wleft
- n
: 0;
448 for (i
= msgCount
; i
> 999; i
/= 10)
451 if (UICMP(32, ABS(n
), >, wleft
))
452 n
= (n
< 0) ? -wleft
: wleft
;
453 n
= fprintf(f
, "%*lu", n
,
454 (threaded
? (ul_it
)mp
->m_threadpos
: (ul_it
)msgno
));
455 wleft
= (n
>= 0) ? wleft
- n
: 0;
461 if (UICMP(32, ABS(n
), >, wleft
))
462 n
= (n
< 0) ? -wleft
: wleft
;
464 snprintf(buf
, sizeof buf
, "%u.%u",
465 (mp
->m_spamscore
>> 8), (mp
->m_spamscore
& 0xFF));
466 n
= fprintf(f
, "%*s", n
, buf
);
467 wleft
= (n
>= 0) ? wleft
- n
: 0;
482 if (subjline
!= NULL
&& subjline
!= (char*)-1)
488 __subject_trim(char *s
)
493 } const *pp
, ignored
[] = { /* TODO make ignore list configurable */
494 { 3, "re:" }, { 4, "fwd:" },
495 { 3, "aw:" }, { 5, "antw:" },
502 while (spacechar(*s
))
504 /* TODO While it is maybe ok not to MIME decode these, we
505 * TODO should skip =?..?= at the beginning? */
506 for (pp
= ignored
; pp
->len
> 0; ++pp
)
507 if (is_asccaseprefix(pp
->dat
, s
)) {
518 __subject(struct message
*mp
, bool_t threaded
, size_t yetprinted
)
520 /* XXX NOTE: because of efficiency reasons we simply ignore any encoded
521 * XXX parts and use ASCII case-insensitive comparison */
524 char *rv
= (char*)-1, *ms
, *mso
, *os
;
527 if ((ms
= hfield1("subject", mp
)) == NULL
)
530 if (!threaded
|| mp
->m_level
== 0)
533 /* In a display thread - check wether this message uses the same
534 * Subject: as it's parent or elder neighbour, suppress printing it if
535 * this is the case. To extend this a bit, ignore any leading Re: or
536 * Fwd: plus follow-up WS. Ignore invisible messages along the way */
537 mso
= __subject_trim(ms
);
538 for (xmp
= mp
; (xmp
= prev_in_thread(xmp
)) != NULL
&& yetprinted
-- > 0;)
539 if (visible(xmp
) && (os
= hfield1("subject", xmp
)) != NULL
&&
540 asccasecmp(mso
, __subject_trim(os
)) == 0)
545 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
553 __putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
556 int *us
, indlvl
, indw
, i
, important
= MNEW
| MFLAGGED
;
560 if (mp
->m_level
== 0 || maxwidth
== 0) {
565 cs
= ac_alloc(mp
->m_level
);
566 us
= ac_alloc(mp
->m_level
* sizeof *us
);
569 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
570 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
571 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
573 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
576 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
577 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
579 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
584 for (i
= mp
->m_level
- 2; i
>= 0; --i
) {
586 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
591 if (mq
->m_parent
&& (mq
->m_parent
->m_flag
& important
))
604 for (indlvl
= indw
= 0; (uc_it
)indlvl
< mp
->m_level
&& indw
< maxwidth
;
606 if (indw
< maxwidth
- 1)
607 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0377, fp
);
609 indw
+= (int)putuc(0x21B8, '^', fp
);
611 indw
+= (/*putuc(0x261E, fp)*/putc('>', fp
) != EOF
);
621 _dispc(struct message
*mp
, char const *a
)
626 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MREAD
)
628 if ((mp
->m_flag
& (MREAD
| MNEW
)) == (MREAD
| MNEW
))
630 if (mp
->m_flag
& MANSWERED
)
632 if (mp
->m_flag
& MDRAFTED
)
634 if ((mp
->m_flag
& (MREAD
| MNEW
)) == MNEW
)
636 if ((mp
->m_flag
& (MREAD
| MNEW
)) == 0)
638 if (mp
->m_flag
& MSPAM
)
640 if (mp
->m_flag
& MSAVED
)
642 if (mp
->m_flag
& MPRESERVE
)
644 if (mp
->m_flag
& (MBOX
| MBOXED
))
646 if (mp
->m_flag
& MFLAGGED
)
648 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
650 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
657 _scroll1(char *arg
, int onlynew
)
662 cur
[0] = onlynew
? -1 : 0;
665 case '1': case '2': case '3': case '4': case '5':
666 case '6': case '7': case '8': case '9': case '0':
668 goto jscroll_forward
;
671 goto jscroll_forward
;
673 _screen
= msgCount
/ size
;
674 goto jscroll_forward
;
679 _screen
+= atoi(arg
+ 1);
681 if (_screen
* size
> msgCount
) {
682 _screen
= msgCount
/ size
;
683 printf(tr(7, "On last screenful of messages\n"));
691 _screen
-= atoi(arg
+ 1);
694 printf(tr(8, "On first screenful of messages\n"));
701 printf(tr(9, "Unrecognized scrolling command \"%s\"\n"), arg
);
712 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
713 bool_t dodecode
, char *cmd
, off_t
*tstats
)
719 FILE * volatile obuf
;
722 enum sendaction
const action
= ((dopipe
&& ok_blook(piperaw
))
723 ? SEND_MBOX
: dodecode
725 ? SEND_TODISP
: SEND_TODISP_ALL
);
726 bool_t
const volatile formfeed
= (dopipe
&& ok_blook(page
));
729 if (sigsetjmp(_cmd1_pipestop
, 1))
732 if ((cp
= ok_vlook(SHELL
)) == NULL
)
734 if ((obuf
= Popen(cmd
, "w", cp
, 1)) == NULL
) {
738 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
739 } else if ((options
& OPT_TTYOUT
) &&
740 (dopage
|| (cp
= ok_vlook(crt
)) != NULL
)) {
741 char const *pager
= NULL
;
744 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
745 mp
= &message
[*ip
- 1];
746 if (!(mp
->m_have
& HAVE_BODY
))
747 if (get_body(mp
) != OKAY
) {
751 nlines
+= mp
->m_lines
;
754 if (dopage
|| UICMP(z
, nlines
, >,
755 (*cp
!= '\0' ? atoi(cp
) : realscreenheight
))) {
758 if ((cp
= getenv("LESS")) == NULL
) /* XXX not here! */
759 setenv("LESS", "FRXi", 0); /* XXX add env. */
761 obuf
= Popen(pager
, "w", NULL
, 1);
764 unsetenv("LESS"); /* XXX to Popen() etc.?!! */
771 safe_signal(SIGPIPE
, &_cmd1_brokpipe
);
774 if (action
!= SEND_MBOX
)
775 colour_table_create(pager
); /* (salloc()s!) */
779 else if ((options
& OPT_TTYOUT
) && action
!= SEND_MBOX
)
780 colour_table_create(NULL
); /* (salloc()s!) */
783 /* This may jump, in which case srelax_rele() wouldn't be called, but
784 * it shouldn't matter, because we -- then -- directly reenter the
785 * lex.c:commands() loop, which sreset()s */
787 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
788 mp
= &message
[*ip
- 1];
795 if (action
!= SEND_MBOX
)
796 _show_msg_overview(obuf
, mp
, *ip
);
798 sendmp(mp
, obuf
, (doign
? ignore
: NULL
), NULL
, action
, mstats
);
803 tstats
[0] += mstats
[0];
804 tstats
[1] += mstats
[1];
809 if (obuf
!= stdout
) {
810 /* Ignore SIGPIPE so it can't cause a duplicate close */
811 safe_signal(SIGPIPE
, SIG_IGN
);
812 colour_reset(obuf
); /* XXX hacky; only here because we still jump */
814 safe_signal(SIGPIPE
, dflpipe
);
824 _pipe1(char *str
, int doign
)
832 if ((cmd
= laststring(str
, &needs_list
, 1)) == NULL
) {
834 if (cmd
== NULL
|| *cmd
== '\0') {
835 fputs(tr(16, "variable cmd not set\n"), stderr
);
840 msgvec
= salloc((msgCount
+ 2) * sizeof *msgvec
);
843 *msgvec
= first(0, MMNORM
);
849 puts(tr(18, "No messages to pipe."));
853 } else if (getmsglist(str
, msgvec
, 0) < 0)
860 printf("No applicable messages.\n");
864 printf(tr(268, "Pipe to: \"%s\"\n"), cmd
);
865 stats
[0] = stats
[1] = 0;
866 if ((rv
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
867 printf("\"%s\" ", cmd
);
869 printf("%lu", (long)stats
[0]);
871 printf(tr(27, "binary"));
872 printf("/%lu\n", (long)stats
[1]);
880 ccmdnotsupp(void *v
) /* TODO -> lex.c */
884 fprintf(stderr
, tr(10, "The requested feature is not compiled in\n"));
893 int *msgvec
= v
, g
, k
, n
, mesg
, size
, lastg
= 1;
894 struct message
*mp
, *mq
, *lastmq
= NULL
;
895 enum mflag fl
= MNEW
| MFLAGGED
;
898 time_current_update(&time_current
, FAL0
);
902 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
911 if (mb
.mb_threaded
== 0) {
914 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
918 if (mp
->m_flag
& fl
) {
922 if ((n
> 0 && mp
== &message
[n
- 1]) || (n
== 0 && g
== k
) ||
923 (n
== -2 && g
== k
+ size
&& lastmq
) ||
924 (n
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
928 if (lastmq
&& (n
== -2 || (n
== -1 && mp
== &message
[msgCount
]))) {
934 mesg
= (int)PTR2SIZE(mp
- message
);
935 if (dot
!= &message
[n
- 1]) {
936 for (mq
= mp
; PTRCMP(mq
, <, message
+ msgCount
); ++mq
)
943 if (mb
.mb_type
== MB_IMAP
)
944 imap_getheaders(mesg
+ 1, mesg
+ size
);
947 for (; PTRCMP(mp
, <, message
+ msgCount
); ++mp
) {
951 if (UICMP(32, flag
++, >=, size
))
953 _print_head(0, mesg
, stdout
, 0);
957 } else { /* threaded */
960 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
961 if (visible(mp
) && (mp
->m_collapsed
<= 0 || mp
== &message
[n
- 1])) {
964 if (mp
->m_flag
& fl
) {
968 if ((n
> 0 && mp
== &message
[n
- 1]) || (n
== 0 && g
== k
) ||
969 (n
== -2 && g
== k
+ size
&& lastmq
) ||
970 (n
< 0 && g
>= k
&& (mp
->m_flag
& fl
) != 0))
974 if (lastmq
&& (n
== -2 || (n
== -1 && mp
== &message
[msgCount
]))) {
980 if (dot
!= &message
[n
- 1]) {
981 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
982 if (visible(mq
) && mq
->m_collapsed
<= 0) {
989 if (visible(mp
) && (mp
->m_collapsed
<= 0 || mp
== &message
[n
- 1])) {
990 if (UICMP(32, flag
++, >=, size
))
992 _print_head(flag
- 1, PTR2SIZE(mp
- message
+ 1), stdout
,
996 mp
= next_in_thread(mp
);
1002 printf(tr(6, "No more mail.\n"));
1013 rv
= _scroll1(v
, 0);
1024 rv
= _scroll1(v
, 1);
1032 int *msgvec
= v
, *ip
, n
;
1034 FILE * volatile obuf
;
1037 time_current_update(&time_current
, FAL0
);
1040 /* TODO unfixable memory leaks still */
1041 if (IS_TTY_SESSION() && (cp
= ok_vlook(crt
)) != NULL
) {
1042 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
)
1044 if (n
> (*cp
== '\0' ? screensize() : atoi(cp
)) + 3) {
1046 if (sigsetjmp(_cmd1_pipejmp
, 1))
1049 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
1054 safe_signal(SIGPIPE
, &_cmd1_onpipe
);
1058 for (n
= 0, ip
= msgvec
; *ip
!= 0; ++ip
) /* TODO join into _print_head() */
1059 _print_head((size_t)n
++, (size_t)*ip
, obuf
, mb
.mb_threaded
);
1061 setdot(&message
[*ip
- 1]);
1064 if (obuf
!= stdout
) {
1065 safe_signal(SIGPIPE
, SIG_IGN
);
1067 safe_signal(SIGPIPE
, dflpipe
);
1074 print_headers(size_t bottom
, size_t topx
)
1080 if (mb
.mb_type
== MB_IMAP
)
1081 imap_getheaders(bottom
, topx
);
1083 time_current_update(&time_current
, FAL0
);
1085 for (printed
= 0; bottom
<= topx
; ++bottom
) /* TODO join into _print_head()*/
1086 if (visible(&message
[bottom
- 1]))
1087 _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(NULL
); /* (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 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
&& 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
, tr(20, "No value set for \"folder\"\n"));
1287 if (which_protocol(name
) == PROTO_IMAP
) {
1289 imap_folders(name
, *argv
== NULL
);
1291 rv
= ccmdnotsupp(NULL
);
1294 if ((cmd
= ok_vlook(LISTER
)) == NULL
)
1296 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);
1303 /* vim:set fenc=utf-8:s-it-mode */