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
49 * Print the current active headings.
50 * Don't change dot if invoker didn't give an argument.
55 /* Prepare and print "[Message: xy]:" intro */
56 static void _show_msg_overview(struct message
*mp
, int msg_no
, FILE *obuf
);
58 static void onpipe(int signo
);
59 static int _dispc(struct message
*mp
, const char *a
);
60 static int scroll1(char *arg
, int onlynew
);
62 /* ... And place the extracted date in `date' */
63 static void _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
]);
65 /* Get the Subject:, but return NULL if in threaded mode and the message
66 * printed before was in the same thread and had the same subject */
67 static char * _get_subject(struct message
*mp
, bool_t threaded
);
68 static char * __subject_trim(char *s
);
70 static void hprf(const char *fmt
, int mesg
, FILE *f
, int threaded
,
71 const char *attrlist
);
72 static int putindent(FILE *fp
, struct message
*mp
, int maxwidth
);
73 static int type1(int *msgvec
, int doign
, int page
, int pipe
, int decode
,
74 char *cmd
, off_t
*tstats
);
75 static int pipe1(char *str
, int doign
);
78 _show_msg_overview(struct message
*mp
, int msg_no
, FILE *obuf
)
80 fprintf(obuf
, tr(17, "[-- Message %2d -- %lu lines, %lu bytes --]:\n"),
81 msg_no
, (ul_it
)mp
->m_lines
, (ul_it
)mp
->m_size
);
88 fprintf(stderr
, tr(10, "The requested feature is not compiled in\n"));
98 if (cp
== NULL
|| *cp
== '\0')
107 int g
, k
, n
, mesg
, flag
= 0, lastg
= 1;
108 struct message
*mp
, *mq
, *lastmq
= NULL
;
110 enum mflag fl
= MNEW
|MFLAGGED
;
112 time_current_update(&time_current
, FAL0
);
115 n
= msgvec
[0]; /* n == {-2, -1, 0}: called from scroll() */
123 if (mb
.mb_threaded
== 0) {
126 for (mp
= &message
[0]; mp
< &message
[msgCount
]; mp
++)
134 if ((n
> 0 && mp
== &message
[n
-1]) ||
135 (n
== 0 && g
== k
) ||
136 (n
== -2 && g
== k
+ size
&&
139 (mp
->m_flag
& fl
) != 0))
143 if (lastmq
&& (n
==-2 || (n
==-1 && mp
== &message
[msgCount
]))) {
149 mesg
= mp
- &message
[0];
150 if (dot
!= &message
[n
-1]) {
151 for (mq
= mp
; mq
< &message
[msgCount
]; mq
++)
158 if (mb
.mb_type
== MB_IMAP
)
159 imap_getheaders(mesg
+1, mesg
+ size
);
161 for (; mp
< &message
[msgCount
]; mp
++) {
167 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) {
204 if (visible(mp
) && (mp
->m_collapsed
<= 0 ||
205 mp
== &message
[n
-1])) {
208 printhead(mp
- &message
[0] + 1, stdout
,
211 mp
= next_in_thread(mp
);
215 printf(tr(6, "No more mail.\n"));
222 * Scroll to the next/previous screen
227 return scroll1(v
, 0);
233 return scroll1(v
, 1);
237 scroll1(char *arg
, int onlynew
)
242 cur
[0] = onlynew
? -1 : 0;
245 case '1': case '2': case '3': case '4': case '5':
246 case '6': case '7': case '8': case '9': case '0':
253 screen
= msgCount
/ size
;
259 screen
+= atoi(arg
+ 1);
261 if (screen
* size
> msgCount
) {
262 screen
= msgCount
/ size
;
263 printf(catgets(catd
, CATSET
, 7,
264 "On last screenful of messages\n"));
272 screen
-= atoi(arg
+ 1);
275 printf(catgets(catd
, CATSET
, 8,
276 "On first screenful of messages\n"));
283 printf(catgets(catd
, CATSET
, 9,
284 "Unrecognized scrolling command \"%s\"\n"), arg
);
287 return(headers(cur
));
291 * Compute screen size.
299 if ((cp
= value("screen")) != NULL
&& (s
= atoi(cp
)) > 0)
301 return scrnheight
- 4;
304 static sigjmp_buf pipejmp
;
311 siglongjmp(pipejmp
, 1);
315 * Print out the headlines for each message
316 * in the passed message list.
321 int *msgvec
= v
, *ip
, n
;
323 FILE *volatile obuf
= stdout
;
325 time_current_update(&time_current
, FAL0
);
327 /* TODO unfixable memory leaks still */
328 if (IS_TTY_SESSION() && (cp
= value("crt")) != NULL
) {
329 for (n
= 0, ip
= msgvec
; *ip
; ip
++)
331 if (n
> (*cp
== '\0' ? screensize() : atoi((char*)cp
)) + 3) {
333 if (sigsetjmp(pipejmp
, 1))
336 if ((obuf
= Popen(p
, "w", NULL
, 1)) == NULL
) {
341 safe_signal(SIGPIPE
, onpipe
);
344 for (ip
= msgvec
; *ip
!= 0; ip
++)
345 printhead(*ip
, obuf
, mb
.mb_threaded
);
347 setdot(&message
[*ip
- 1]);
349 if (obuf
!= stdout
) {
350 safe_signal(SIGPIPE
, SIG_IGN
);
352 safe_signal(SIGPIPE
, dflpipe
);
358 _dispc(struct message
*mp
, const char *a
)
365 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MREAD
)
367 if ((mp
->m_flag
& (MREAD
|MNEW
)) == (MREAD
|MNEW
))
369 if (mp
->m_flag
& MANSWERED
)
371 if (mp
->m_flag
& MDRAFTED
)
373 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
375 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
377 if (mp
->m_flag
& MSPAM
)
379 if (mp
->m_flag
& MSAVED
)
381 if (mp
->m_flag
& MPRESERVE
)
383 if (mp
->m_flag
& (MBOX
|MBOXED
))
385 if (mp
->m_flag
& MFLAGGED
)
387 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
> 0)
389 if (mb
.mb_threaded
== 1 && mp
->m_collapsed
< 0)
395 _parse_from_(struct message
*mp
, char date
[FROM_DATEBUF
])
402 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) != NULL
&&
403 (hlen
= readline_restart(ibuf
, &hline
, &hsize
, 0)) > 0)
404 (void)extract_date_from_from_(hline
, hlen
, date
);
410 __subject_trim(char *s
)
413 while (spacechar(*s
))
415 if (is_asccaseprefix("re:", s
)) {
419 if (is_asccaseprefix("fwd:", s
)) {
429 _get_subject(struct message
*mp
, bool_t threaded
)
432 char *rv
= (char*)-1, *ms
, *mso
, *os
;
434 if ((ms
= hfield1("subject", mp
)) == NULL
)
437 if (! threaded
|| mp
->m_level
== 0)
440 /* In a display thread - check wether this message uses the same
441 * Subject: as it's parent or elder neighbour, suppress printing it if
442 * this is the case. To extend this a bit, ignore any leading Re: or
443 * Fwd: plus follow-up WS; XXX NOTE: because of efficiency reasons we
444 * XXX simply ignore any encoded parts and use ASCII case-insensitive
446 mso
= __subject_trim(ms
);
448 if (mp
->m_elder
!= NULL
&&
449 (os
= hfield1("subject", mp
->m_elder
)) != NULL
&&
450 asccasecmp(mso
, __subject_trim(os
)) == 0)
453 if (mp
->m_parent
!= NULL
&&
454 (os
= hfield1("subject", mp
->m_parent
)) != NULL
&&
455 asccasecmp(mso
, __subject_trim(os
)) == 0)
461 mime_fromhdr(&in
, &out
, TD_ICONV
| TD_ISPR
);
468 hprf(const char *fmt
, int mesg
, FILE *f
, int threaded
, const char *attrlist
)
470 char datebuf
[FROM_DATEBUF
], *cp
, *subjline
;
471 char const *datefmt
, *date
, *name
, *fp
;
472 int B
, c
, i
, n
, s
, wleft
, subjlen
, isto
= 0, isaddr
= 0;
473 struct message
*mp
= &message
[mesg
- 1];
474 time_t datet
= mp
->m_time
;
477 if ((datefmt
= value("datefield")) != NULL
) {
478 fp
= hfield1("date", mp
);/* TODO use m_date field! */
484 date
= fakedate(datet
);
485 fp
= value("datefield-markout-older");
486 i
= (*datefmt
!= '\0');
488 i
|= (*fp
!= '\0') ? 2 | 4 : 2;
489 /* May we strftime(3)? */
491 memcpy(&time_current
.tc_local
, localtime(&datet
),
492 sizeof time_current
.tc_local
);
494 /* TODO *datefield-markout-older* we accept
495 * TODO one day in the future, should be UTC
496 * TODO offset only? and Stephen Isard had
497 * TODO one week once he proposed the patch! */
498 (datet
> time_current
.tc_time
+ DATE_SECSDAY
||
499 #define _6M ((DATE_DAYSYEAR / 2) * DATE_SECSDAY)
500 (datet
+ _6M
< time_current
.tc_time
))) {
502 if ((datefmt
= (i
& 4) ? fp
: NULL
) == NULL
) {
503 memset(datebuf
, ' ', FROM_DATEBUF
); /* xxx ur */
504 memcpy(datebuf
+ 4, date
+ 4, 7);
505 datebuf
[4 + 7] = ' ';
506 memcpy(datebuf
+ 4 + 7 + 1, date
+ 20, 4);
507 datebuf
[4 + 7 + 1 + 4] = '\0';
510 } else if ((i
& 1) == 0)
512 } else if (datet
== (time_t)0 && (mp
->m_flag
& MNOFROM
) == 0) {
513 /* TODO eliminate this path, query the FROM_ date in setptr(),
514 * TODO all other codepaths do so by themselves ALREADY ?????
515 * TODO assert(mp->m_time != 0);, then
516 * TODO ALSO changes behaviour of markout-non-current */
517 _parse_from_(mp
, datebuf
);
521 date
= fakedate(datet
);
526 if (name
!= NULL
&& value("showto") && is_myname(skin(name
))) {
527 if ((cp
= hfield1("to", mp
)) != NULL
) {
537 if (value("showname"))
538 name
= realname(name
);
540 name
= prstr(skin(name
));
546 /* Detect the width of the non-format characters in *headline*;
547 * like that we can simply use putc() in the next loop, since we have
548 * already calculated their column widths (TODO it's sick) */
552 for (fp
= fmt
; *fp
; ++fp
) {
556 } else if (*fp
== '+')
558 if (digitchar(*fp
)) {
561 n
= 10*n
+ *fp
- '0';
562 while (++fp
, digitchar(*fp
));
569 #if defined HAVE_MBTOWC && defined HAVE_WCWIDTH
570 if (mb_cur_max
> 1) {
572 if ((s
= mbtowc(&wc
, fp
, mb_cur_max
)) < 0)
574 else if ((n
= wcwidth(wc
)) < 0)
586 /* Walk *headline*, producing output */
587 for (fp
= fmt
; *fp
; ++fp
) {
588 if ((c
= *fp
& 0xFF) == '%') {
595 } else if (*fp
== '+')
597 if (digitchar(*fp
)) {
599 n
= 10*n
+ *fp
- '0';
600 while (++fp
, digitchar(*fp
));
606 switch ((c
= *fp
& 0xFF)) {
615 c
= _dispc(mp
, attrlist
);
618 n
= (n
< 0) ? -wleft
: wleft
;
619 n
= fprintf(f
, "%*c", n
, c
);
620 wleft
= (n
>= 0) ? wleft
- n
: 0;
626 for (i
=msgCount
; i
>999; i
/=10)
630 n
= (n
< 0) ? -wleft
: wleft
;
631 n
= fprintf(f
, "%*d", n
, mesg
);
632 wleft
= (n
>= 0) ? wleft
- n
: 0;
643 n
= (n
< 0) ? -wleft
: wleft
;
645 if (isto
) /* XXX tr()! */
647 n
= fprintf(f
, "%s%s", (isto
? "To " : ""),
648 colalign(name
, i
, n
, &wleft
));
655 if (datefmt
!= NULL
) {
656 i
= strftime(datebuf
, sizeof datebuf
,
658 &time_current
.tc_local
);
662 fprintf(stderr
, tr(174,
663 "Ignored date format, "
667 (ul_it
)sizeof datebuf
);
673 n
= (n
< 0) ? -wleft
: wleft
;
674 n
= fprintf(f
, "%*.*s", n
, n
, date
);
675 wleft
= (n
>= 0) ? wleft
- n
: 0;
681 n
= (n
< 0) ? -wleft
: wleft
;
683 n
= fprintf(f
, "%*ld", n
, mp
->m_xlines
);
684 wleft
= (n
>= 0) ? wleft
- n
: 0;
696 n
= (n
< 0) ? -wleft
: wleft
;
697 n
= fprintf(f
, "%*lu", n
, (long)mp
->m_xsize
);
698 wleft
= (n
>= 0) ? wleft
- n
: 0;
702 n
= putindent(f
, mp
, MIN(wleft
,
704 wleft
= (n
>= 0) ? wleft
- n
: 0;
717 if (ABS(n
) > subjlen
)
718 n
= (n
< 0) ? -subjlen
: subjlen
;
720 n
-= (n
< 0) ? -2 : 2;
723 if (subjline
== NULL
)
724 subjline
= _get_subject(mp
, threaded
);
725 if (subjline
== (char*)-1) {
726 n
= fprintf(f
, "%*s", n
, "");
727 wleft
= (n
>= 0) ? wleft
-n
: 0;
729 n
= fprintf(f
, (B
? "\"%s\"" : "%s"),
730 colalign(subjline
, ABS(n
), n
,
741 n
= (n
< 0) ? -wleft
: wleft
;
742 n
= fprintf(f
, "%*lu", n
, mp
->m_uid
);
743 wleft
= (n
>= 0) ? wleft
- n
: 0;
753 n
= (n
< 0) ? -wleft
: wleft
;
754 n
= fprintf(f
, "%*u", n
,
755 threaded
== 1 ? mp
->m_level
: 0);
756 wleft
= (n
>= 0) ? wleft
- n
: 0;
762 for (i
=msgCount
; i
>999; i
/=10)
766 n
= (n
< 0) ? -wleft
: wleft
;
767 n
= fprintf(f
, "%*ld", n
,
768 threaded
? mp
->m_threadpos
: mesg
);
769 wleft
= (n
>= 0) ? wleft
- n
: 0;
776 n
= (n
< 0) ? -wleft
: wleft
;
778 snprintf(buf
, sizeof buf
, "%u.%u",
779 (mp
->m_spamscore
>> 8),
780 (mp
->m_spamscore
& 0xFF));
781 n
= fprintf(f
, "%*s", n
, buf
);
782 wleft
= (n
>= 0) ? wleft
- n
: 0;
797 if (subjline
!= NULL
&& subjline
!= (char*)-1)
802 * Print out the indenting in threaded display.
805 putindent(FILE *fp
, struct message
*mp
, int maxwidth
)/* XXX no magic consts */
808 int *us
, indlvl
, indw
, i
, important
= MNEW
|MFLAGGED
;
811 if (mp
->m_level
== 0 || maxwidth
== 0)
813 cs
= ac_alloc(mp
->m_level
);
814 us
= ac_alloc(mp
->m_level
* sizeof *us
);
817 if (mp
->m_younger
&& (unsigned)i
+ 1 == mp
->m_younger
->m_level
) {
818 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
819 us
[i
] = mp
->m_flag
& important
? 0x2523 : 0x2520;
821 us
[i
] = mp
->m_flag
& important
? 0x251D : 0x251C;
824 if (mp
->m_parent
&& mp
->m_parent
->m_flag
& important
)
825 us
[i
] = mp
->m_flag
& important
? 0x2517 : 0x2516;
827 us
[i
] = mp
->m_flag
& important
? 0x2515 : 0x2514;
832 for (i
= mp
->m_level
- 2; i
>= 0; i
--) {
834 if ((unsigned)i
> mq
->m_level
- 1) {
840 mq
->m_parent
->m_flag
&important
)
853 for (indlvl
= indw
= 0; (uc_it
)indlvl
< mp
->m_level
&&
854 indw
< maxwidth
; ++indlvl
) {
855 if (indw
< maxwidth
- 1)
856 indw
+= (int)putuc(us
[indlvl
], cs
[indlvl
] & 0377, fp
);
858 indw
+= (int)putuc(0x21B8, '^', fp
);
860 indw
+= /*putuc(0x261E, fp)*/putc('>', fp
) != EOF
;
868 printhead(int mesg
, FILE *f
, int threaded
)
870 int bsdflags
, bsdheadline
, sz
;
871 char attrlist
[30], *cp
;
874 bsdflags
= value("bsdcompat") != NULL
|| value("bsdflags") != NULL
||
875 getenv("SYSV3") != NULL
;
876 strcpy(attrlist
, bsdflags
? "NU *HMFAT+-$" : "NUROSPMFAT+-$");
877 if ((cp
= value("attrlist")) != NULL
) {
879 if (sz
> (int)sizeof attrlist
- 1)
880 sz
= (int)sizeof attrlist
- 1;
881 memcpy(attrlist
, cp
, sz
);
883 bsdheadline
= value("bsdcompat") != NULL
||
884 value("bsdheadline") != NULL
;
885 if ((fmt
= value("headline")) == NULL
)
887 "%>%a%m %-20f %16d %3l/%-5o %i%-S" :
888 "%>%a%m %-18f %16d %4l/%-5o %i%-s";
889 hprf(fmt
, mesg
, f
, threaded
, attrlist
);
893 * Print out the value of dot.
900 printf("%d\n", (int)(dot
- &message
[0] + 1));
905 * Print out all the possible commands.
909 _pcmd_cmp(void const *s1
, void const *s2
)
911 struct cmd
const *const*c1
= s1
, *const*c2
= s2
;
912 return (strcmp((*c1
)->c_name
, (*c2
)->c_name
));
919 extern struct cmd
const cmdtab
[];
920 struct cmd
const **cpa
, *cp
, **cursor
;
924 for (i
= 0; cmdtab
[i
].c_name
!= NULL
; ++i
)
927 cpa
= ac_alloc(sizeof(cp
) * i
);
929 for (i
= 0; (cp
= cmdtab
+ i
)->c_name
!= NULL
; ++i
)
933 qsort(cpa
, i
, sizeof(cp
), &_pcmd_cmp
);
935 printf(tr(14, "Commands are:\n"));
936 for (i
= 0, cursor
= cpa
; (cp
= *cursor
++) != NULL
;) {
938 if (cp
->c_func
== &ccmdnotsupp
)
940 j
= strlen(cp
->c_name
) + 2;
945 printf((*cursor
!= NULL
? "%s, " : "%s\n"), cp
->c_name
);
953 * Type out the messages requested.
955 static sigjmp_buf pipestop
;
962 siglongjmp(pipestop
, 1);
966 type1(int *msgvec
, int doign
, int page
, int pipe
, int decode
,
967 char *cmd
, off_t
*tstats
)
977 if (sigsetjmp(pipestop
, 1))
983 obuf
= Popen(cmd
, "w", cp
, 1);
988 safe_signal(SIGPIPE
, brokpipe
);
990 } else if ((options
& OPT_TTYOUT
) &&
991 (page
|| (cp
= value("crt")) != NULL
)) {
994 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
995 if ((message
[*ip
-1].m_have
& HAVE_BODY
) == 0) {
996 if ((get_body(&message
[*ip
- 1])) !=
1000 nlines
+= message
[*ip
- 1].m_lines
;
1003 if (page
|| nlines
> (*cp
? atoi(cp
) : realscreenheight
)) {
1004 char const *p
= get_pager();
1005 obuf
= Popen(p
, "w", NULL
, 1);
1010 safe_signal(SIGPIPE
, brokpipe
);
1013 for (ip
= msgvec
; *ip
&& ip
- msgvec
< msgCount
; ip
++) {
1014 mp
= &message
[*ip
- 1];
1018 if (! pipe
&& ip
!= msgvec
)
1019 fprintf(obuf
, "\n");
1020 _show_msg_overview(mp
, *ip
, obuf
);
1021 send(mp
, obuf
, doign
? ignore
: 0, NULL
,
1022 pipe
&& value("piperaw") ? SEND_MBOX
:
1023 decode
? SEND_SHOW
:
1024 doign
? SEND_TODISP
: SEND_TODISP_ALL
,
1026 if (pipe
&& value("page")) {
1030 tstats
[0] += mstats
[0];
1031 tstats
[1] += mstats
[1];
1035 if (obuf
!= stdout
) {
1037 * Ignore SIGPIPE so it can't cause a duplicate close.
1039 safe_signal(SIGPIPE
, SIG_IGN
);
1041 safe_signal(SIGPIPE
, dflpipe
);
1047 * Get the last, possibly quoted part of linebuf.
1050 laststring(char *linebuf
, int *flag
, int strip
)
1056 cp
= strlen(linebuf
) + linebuf
- 1;
1059 * Strip away trailing blanks.
1061 while (cp
> linebuf
&& whitechar(*cp
& 0377))
1064 if (cp
== linebuf
) {
1070 * Now search for the beginning of the command name.
1073 if (quoted
== '\'' || quoted
== '\"') {
1078 while (cp
> linebuf
) {
1079 if (*cp
!= quoted
) {
1081 } else if (*(cp
- 1) != '\\') {
1093 if (*cp
== quoted
) {
1099 while (cp
> linebuf
&& !whitechar(*cp
& 0377))
1101 if (whitechar(*cp
& 0377))
1113 * Pipe the messages requested.
1116 pipe1(char *str
, int doign
)
1119 int f
, *msgvec
, ret
;
1123 msgvec
= (int *)salloc((msgCount
+ 2) * sizeof *msgvec
);
1124 if ((cmd
= laststring(str
, &f
, 1)) == NULL
) {
1126 if (cmd
== NULL
|| *cmd
== '\0') {
1127 fputs(catgets(catd
, CATSET
, 16,
1128 "variable cmd not set\n"), stderr
);
1133 *msgvec
= first(0, MMNORM
);
1137 puts(catgets(catd
, CATSET
, 18, "No messages to pipe."));
1141 } else if (getmsglist(str
, msgvec
, 0) < 0)
1146 printf("No applicable messages.\n");
1149 printf(catgets(catd
, CATSET
, 268, "Pipe to: \"%s\"\n"), cmd
);
1150 stats
[0] = stats
[1] = 0;
1151 if ((ret
= type1(msgvec
, doign
, 0, 1, 0, cmd
, stats
)) == 0) {
1152 printf("\"%s\" ", cmd
);
1154 printf("%lu", (long)stats
[0]);
1156 printf(catgets(catd
, CATSET
, 27, "binary"));
1157 printf("/%lu\n", (long)stats
[1]);
1163 * Paginate messages, honor ignored fields.
1169 return (type1(msgvec
, 1, 1, 0, 0, NULL
, NULL
));
1173 * Paginate messages, even printing ignored fields.
1180 return (type1(msgvec
, 0, 1, 0, 0, NULL
, NULL
));
1184 * Type out messages, honor ignored fields.
1191 return(type1(msgvec
, 1, 0, 0, 0, NULL
, NULL
));
1195 * Type out messages, even printing ignored fields.
1202 return(type1(msgvec
, 0, 0, 0, 0, NULL
, NULL
));
1206 * Show MIME-encoded message text, including all fields.
1213 return(type1(msgvec
, 0, 0, 0, 1, NULL
, NULL
));
1217 * Pipe messages, honor ignored fields.
1223 return(pipe1(str
, 1));
1226 * Pipe messages, not respecting ignored fields.
1232 return(pipe1(str
, 0));
1236 * Print the top so many lines of each desired message.
1237 * The number of lines is taken from the variable "toplines"
1238 * and defaults to 5.
1243 int *msgvec
= v
, *ip
, c
, topl
, lines
, empty_last
;
1245 char *cp
, *linebuf
= NULL
;
1250 cp
= value("toplines");
1253 if (topl
< 0 || topl
> 10000)
1257 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
1258 mp
= &message
[*ip
- 1];
1261 did_print_dot
= TRU1
;
1264 _show_msg_overview(mp
, *ip
, stdout
);
1265 if (mp
->m_flag
& MNOFROM
)
1266 printf("From %s %s\n", fakefrom(mp
),
1267 fakedate(mp
->m_time
));
1268 if ((ibuf
= setinput(&mb
, mp
, NEED_BODY
)) == NULL
) { /* XXX could use TOP */
1273 for (lines
= 0; lines
< c
&& lines
<= topl
; lines
++) {
1274 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1278 for (cp
= linebuf
; *cp
&& blankchar(*cp
); ++cp
)
1280 empty_last
= (*cp
== '\0');
1284 if (linebuf
!= NULL
)
1290 * Touch all the given messages so that they will
1299 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1300 setdot(&message
[*ip
-1]);
1301 dot
->m_flag
|= MTOUCH
;
1302 dot
->m_flag
&= ~MPRESERVE
;
1304 * POSIX interpretation necessary.
1306 did_print_dot
= TRU1
;
1312 * Make sure all passed messages get mboxed.
1320 for (ip
= msgvec
; *ip
!= 0; ip
++) {
1321 setdot(&message
[*ip
-1]);
1322 dot
->m_flag
|= MTOUCH
|MBOX
;
1323 dot
->m_flag
&= ~MPRESERVE
;
1325 * POSIX interpretation necessary.
1327 did_print_dot
= TRU1
;
1333 * List the folders the user currently has.
1338 char dirname
[MAXPATHLEN
], *name
, **argv
= v
;
1342 name
= expand(*argv
);
1345 } else if (! getfold(dirname
, sizeof dirname
)) {
1346 fprintf(stderr
, tr(20, "No value set for \"folder\"\n"));
1351 if (which_protocol(name
) == PROTO_IMAP
) {
1353 imap_folders(name
, *argv
== NULL
);
1355 return ccmdnotsupp(NULL
);
1358 if ((cmd
= value("LISTER")) == NULL
)
1360 run_command(cmd
, 0, -1, -1, name
, NULL
, NULL
);