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 - 2013 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
43 * Print the current active headings.
44 * Don't change dot if invoker didn't give an argument.
49 /* Prepare and print "[Message: xy]:" intro */
50 static void _show_msg_overview(struct message
*mp
, int msg_no
, FILE *obuf
);
52 static void onpipe(int signo
);
53 static int _dispc(struct message
*mp
, const char *a
);
54 static int scroll1(char *arg
, int onlynew
);
56 /* ... And place the extracted date in `date' */
57 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
59 /* Get the Subject:, but return NULL if in threaded mode and the message
60 * printed before was in the same thread and had the same subject */
61 static char * _get_subject(struct message
*mp
, bool_t threaded
);
62 static char * __subject_trim(char *s
);
64 static void hprf(const char *fmt
, int mesg
, FILE *f
, int threaded
,
65 const char *attrlist
);
66 static int putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
67 static int type1(int *msgvec
, int doign
, int page
, int pipe
, int decode
,
68 char *cmd
, off_t
*tstats
);
69 static int pipe1(char *str
, int doign
);
72 _show_msg_overview(struct message
*mp
, int msg_no
, FILE *obuf
)
74 fprintf(obuf
, tr(17, "[-- Message %2d -- %lu lines, %lu bytes --]:\n"),
75 msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
);
82 fprintf(stderr
, tr(10, "The requested feature is not compiled in\n"));
92 if (cp
== NULL
|| *cp
== '\0')
101 int g
, k
, n
, mesg
, flag
= 0, lastg
= 1;
102 struct message
*mp
, *mq
, *lastmq
= NULL
;
104 enum mflag fl
= MNEW
|MFLAGGED
;
106 time_current_update(&time_current
, FAL0
);
109 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
117 if (mb
.mb_threaded
== 0) {
120 for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
128 if ((n
> 0 && mp
== &message
[n
-1]) ||
129 (n
== 0 && g
== k
) ||
130 (n
== -2 && g
== k
+ size
&&
133 (mp
->m_flag
& fl
) != 0))
137 if (lastmq
&& (n
==-2 || (n
==-1 && mp
== &message
[msgCount
]))) {
143 mesg
= mp
- &message
[0];
144 if (dot
!= &message
[n
-1]) {
145 for (mq
= mp
; mq
< &message
[msgCount
]; mq
++)
152 if (mb
.mb_type
== MB_IMAP
)
153 imap_getheaders(mesg
+1, mesg
+ size
);
155 for (; mp
< &message
[msgCount
]; mp
++) {
161 printhead(mesg
, stdout
, 0);
163 } else { /* threaded */
166 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
167 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
168 mp
== &message
[n
-1])) {
175 if ((n
> 0 && mp
== &message
[n
-1]) ||
176 (n
== 0 && g
== k
) ||
177 (n
== -2 && g
== k
+ size
&&
180 (mp
->m_flag
& fl
) != 0))
184 if (lastmq
&& (n
==-2 || (n
==-1 && mp
==&message
[msgCount
]))) {
190 if (dot
!= &message
[n
-1]) {
191 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
192 if (visible(mq
) && mq
->m_collapsed
<= 0) {
198 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
199 mp
== &message
[n
-1])) {
202 printhead(mp
- &message
[0] + 1, stdout
,
205 mp
= next_in_thread(mp
);
209 printf(tr(6, "No more mail.\n"));
216 * Scroll to the next/previous screen
221 return scroll1(v
, 0);
227 return scroll1(v
, 1);
231 scroll1(char *arg
, int onlynew
)
236 cur
[0] = onlynew
? -1 : 0;
239 case '1': case '2': case '3': case '4': case '5':
240 case '6': case '7': case '8': case '9': case '0':
247 screen
= msgCount
/ size
;
253 screen
+= atoi(arg
+ 1);
255 if (screen
* size
> msgCount
) {
256 screen
= msgCount
/ size
;
257 printf(tr(7, "On last screenful of messages\n"));
265 screen
-= atoi(arg
+ 1);
268 printf(tr(8, "On first screenful of messages\n"));
275 printf(tr(9, "Unrecognized scrolling command \"%s\"\n"), arg
);
278 return(headers(cur
));
282 * Compute screen size.
290 if ((cp
= value("screen")) != NULL
&& (s
= atoi(cp
)) > 0)
292 return scrnheight
- 4;
295 static sigjmp_buf pipejmp
;
302 siglongjmp(pipejmp
, 1);
306 * Print out the headlines for each message
307 * in the passed message list.
312 int *msgvec
= v
, *ip
, n
;
314 FILE *volatile obuf
= stdout
;
316 time_current_update(&time_current
, FAL0
);
318 /* TODO unfixable memory leaks still */
319 if (IS_TTY_SESSION() && (cp
= value("crt")) != NULL
) {
320 for (n
= 0, ip
= msgvec
; *ip
; ip
++)
322 if (n
> (*cp
== '\0' ? screensize() : atoi((char*)cp
)) + 3) {
324 if (sigsetjmp(pipejmp
, 1))
327 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
332 safe_signal(SIGPIPE
, onpipe
);
335 for (ip
= msgvec
; *ip
!= 0; ip
++)
336 printhead(*ip
, obuf
, mb
.mb_threaded
);
338 setdot(&message
[*ip
- 1]);
340 if (obuf
!= stdout
) {
341 safe_signal(SIGPIPE
, SIG_IGN
);
343 safe_signal(SIGPIPE
, dflpipe
);
349 _dispc(struct message
*mp
, const char *a
)
356 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MREAD
)
358 if ((mp
->m_flag
& (MREAD
|MNEW
)) == (MREAD
|MNEW
))
360 if (mp
->m_flag
& MANSWERED
)
362 if (mp
->m_flag
& MDRAFTED
)
364 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
366 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
368 if (mp
->m_flag
& MSPAM
)
370 if (mp
->m_flag
& MSAVED
)
372 if (mp
->m_flag
& MPRESERVE
)
374 if (mp
->m_flag
& (MBOX
|MBOXED
))
376 if (mp
->m_flag
& MFLAGGED
)
378 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
380 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
386 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
])
393 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
394 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
395 (void)extract_date_from_from_(hline
, hlen
, date
);
401 __subject_trim(char *s
)
404 while (spacechar(*s
))
406 if (is_asccaseprefix("re:", s
)) {
410 if (is_asccaseprefix("fwd:", s
)) {
420 _get_subject(struct message
*mp
, bool_t threaded
)
423 char *rv
= (char*)-1, *ms
, *mso
, *os
;
425 if ((ms
= hfield1("subject", mp
)) == NULL
)
428 if (! threaded
|| mp
->m_level
== 0)
431 /* In a display thread - check wether this message uses the same
432 * Subject: as it's parent or elder neighbour, suppress printing it if
433 * this is the case. To extend this a bit, ignore any leading Re: or
434 * Fwd: plus follow-up WS; XXX NOTE: because of efficiency reasons we
435 * XXX simply ignore any encoded parts and use ASCII case-insensitive
437 mso
= __subject_trim(ms
);
439 if (mp
->m_elder
!= NULL
&&
440 (os
= hfield1("subject", mp
->m_elder
)) != NULL
&&
441 asccasecmp(mso
, __subject_trim(os
)) == 0)
444 if (mp
->m_parent
!= NULL
&&
445 (os
= hfield1("subject", mp
->m_parent
)) != NULL
&&
446 asccasecmp(mso
, __subject_trim(os
)) == 0)
452 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
459 hprf(const char *fmt
, int mesg
, FILE *f
, int threaded
, const char *attrlist
)
461 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
462 char const *datefmt
, *date
, *name
, *fp
;
463 int B
, c
, i
, n
, s
, wleft
, subjlen
, isto
= 0, isaddr
= 0;
464 struct message
*mp
= &message
[mesg
- 1];
465 time_t datet
= mp
->m_time
;
468 if ((datefmt
= value("datefield")) != NULL
) {
469 fp
= hfield1("date", mp
);/* TODO use m_date field! */
475 date
= fakedate(datet
);
476 fp
= value("datefield-markout-older");
477 i
= (*datefmt
!= '\0');
479 i
|= (*fp
!= '\0') ? 2 | 4 : 2;
480 /* May we strftime(3)? */
482 memcpy(&time_current
.tc_local
, localtime(&datet
),
483 sizeof time_current
.tc_local
);
485 /* TODO *datefield-markout-older* we accept
486 * TODO one day in the future, should be UTC
487 * TODO offset only? and Stephen Isard had
488 * TODO one week once he proposed the patch! */
489 (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
490 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
491 (datet
+ _6M
< time_current
.tc_time
))) {
493 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
494 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
495 memcpy(datebuf
+ 4, date
+ 4, 7);
496 datebuf
[4 + 7] = ' ';
497 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
498 datebuf
[4 + 7 + 1 + 4] = '\0';
501 } else if ((i
& 1) == 0)
503 } else if (datet
== (time_t)0 && (mp
->m_flag
& MNOFROM
) == 0) {
504 /* TODO eliminate this path, query the FROM_ date in setptr(),
505 * TODO all other codepaths do so by themselves ALREADY ?????
506 * TODO assert(mp->m_time != 0);, then
507 * TODO ALSO changes behaviour of markout-non-current */
508 _parse_from_(mp
, datebuf
);
512 date
= fakedate(datet
);
517 if (name
!= NULL
&& value("showto") && is_myname(skin(name
))) {
518 if ((cp
= hfield1("to", mp
)) != NULL
) {
528 if (value("showname"))
529 name
= realname(name
);
531 name
= prstr(skin(name
));
537 /* Detect the width of the non-format characters in *headline*;
538 * like that we can simply use putc() in the next loop, since we have
539 * already calculated their column widths (TODO it's sick) */
543 for (fp
= fmt
; *fp
; ++fp
) {
547 } else if (*fp
== '+')
549 if (digitchar(*fp
)) {
552 n
= 10*n
+ *fp
- '0';
553 while (++fp
, digitchar(*fp
));
560 #if defined HAVE_MBTOWC && defined HAVE_WCWIDTH
561 if (mb_cur_max
> 1) {
563 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) < 0)
565 else if ((n
= wcwidth(wc
)) < 0)
577 /* Walk *headline*, producing output */
578 for (fp
= fmt
; *fp
; ++fp
) {
579 if ((c
= *fp
& 0xFF) == '%') {
586 } else if (*fp
== '+')
588 if (digitchar(*fp
)) {
590 n
= 10*n
+ *fp
- '0';
591 while (++fp
, digitchar(*fp
));
597 switch ((c
= *fp
& 0xFF)) {
606 c
= _dispc(mp
, attrlist
);
609 n
= (n
< 0) ? -wleft
: wleft
;
610 n
= fprintf(f
, "%*c", n
, c
);
611 wleft
= (n
>= 0) ? wleft
- n
: 0;
617 for (i
=msgCount
; i
>999; i
/=10)
621 n
= (n
< 0) ? -wleft
: wleft
;
622 n
= fprintf(f
, "%*d", n
, mesg
);
623 wleft
= (n
>= 0) ? wleft
- n
: 0;
634 n
= (n
< 0) ? -wleft
: wleft
;
636 if (isto
) /* XXX tr()! */
638 n
= fprintf(f
, "%s%s", (isto
? "To " : ""),
639 colalign(name
, i
, n
, &wleft
));
646 if (datefmt
!= NULL
) {
647 i
= strftime(datebuf
, sizeof datebuf
,
649 &time_current
.tc_local
);
653 fprintf(stderr
, tr(174,
654 "Ignored date format, "
658 (ul_it
)sizeof datebuf
);
664 n
= (n
< 0) ? -wleft
: wleft
;
665 n
= fprintf(f
, "%*.*s", n
, n
, date
);
666 wleft
= (n
>= 0) ? wleft
- n
: 0;
672 n
= (n
< 0) ? -wleft
: wleft
;
674 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
675 wleft
= (n
>= 0) ? wleft
- n
: 0;
687 n
= (n
< 0) ? -wleft
: wleft
;
688 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
689 wleft
= (n
>= 0) ? wleft
- n
: 0;
693 n
= putindent(f
, mp
, MIN(wleft
,
695 wleft
= (n
>= 0) ? wleft
- n
: 0;
708 if (ABS(n
) > subjlen
)
709 n
= (n
< 0) ? -subjlen
: subjlen
;
711 n
-= (n
< 0) ? -2 : 2;
714 if (subjline
== NULL
)
715 subjline
= _get_subject(mp
, threaded
);
716 if (subjline
== (char*)-1) {
717 n
= fprintf(f
, "%*s", n
, "");
718 wleft
= (n
>= 0) ? wleft
-n
: 0;
720 n
= fprintf(f
, (B
? "\"%s\"" : "%s"),
721 colalign(subjline
, ABS(n
), n
,
732 n
= (n
< 0) ? -wleft
: wleft
;
733 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
734 wleft
= (n
>= 0) ? wleft
- n
: 0;
744 n
= (n
< 0) ? -wleft
: wleft
;
745 n
= fprintf(f
, "%*u", n
,
746 threaded
== 1 ? mp
->m_level
: 0);
747 wleft
= (n
>= 0) ? wleft
- n
: 0;
753 for (i
=msgCount
; i
>999; i
/=10)
757 n
= (n
< 0) ? -wleft
: wleft
;
758 n
= fprintf(f
, "%*ld", n
,
759 threaded
? mp
->m_threadpos
: mesg
);
760 wleft
= (n
>= 0) ? wleft
- n
: 0;
767 n
= (n
< 0) ? -wleft
: wleft
;
769 snprintf(buf
, sizeof buf
, "%u.%u",
770 (mp
->m_spamscore
>> 8),
771 (mp
->m_spamscore
& 0xFF));
772 n
= fprintf(f
, "%*s", n
, buf
);
773 wleft
= (n
>= 0) ? wleft
- n
: 0;
788 if (subjline
!= NULL
&& subjline
!= (char*)-1)
793 * Print out the indenting in threaded display.
796 putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
799 int *us
, indlvl
, indw
, i
, important
= MNEW
|MFLAGGED
;
802 if (mp
->m_level
== 0 || maxwidth
== 0)
804 cs
= ac_alloc(mp
->m_level
);
805 us
= ac_alloc(mp
->m_level
* sizeof *us
);
808 if (mp
->m_younger
&& (unsigned)i
+ 1 == mp
->m_younger
->m_level
) {
809 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
810 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
812 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
815 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
816 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
818 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
823 for (i
= mp
->m_level
- 2; i
>= 0; i
--) {
825 if ((unsigned)i
> mq
->m_level
- 1) {
831 mq
->m_parent
->m_flag
&important
)
844 for (indlvl
= indw
= 0; (uc_it
)indlvl
< mp
->m_level
&&
845 indw
< maxwidth
; ++indlvl
) {
846 if (indw
< maxwidth
- 1)
847 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0377, fp
);
849 indw
+= (int)putuc(0x21B8, '^', fp
);
851 indw
+= /*putuc(0x261E, fp)*/putc('>', fp
) != EOF
;
859 printhead(int mesg
, FILE *f
, int threaded
)
861 int bsdflags
, bsdheadline
, sz
;
862 char attrlist
[30], *cp
;
865 bsdflags
= value("bsdcompat") != NULL
|| value("bsdflags") != NULL
||
866 getenv("SYSV3") != NULL
;
867 strcpy(attrlist
, bsdflags
? "NU *HMFAT+-$" : "NUROSPMFAT+-$");
868 if ((cp
= value("attrlist")) != NULL
) {
870 if (sz
> (int)sizeof attrlist
- 1)
871 sz
= (int)sizeof attrlist
- 1;
872 memcpy(attrlist
, cp
, sz
);
874 bsdheadline
= value("bsdcompat") != NULL
||
875 value("bsdheadline") != NULL
;
876 if ((fmt
= value("headline")) == NULL
)
878 "%>%a%m %-20f %16d %3l/%-5o %i%-S" :
879 "%>%a%m %-18f %16d %4l/%-5o %i%-s";
880 hprf(fmt
, mesg
, f
, threaded
, attrlist
);
884 * Print out the value of dot.
891 printf("%d\n", (int)(dot
- &message
[0] + 1));
896 * Type out the messages requested.
898 static sigjmp_buf pipestop
;
905 siglongjmp(pipestop
, 1);
909 type1(int *msgvec
, int doign
, int page
, int pipe
, int decode
,
910 char *cmd
, off_t
*tstats
)
920 if (sigsetjmp(pipestop
, 1))
926 obuf
= Popen(cmd
, "w", cp
, 1);
931 safe_signal(SIGPIPE
, brokpipe
);
933 } else if ((options
& OPT_TTYOUT
) &&
934 (page
|| (cp
= value("crt")) != NULL
)) {
937 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
938 if ((message
[*ip
-1].m_have
& HAVE_BODY
) == 0) {
939 if ((get_body(&message
[*ip
- 1])) !=
943 nlines
+= message
[*ip
- 1].m_lines
;
946 if (page
|| nlines
> (*cp
? atoi(cp
) : realscreenheight
)) {
947 char const *p
= get_pager();
948 obuf
= Popen(p
, "w", NULL
, 1);
953 safe_signal(SIGPIPE
, brokpipe
);
956 for (ip
= msgvec
; *ip
&& ip
- msgvec
< msgCount
; ip
++) {
957 mp
= &message
[*ip
- 1];
961 if (! pipe
&& ip
!= msgvec
)
963 _show_msg_overview(mp
, *ip
, obuf
);
964 sendmp(mp
, obuf
, doign
? ignore
: 0, NULL
,
965 pipe
&& value("piperaw") ? SEND_MBOX
:
967 doign
? SEND_TODISP
: SEND_TODISP_ALL
,
969 if (pipe
&& value("page")) {
973 tstats
[0] += mstats
[0];
974 tstats
[1] += mstats
[1];
978 if (obuf
!= stdout
) {
980 * Ignore SIGPIPE so it can't cause a duplicate close.
982 safe_signal(SIGPIPE
, SIG_IGN
);
984 safe_signal(SIGPIPE
, dflpipe
);
990 * Get the last, possibly quoted part of linebuf.
993 laststring(char *linebuf
, int *flag
, int strip
)
999 cp
= strlen(linebuf
) + linebuf
- 1;
1002 * Strip away trailing blanks.
1004 while (cp
> linebuf
&& whitechar(*cp
& 0377))
1007 if (cp
== linebuf
) {
1013 * Now search for the beginning of the command name.
1016 if (quoted
== '\'' || quoted
== '\"') {
1021 while (cp
> linebuf
) {
1022 if (*cp
!= quoted
) {
1024 } else if (*(cp
- 1) != '\\') {
1036 if (*cp
== quoted
) {
1042 while (cp
> linebuf
&& !whitechar(*cp
& 0377))
1044 if (whitechar(*cp
& 0377))
1056 * Pipe the messages requested.
1059 pipe1(char *str
, int doign
)
1062 int f
, *msgvec
, ret
;
1066 msgvec
= (int *)salloc((msgCount
+ 2) * sizeof *msgvec
);
1067 if ((cmd
= laststring(str
, &f
, 1)) == NULL
) {
1069 if (cmd
== NULL
|| *cmd
== '\0') {
1070 fputs(tr(16, "variable cmd not set\n"), stderr
);
1075 *msgvec
= first(0, MMNORM
);
1079 puts(tr(18, "No messages to pipe."));
1083 } else if (getmsglist(str
, msgvec
, 0) < 0)
1088 printf("No applicable messages.\n");
1091 printf(tr(268, "Pipe to: \"%s\"\n"), cmd
);
1092 stats
[0] = stats
[1] = 0;
1093 if ((ret
= type1(msgvec
, doign
, 0, 1, 0, cmd
, stats
)) == 0) {
1094 printf("\"%s\" ", cmd
);
1096 printf("%lu", (long)stats
[0]);
1098 printf(tr(27, "binary"));
1099 printf("/%lu\n", (long)stats
[1]);
1105 * Paginate messages, honor ignored fields.
1111 return (type1(msgvec
, 1, 1, 0, 0, NULL
, NULL
));
1115 * Paginate messages, even printing ignored fields.
1122 return (type1(msgvec
, 0, 1, 0, 0, NULL
, NULL
));
1126 * Type out messages, honor ignored fields.
1133 return(type1(msgvec
, 1, 0, 0, 0, NULL
, NULL
));
1137 * Type out messages, even printing ignored fields.
1144 return(type1(msgvec
, 0, 0, 0, 0, NULL
, NULL
));
1148 * Show MIME-encoded message text, including all fields.
1155 return(type1(msgvec
, 0, 0, 0, 1, NULL
, NULL
));
1159 * Pipe messages, honor ignored fields.
1165 return(pipe1(str
, 1));
1168 * Pipe messages, not respecting ignored fields.
1174 return(pipe1(str
, 0));
1178 * Print the top so many lines of each desired message.
1179 * The number of lines is taken from the variable "toplines"
1180 * and defaults to 5.
1185 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1187 char *cp
, *linebuf
= NULL
;
1192 cp
= value("toplines");
1195 if (topl
< 0 || topl
> 10000)
1199 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
1200 mp
= &message
[*ip
- 1];
1203 did_print_dot
= TRU1
;
1206 _show_msg_overview(mp
, *ip
, stdout
);
1207 if (mp
->m_flag
& MNOFROM
)
1208 printf("From %s %s\n", fakefrom(mp
),
1209 fakedate(mp
->m_time
));
1210 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1215 for (lines
= 0; lines
< c
&& lines
<= topl
; lines
++) {
1216 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1220 for (cp
= linebuf
; *cp
&& blankchar(*cp
); ++cp
)
1222 empty_last
= (*cp
== '\0');
1226 if (linebuf
!= NULL
)
1232 * Touch all the given messages so that they will
1241 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1242 setdot(&message
[*ip
-1]);
1243 dot
->m_flag
|= MTOUCH
;
1244 dot
->m_flag
&= ~MPRESERVE
;
1246 * POSIX interpretation necessary.
1248 did_print_dot
= TRU1
;
1254 * Make sure all passed messages get mboxed.
1262 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1263 setdot(&message
[*ip
-1]);
1264 dot
->m_flag
|= MTOUCH
|MBOX
;
1265 dot
->m_flag
&= ~MPRESERVE
;
1267 * POSIX interpretation necessary.
1269 did_print_dot
= TRU1
;
1275 * List the folders the user currently has.
1280 char dirname
[MAXPATHLEN
], *name
, **argv
= v
;
1284 name
= expand(*argv
);
1287 } else if (! getfold(dirname
, sizeof dirname
)) {
1288 fprintf(stderr
, tr(20, "No value set for \"folder\"\n"));
1293 if (which_protocol(name
) == PROTO_IMAP
) {
1295 imap_folders(name
, *argv
== NULL
);
1297 return ccmdnotsupp(NULL
);
1300 if ((cmd
= value("LISTER")) == NULL
)
1302 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);