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
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(struct message
*mp
, int msg_no
, FILE *obuf
);
54 static void _cmd1_onpipe(int signo
);
55 static int _dispc(struct message
*mp
, const char *a
);
56 static int scroll1(char *arg
, int onlynew
);
58 /* ... And place the extracted date in `date' */
59 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
61 /* Get the Subject:, but return NULL if in threaded mode and the message
62 * printed before was in the same thread and had the same subject */
63 static char * _get_subject(struct message
*mp
, bool_t threaded
);
64 static char * __subject_trim(char *s
);
66 static void hprf(const char *fmt
, int mesg
, FILE *f
, int threaded
,
67 const char *attrlist
);
68 static int putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
69 static int _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
70 bool_t dodecode
, char *cmd
, off_t
*tstats
);
71 static int pipe1(char *str
, int doign
);
74 _show_msg_overview(struct message
*mp
, int msg_no
, FILE *obuf
)
76 fprintf(obuf
, tr(17, "[-- Message %2d -- %lu lines, %lu bytes --]:\n"),
77 msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
);
84 fprintf(stderr
, tr(10, "The requested feature is not compiled in\n"));
94 if (cp
== NULL
|| *cp
== '\0')
103 int *msgvec
= v
, g
, k
, n
, mesg
, size
, lastg
= 1;
104 struct message
*mp
, *mq
, *lastmq
= NULL
;
105 enum mflag fl
= MNEW
|MFLAGGED
;
107 time_current_update(&time_current
, FAL0
);
111 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
120 if (mb
.mb_threaded
== 0) {
123 for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
131 if ((n
> 0 && mp
== &message
[n
-1]) ||
132 (n
== 0 && g
== k
) ||
133 (n
== -2 && g
== k
+ size
&&
136 (mp
->m_flag
& fl
) != 0))
140 if (lastmq
&& (n
==-2 || (n
==-1 && mp
== &message
[msgCount
]))) {
146 mesg
= mp
- &message
[0];
147 if (dot
!= &message
[n
-1]) {
148 for (mq
= mp
; mq
< &message
[msgCount
]; mq
++)
155 if (mb
.mb_type
== MB_IMAP
)
156 imap_getheaders(mesg
+1, mesg
+ size
);
159 for (; mp
< &message
[msgCount
]; mp
++) {
163 if (UICMP(32, flag
++, >=, size
))
165 printhead(mesg
, stdout
, 0);
169 } else { /* threaded */
172 for (mp
= threadroot
; mp
; mp
= next_in_thread(mp
))
173 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
174 mp
== &message
[n
-1])) {
181 if ((n
> 0 && mp
== &message
[n
-1]) ||
182 (n
== 0 && g
== k
) ||
183 (n
== -2 && g
== k
+ size
&&
186 (mp
->m_flag
& fl
) != 0))
190 if (lastmq
&& (n
==-2 || (n
==-1 && mp
==&message
[msgCount
]))) {
196 if (dot
!= &message
[n
-1]) {
197 for (mq
= mp
; mq
; mq
= next_in_thread(mq
))
198 if (visible(mq
) && mq
->m_collapsed
<= 0) {
205 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
206 mp
== &message
[n
-1])) {
207 if (UICMP(32, flag
++, >=, size
))
209 printhead(mp
- &message
[0] + 1, stdout
,
213 mp
= next_in_thread(mp
);
218 printf(tr(6, "No more mail.\n"));
223 * Scroll to the next/previous screen
228 return scroll1(v
, 0);
234 return scroll1(v
, 1);
238 scroll1(char *arg
, int onlynew
)
243 cur
[0] = onlynew
? -1 : 0;
246 case '1': case '2': case '3': case '4': case '5':
247 case '6': case '7': case '8': case '9': case '0':
254 screen
= msgCount
/ size
;
260 screen
+= atoi(arg
+ 1);
262 if (screen
* size
> msgCount
) {
263 screen
= msgCount
/ size
;
264 printf(tr(7, "On last screenful of messages\n"));
272 screen
-= atoi(arg
+ 1);
275 printf(tr(8, "On first screenful of messages\n"));
282 printf(tr(9, "Unrecognized scrolling command \"%s\"\n"), arg
);
285 return(headers(cur
));
289 * Compute screen size.
297 if ((cp
= value("screen")) != NULL
&& (s
= atoi(cp
)) > 0)
299 return scrnheight
- 4;
302 static sigjmp_buf _cmd1_pipejmp
;
306 _cmd1_onpipe(int signo
)
309 siglongjmp(_cmd1_pipejmp
, 1);
313 * Print out the headlines for each message
314 * in the passed message list.
319 int *msgvec
= v
, *ip
, n
;
321 FILE *volatile obuf
= stdout
;
323 time_current_update(&time_current
, FAL0
);
325 /* TODO unfixable memory leaks still */
326 if (IS_TTY_SESSION() && (cp
= value("crt")) != NULL
) {
327 for (n
= 0, ip
= msgvec
; *ip
; ip
++)
329 if (n
> (*cp
== '\0' ? screensize() : atoi((char*)cp
)) + 3) {
331 if (sigsetjmp(_cmd1_pipejmp
, 1))
334 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
339 safe_signal(SIGPIPE
, _cmd1_onpipe
);
342 for (ip
= msgvec
; *ip
!= 0; ip
++)
343 printhead(*ip
, obuf
, mb
.mb_threaded
);
345 setdot(&message
[*ip
- 1]);
347 if (obuf
!= stdout
) {
348 safe_signal(SIGPIPE
, SIG_IGN
);
350 safe_signal(SIGPIPE
, dflpipe
);
356 _dispc(struct message
*mp
, const char *a
)
363 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MREAD
)
365 if ((mp
->m_flag
& (MREAD
|MNEW
)) == (MREAD
|MNEW
))
367 if (mp
->m_flag
& MANSWERED
)
369 if (mp
->m_flag
& MDRAFTED
)
371 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
373 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
375 if (mp
->m_flag
& MSPAM
)
377 if (mp
->m_flag
& MSAVED
)
379 if (mp
->m_flag
& MPRESERVE
)
381 if (mp
->m_flag
& (MBOX
|MBOXED
))
383 if (mp
->m_flag
& MFLAGGED
)
385 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
387 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
393 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
])
400 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
401 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
402 (void)extract_date_from_from_(hline
, hlen
, date
);
408 __subject_trim(char *s
)
411 while (spacechar(*s
))
413 if (is_asccaseprefix("re:", s
)) {
417 if (is_asccaseprefix("fwd:", s
)) {
427 _get_subject(struct message
*mp
, bool_t threaded
)
430 char *rv
= (char*)-1, *ms
, *mso
, *os
;
432 if ((ms
= hfield1("subject", mp
)) == NULL
)
435 if (! threaded
|| mp
->m_level
== 0)
438 /* In a display thread - check wether this message uses the same
439 * Subject: as it's parent or elder neighbour, suppress printing it if
440 * this is the case. To extend this a bit, ignore any leading Re: or
441 * Fwd: plus follow-up WS; XXX NOTE: because of efficiency reasons we
442 * XXX simply ignore any encoded parts and use ASCII case-insensitive
444 mso
= __subject_trim(ms
);
446 if (mp
->m_elder
!= NULL
&&
447 (os
= hfield1("subject", mp
->m_elder
)) != NULL
&&
448 asccasecmp(mso
, __subject_trim(os
)) == 0)
451 if (mp
->m_parent
!= NULL
&&
452 (os
= hfield1("subject", mp
->m_parent
)) != NULL
&&
453 asccasecmp(mso
, __subject_trim(os
)) == 0)
459 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
466 hprf(const char *fmt
, int mesg
, FILE *f
, int threaded
, const char *attrlist
)
468 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
469 char const *datefmt
, *date
, *name
, *fp
;
470 int B
, c
, i
, n
, s
, wleft
, subjlen
, isto
= 0, isaddr
= 0;
471 struct message
*mp
= &message
[mesg
- 1];
472 time_t datet
= mp
->m_time
;
475 if ((datefmt
= value("datefield")) != NULL
) {
476 fp
= hfield1("date", mp
);/* TODO use m_date field! */
482 date
= fakedate(datet
);
483 fp
= value("datefield-markout-older");
484 i
= (*datefmt
!= '\0');
486 i
|= (*fp
!= '\0') ? 2 | 4 : 2;
487 /* May we strftime(3)? */
489 memcpy(&time_current
.tc_local
, localtime(&datet
),
490 sizeof time_current
.tc_local
);
492 /* TODO *datefield-markout-older* we accept
493 * TODO one day in the future, should be UTC
494 * TODO offset only? and Stephen Isard had
495 * TODO one week once he proposed the patch! */
496 (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
497 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
498 (datet
+ _6M
< time_current
.tc_time
))) {
500 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
501 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
502 memcpy(datebuf
+ 4, date
+ 4, 7);
503 datebuf
[4 + 7] = ' ';
504 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
505 datebuf
[4 + 7 + 1 + 4] = '\0';
508 } else if ((i
& 1) == 0)
510 } else if (datet
== (time_t)0 && (mp
->m_flag
& MNOFROM
) == 0) {
511 /* TODO eliminate this path, query the FROM_ date in setptr(),
512 * TODO all other codepaths do so by themselves ALREADY ?????
513 * TODO assert(mp->m_time != 0);, then
514 * TODO ALSO changes behaviour of markout-non-current */
515 _parse_from_(mp
, datebuf
);
519 date
= fakedate(datet
);
524 if (name
!= NULL
&& value("showto") && is_myname(skin(name
))) {
525 if ((cp
= hfield1("to", mp
)) != NULL
) {
535 if (value("showname"))
536 name
= realname(name
);
538 name
= prstr(skin(name
));
544 /* Detect the width of the non-format characters in *headline*;
545 * like that we can simply use putc() in the next loop, since we have
546 * already calculated their column widths (TODO it's sick) */
550 for (fp
= fmt
; *fp
; ++fp
) {
554 } else if (*fp
== '+')
556 if (digitchar(*fp
)) {
559 n
= 10*n
+ *fp
- '0';
560 while (++fp
, digitchar(*fp
));
567 #if defined HAVE_MBTOWC && defined HAVE_WCWIDTH
568 if (mb_cur_max
> 1) {
570 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) < 0)
572 else if ((n
= wcwidth(wc
)) < 0)
584 /* Walk *headline*, producing output */
585 for (fp
= fmt
; *fp
; ++fp
) {
586 if ((c
= *fp
& 0xFF) == '%') {
593 } else if (*fp
== '+')
595 if (digitchar(*fp
)) {
597 n
= 10*n
+ *fp
- '0';
598 while (++fp
, digitchar(*fp
));
604 switch ((c
= *fp
& 0xFF)) {
613 c
= _dispc(mp
, attrlist
);
615 if (UICMP(32, ABS(n
), >, wleft
))
616 n
= (n
< 0) ? -wleft
: wleft
;
617 n
= fprintf(f
, "%*c", n
, c
);
618 wleft
= (n
>= 0) ? wleft
- n
: 0;
624 for (i
=msgCount
; i
>999; i
/=10)
627 if (UICMP(32, ABS(n
), >, wleft
))
628 n
= (n
< 0) ? -wleft
: wleft
;
629 n
= fprintf(f
, "%*d", n
, mesg
);
630 wleft
= (n
>= 0) ? wleft
- n
: 0;
641 n
= (n
< 0) ? -wleft
: wleft
;
643 if (isto
) /* XXX tr()! */
645 n
= fprintf(f
, "%s%s", (isto
? "To " : ""),
646 colalign(name
, i
, n
, &wleft
));
653 if (datefmt
!= NULL
) {
654 i
= strftime(datebuf
, sizeof datebuf
,
656 &time_current
.tc_local
);
660 fprintf(stderr
, tr(174,
661 "Ignored date format, "
665 (ul_it
)sizeof datebuf
);
670 if (UICMP(32, ABS(n
), >, wleft
))
671 n
= (n
< 0) ? -wleft
: wleft
;
672 n
= fprintf(f
, "%*.*s", n
, n
, date
);
673 wleft
= (n
>= 0) ? wleft
- n
: 0;
678 if (UICMP(32, ABS(n
), >, wleft
))
679 n
= (n
< 0) ? -wleft
: wleft
;
681 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
682 wleft
= (n
>= 0) ? wleft
- n
: 0;
693 if (UICMP(32, ABS(n
), >, wleft
))
694 n
= (n
< 0) ? -wleft
: wleft
;
695 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
696 wleft
= (n
>= 0) ? wleft
- n
: 0;
700 n
= putindent(f
, mp
, MIN(wleft
,
702 wleft
= (n
>= 0) ? wleft
- n
: 0;
715 if (UICMP(32, ABS(n
), >, subjlen
))
716 n
= (n
< 0) ? -subjlen
: subjlen
;
718 n
-= (n
< 0) ? -2 : 2;
721 if (subjline
== NULL
)
722 subjline
= _get_subject(mp
, threaded
);
723 if (subjline
== (char*)-1) {
724 n
= fprintf(f
, "%*s", n
, "");
725 wleft
= (n
>= 0) ? wleft
-n
: 0;
727 n
= fprintf(f
, (B
? "\"%s\"" : "%s"),
728 colalign(subjline
, ABS(n
), n
,
738 if (UICMP(32, ABS(n
), >, wleft
))
739 n
= (n
< 0) ? -wleft
: wleft
;
740 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
741 wleft
= (n
>= 0) ? wleft
- n
: 0;
750 if (UICMP(32, ABS(n
), >, wleft
))
751 n
= (n
< 0) ? -wleft
: wleft
;
752 n
= fprintf(f
, "%*u", n
,
753 threaded
== 1 ? mp
->m_level
: 0);
754 wleft
= (n
>= 0) ? wleft
- n
: 0;
760 for (i
=msgCount
; i
>999; i
/=10)
763 if (UICMP(32, ABS(n
), >, wleft
))
764 n
= (n
< 0) ? -wleft
: wleft
;
765 n
= fprintf(f
, "%*ld", n
,
766 threaded
? mp
->m_threadpos
: mesg
);
767 wleft
= (n
>= 0) ? wleft
- n
: 0;
773 if (UICMP(32, ABS(n
), >, wleft
))
774 n
= (n
< 0) ? -wleft
: wleft
;
776 snprintf(buf
, sizeof buf
, "%u.%u",
777 (mp
->m_spamscore
>> 8),
778 (mp
->m_spamscore
& 0xFF));
779 n
= fprintf(f
, "%*s", n
, buf
);
780 wleft
= (n
>= 0) ? wleft
- n
: 0;
795 if (subjline
!= NULL
&& subjline
!= (char*)-1)
800 * Print out the indenting in threaded display.
803 putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
806 int *us
, indlvl
, indw
, i
, important
= MNEW
|MFLAGGED
;
809 if (mp
->m_level
== 0 || maxwidth
== 0)
811 cs
= ac_alloc(mp
->m_level
);
812 us
= ac_alloc(mp
->m_level
* sizeof *us
);
815 if (mp
->m_younger
&& UICMP(32, i
+ 1, ==, mp
->m_younger
->m_level
)) {
816 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
817 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
819 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
822 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
823 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
825 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
830 for (i
= mp
->m_level
- 2; i
>= 0; i
--) {
832 if (UICMP(32, i
, >, mq
->m_level
- 1)) {
838 mq
->m_parent
->m_flag
&important
)
851 for (indlvl
= indw
= 0; (uc_it
)indlvl
< mp
->m_level
&&
852 indw
< maxwidth
; ++indlvl
) {
853 if (indw
< maxwidth
- 1)
854 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0377, fp
);
856 indw
+= (int)putuc(0x21B8, '^', fp
);
858 indw
+= /*putuc(0x261E, fp)*/putc('>', fp
) != EOF
;
866 printhead(int mesg
, FILE *f
, int threaded
)
868 int bsdflags
, bsdheadline
, sz
;
869 char attrlist
[30], *cp
;
872 bsdflags
= value("bsdcompat") != NULL
|| value("bsdflags") != NULL
||
873 getenv("SYSV3") != NULL
;
874 strcpy(attrlist
, bsdflags
? "NU *HMFAT+-$" : "NUROSPMFAT+-$");
875 if ((cp
= value("attrlist")) != NULL
) {
877 if (UICMP(32, sz
, >, sizeof attrlist
- 1))
878 sz
= (int)sizeof attrlist
- 1;
879 memcpy(attrlist
, cp
, sz
);
881 bsdheadline
= value("bsdcompat") != NULL
||
882 value("bsdheadline") != NULL
;
883 if ((fmt
= value("headline")) == NULL
)
885 "%>%a%m %-20f %16d %3l/%-5o %i%-S" :
886 "%>%a%m %-18f %16d %4l/%-5o %i%-s";
887 hprf(fmt
, mesg
, f
, threaded
, attrlist
);
891 * Print out the value of dot.
898 printf("%d\n", (int)(dot
- &message
[0] + 1));
903 * Type out the messages requested.
905 static sigjmp_buf pipestop
;
912 siglongjmp(pipestop
, 1);
916 _type1(int *msgvec
, bool_t doign
, bool_t dopage
, bool_t dopipe
,
917 bool_t dodecode
, char *cmd
, off_t
*tstats
)
923 FILE * volatile obuf
;
926 if (sigsetjmp(pipestop
, 1))
929 if ((cp
= value("SHELL")) == NULL
)
931 if ((obuf
= Popen(cmd
, "w", cp
, 1)) == NULL
) {
935 safe_signal(SIGPIPE
, brokpipe
);
936 } else if ((options
& OPT_TTYOUT
) &&
937 (dopage
|| (cp
= value("crt")) != NULL
)) {
940 for (ip
= msgvec
; *ip
&&
941 PTRCMP(ip
- msgvec
, <, msgCount
);
943 if (!(message
[*ip
- 1].m_have
& HAVE_BODY
)) {
944 if ((get_body(&message
[*ip
- 1])) !=
948 nlines
+= message
[*ip
- 1].m_lines
;
951 if (dopage
|| nlines
> (*cp
? atoi(cp
) : realscreenheight
)) {
952 char const *p
= get_pager();
953 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
957 safe_signal(SIGPIPE
, brokpipe
);
961 /* This may jump, in which case srelax_rele() wouldn't be called, but
962 * it shouldn't matter, because we -- then -- directly reenter the
963 * lex.c:commands() loop, which sreset()s */
965 for (ip
= msgvec
; *ip
&& PTRCMP(ip
- msgvec
, <, msgCount
); ++ip
) {
966 mp
= &message
[*ip
- 1];
970 if (!dopipe
&& ip
!= msgvec
)
972 _show_msg_overview(mp
, *ip
, obuf
);
973 sendmp(mp
, obuf
, (doign
? ignore
: 0), NULL
,
974 ((dopipe
&& boption("piperaw"))
975 ? SEND_MBOX
: dodecode
977 ? SEND_TODISP
: SEND_TODISP_ALL
),
980 if (dopipe
&& boption("page"))
983 tstats
[0] += mstats
[0];
984 tstats
[1] += mstats
[1];
989 if (obuf
!= stdout
) {
990 /* Ignore SIGPIPE so it can't cause a duplicate close */
991 safe_signal(SIGPIPE
, SIG_IGN
);
993 safe_signal(SIGPIPE
, dflpipe
);
999 * Pipe the messages requested.
1002 pipe1(char *str
, int doign
)
1010 msgvec
= (int *)salloc((msgCount
+ 2) * sizeof *msgvec
);
1011 if ((cmd
= laststring(str
, &f
, 1)) == NULL
) {
1013 if (cmd
== NULL
|| *cmd
== '\0') {
1014 fputs(tr(16, "variable cmd not set\n"), stderr
);
1019 *msgvec
= first(0, MMNORM
);
1023 puts(tr(18, "No messages to pipe."));
1027 } else if (getmsglist(str
, msgvec
, 0) < 0)
1032 printf("No applicable messages.\n");
1035 printf(tr(268, "Pipe to: \"%s\"\n"), cmd
);
1036 stats
[0] = stats
[1] = 0;
1037 if ((ret
= _type1(msgvec
, doign
, FAL0
, TRU1
, FAL0
, cmd
, stats
)) == 0) {
1038 printf("\"%s\" ", cmd
);
1040 printf("%lu", (long)stats
[0]);
1042 printf(tr(27, "binary"));
1043 printf("/%lu\n", (long)stats
[1]);
1049 * Paginate messages, honor ignored fields.
1056 return _type1(msgvec
, TRU1
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1060 * Paginate messages, even printing ignored fields.
1067 return _type1(msgvec
, FAL0
, TRU1
, FAL0
, FAL0
, NULL
, NULL
);
1071 * Type out messages, honor ignored fields.
1078 return _type1(msgvec
, TRU1
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1082 * Type out messages, even printing ignored fields.
1089 return _type1(msgvec
, FAL0
, FAL0
, FAL0
, FAL0
, NULL
, NULL
);
1093 * Show MIME-encoded message text, including all fields.
1100 return _type1(msgvec
, FAL0
, FAL0
, FAL0
, TRU1
, NULL
, NULL
);
1104 * Pipe messages, honor ignored fields.
1110 return(pipe1(str
, 1));
1113 * Pipe messages, not respecting ignored fields.
1119 return(pipe1(str
, 0));
1123 * Print the top so many lines of each desired message.
1124 * The number of lines is taken from the variable "toplines"
1125 * and defaults to 5.
1130 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1132 char *cp
, *linebuf
= NULL
;
1137 cp
= value("toplines");
1140 if (topl
< 0 || topl
> 10000)
1144 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
1145 mp
= &message
[*ip
- 1];
1148 did_print_dot
= TRU1
;
1151 _show_msg_overview(mp
, *ip
, stdout
);
1152 if (mp
->m_flag
& MNOFROM
)
1153 printf("From %s %s\n", fakefrom(mp
),
1154 fakedate(mp
->m_time
));
1155 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1160 for (lines
= 0; lines
< c
&& UICMP(32, lines
, <=, topl
);
1162 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1166 for (cp
= linebuf
; *cp
&& blankchar(*cp
); ++cp
)
1168 empty_last
= (*cp
== '\0');
1172 if (linebuf
!= NULL
)
1178 * Touch all the given messages so that they will
1187 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1188 setdot(&message
[*ip
-1]);
1189 dot
->m_flag
|= MTOUCH
;
1190 dot
->m_flag
&= ~MPRESERVE
;
1192 * POSIX interpretation necessary.
1194 did_print_dot
= TRU1
;
1200 * Make sure all passed messages get mboxed.
1208 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1209 setdot(&message
[*ip
-1]);
1210 dot
->m_flag
|= MTOUCH
|MBOX
;
1211 dot
->m_flag
&= ~MPRESERVE
;
1213 * POSIX interpretation necessary.
1215 did_print_dot
= TRU1
;
1221 * List the folders the user currently has.
1226 char dirname
[MAXPATHLEN
], *name
, **argv
= v
;
1230 name
= expand(*argv
);
1233 } else if (! getfold(dirname
, sizeof dirname
)) {
1234 fprintf(stderr
, tr(20, "No value set for \"folder\"\n"));
1239 if (which_protocol(name
) == PROTO_IMAP
) {
1241 imap_folders(name
, *argv
== NULL
);
1243 return ccmdnotsupp(NULL
);
1246 if ((cmd
= value("LISTER")) == NULL
)
1248 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);