1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: mailpart.c 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2018 Eduardo Chappa
8 * Copyright 2006-2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 /*======================================================================
21 The meat and pototoes of attachment processing here.
43 #include "../pith/state.h"
44 #include "../pith/conf.h"
45 #include "../pith/store.h"
46 #include "../pith/msgno.h"
47 #include "../pith/detach.h"
48 #include "../pith/handle.h"
49 #include "../pith/filter.h"
50 #include "../pith/bitmap.h"
51 #include "../pith/charset.h"
52 #include "../pith/mimedesc.h"
53 #include "../pith/mailcap.h"
54 #include "../pith/newmail.h"
55 #include "../pith/rfc2231.h"
56 #include "../pith/flag.h"
57 #include "../pith/text.h"
58 #include "../pith/editorial.h"
59 #include "../pith/save.h"
60 #include "../pith/pipe.h"
61 #include "../pith/util.h"
62 #include "../pith/detoken.h"
63 #include "../pith/busy.h"
64 #include "../pith/mimetype.h"
65 #include "../pith/icache.h"
66 #include "../pith/list.h"
67 #include "../pith/ablookup.h"
68 #include "../pith/options.h"
69 #include "../pith/smime.h"
70 #include "../pith/ical.h"
71 #include "../pith/body.h"
74 * Information used to paint and maintain a line on the attachment
77 typedef struct atdisp_line
{
78 char *dstring
; /* alloc'd var value string */
79 ATTACH_S
*attp
; /* actual attachment pointer */
80 struct atdisp_line
*next
, *prev
;
85 * struct defining attachment screen's current state
87 typedef struct att_screen
{
90 COLOR_PAIR
*titlecolor
;
93 static ATT_SCREEN_S
*att_screen
;
96 #define next_attline(p) ((p) ? (p)->next : NULL)
97 #define prev_attline(p) ((p) ? (p)->prev : NULL)
102 * local global pointer to scroll attachment popup menu
104 static ATTACH_S
*scrat_attachp
;
108 #define FETCH_READC g_fr_desc->readc
111 /* used to keep track of detached MIME segments total length */
112 static long save_att_length
;
115 * Internal Prototypes
117 ATDISP_S
*new_attline(ATDISP_S
**);
118 void free_attline(ATDISP_S
**);
119 int attachment_screen_updater(struct pine
*, ATDISP_S
*, ATT_SCREEN_S
*);
120 void attachment_screen_redrawer(void);
121 void update_att_screen_titlebar(void);
122 ATDISP_S
*first_attline(ATDISP_S
*);
123 int init_att_progress(char *, MAILSTREAM
*, BODY
*);
124 long save_att_piped(int);
125 int save_att_percent(void);
126 void save_attachment(int, long, ATTACH_S
*);
127 void export_attachment(int, long, ATTACH_S
*);
128 char *write_attached_msg(long, ATTACH_S
**, STORE_S
*, int);
129 void save_msg_att(long, ATTACH_S
*);
130 void save_digest_att(long, ATTACH_S
*);
131 int save_msg_att_work(long int, ATTACH_S
*, MAILSTREAM
*, char *,
132 CONTEXT_S
*, char *);
133 void export_msg_att(long, ATTACH_S
*);
134 void export_digest_att(long, ATTACH_S
*);
135 void print_attachment(int, long, ATTACH_S
*);
136 int print_msg_att(long, ATTACH_S
*, int);
137 void print_digest_att(long, ATTACH_S
*);
138 void run_viewer(char *, BODY
*, int);
139 STORE_S
*format_text_att(long, ATTACH_S
*, HANDLE_S
**);
140 int display_text_att(long, ATTACH_S
*, int);
141 int display_msg_att(long, ATTACH_S
*, int);
142 void display_digest_att(long, ATTACH_S
*, int);
143 int scroll_attachment(char *, STORE_S
*, SourceType
, HANDLE_S
*, ATTACH_S
*, int);
144 int process_attachment_cmd(int, MSGNO_S
*, SCROLL_S
*);
145 int format_msg_att(long, ATTACH_S
**, HANDLE_S
**, gf_io_t
, int);
146 void display_vcard_att(long, ATTACH_S
*, int);
147 void display_vcalendar_att(long, ATTACH_S
*, int);
148 void display_attach_info(long, ATTACH_S
*);
149 void forward_attachment(MAILSTREAM
*, long, ATTACH_S
*);
150 void forward_msg_att(MAILSTREAM
*, long, ATTACH_S
*);
151 void reply_msg_att(MAILSTREAM
*, long, ATTACH_S
*);
152 void bounce_msg_att(MAILSTREAM
*, long, char *, char *);
153 void pipe_attachment(long, ATTACH_S
*);
154 int delete_attachment(long, ATTACH_S
*);
155 int undelete_attachment(long, ATTACH_S
*, int *);
157 int scroll_att_popup(SCROLL_S
*, int);
158 void display_text_att_window(ATTACH_S
*);
159 void display_msg_att_window(ATTACH_S
*);
163 /*----------------------------------------------------------------------
164 Provide attachments in browser for selected action
166 Args: ps -- pointer to pine structure
167 msgmap -- struct containing current message to display
171 Handle painting and navigation of attachment index. It would be nice
172 to someday handle message/rfc822 segments in a neat way (i.e., enable
173 forwarding, take address, etc.).
176 attachment_screen(struct pine
*ps
)
180 maxnumwid
= 0, maxsizewid
= 0, old_cols
= -1, km_popped
= 0, expbits
,
181 last_type
= TYPEOTHER
;
183 char *q
, *last_subtype
= NULL
, backtag
[64], *utf8str
;
186 ATDISP_S
*current
= NULL
, *ctmp
= NULL
;
189 ps
->prev_screen
= attachment_screen
;
190 ps
->next_screen
= SCREEN_FUN_NULL
;
192 ps
->some_quoting_was_suppressed
= 0;
194 if(ps
->ttyo
->screen_rows
- HEADER_ROWS(ps
) - FOOTER_ROWS(ps
) < 1){
195 q_status_message(SM_ORDER
| SM_DING
, 0, 3,
196 _("Screen too small to view attachment"));
197 ps
->next_screen
= mail_view_screen
;
201 if(mn_total_cur(ps
->msgmap
) > 1L){
202 q_status_message(SM_ORDER
| SM_DING
, 0, 3,
203 _("Can only view one message's attachments at a time."));
206 else if(ps
->atmts
&& ps
->atmts
->description
&& !(ps
->atmts
+ 1)->description
)
207 q_status_message1(SM_ASYNC
, 0, 3,
208 _("Message %s has only one part (the message body), and no attachments."),
209 long2string(mn_get_cur(ps
->msgmap
)));
211 /*----- Figure max display widths -----*/
212 for(a
= ps
->atmts
; a
&& a
->description
!= NULL
; a
++){
213 if((n
= utf8_width(a
->number
)) > maxnumwid
)
216 if((n
= utf8_width(a
->size
)) > maxsizewid
)
221 * Then, allocate and initialize attachment line list...
223 for(a
= ps
->atmts
; a
&& a
->description
; a
++)
224 new_attline(¤t
)->attp
= a
;
226 memset(&screen
, 0, sizeof(screen
));
227 msgno
= mn_m2raw(ps
->msgmap
, mn_get_cur(ps
->msgmap
));
228 ps
->mangled_screen
= 1; /* build display */
229 ps
->redrawer
= attachment_screen_redrawer
;
230 att_screen
= &screen
;
231 current
= first_attline(current
);
235 * Advance to next attachment if it's likely that we've already
236 * shown it to the user...
239 if (current
== NULL
){
240 q_status_message1(SM_ORDER
| SM_DING
, 0, 3,
241 _("Malformed message: %s"),
242 ps
->c_client_error
? ps
->c_client_error
: "?");
243 ps
->next_screen
= mail_view_screen
;
245 else if(current
->attp
->shown
&& (ctmp
= next_attline(current
)))
248 while(ps
->next_screen
== SCREEN_FUN_NULL
){
249 ps
->user_says_cancel
= 0;
254 ps
->mangled_body
= 1;
258 if(ps
->mangled_screen
){
260 * build/rebuild display lines
262 if(old_cols
!= ps
->ttyo
->screen_cols
){
263 int avail
, s1
, s2
, s4
, s5
, dwid
, sizewid
, descwid
;
265 avail
= ps_global
->ttyo
->screen_cols
;
267 s1
= MAX(MIN(1, avail
), 0);
270 dwid
= MAX(MIN(1, avail
), 0);
273 s2
= MAX(MIN(1, avail
), 0);
276 /* Only give up a third of the display to part numbers */
277 maxnumwid
= MIN(maxnumwid
, (ps_global
->ttyo
->screen_cols
/3));
278 maxnumwid
= MAX(MIN(maxnumwid
, avail
), 0);
281 s4
= MAX(MIN(3, avail
), 0);
284 sizewid
= MAX(MIN(maxsizewid
, avail
), 0);
287 s5
= MAX(MIN(3, avail
), 0);
290 descwid
= MAX(0, avail
);
292 old_cols
= ps
->ttyo
->screen_cols
;
294 for(ctmp
= first_attline(current
);
295 ctmp
&& (a
= ctmp
->attp
) && a
->description
;
296 ctmp
= next_attline(ctmp
)){
299 char description
[1000];
302 fs_give((void **)&ctmp
->dstring
);
304 len
= 6 * MAX(80, ps
->ttyo
->screen_cols
) * sizeof(char);
305 ctmp
->dstring
= (char *)fs_get(len
+ 1);
310 q
= a
->body
->description
;
311 if(!(q
&& q
[0]) && (MIME_MSG_A(a
) && a
->body
->nested
.msg
->env
))
312 q
= a
->body
->nested
.msg
->env
->subject
;
317 strncpy(buftmp
, q
, sizeof(buftmp
));
318 buftmp
[sizeof(buftmp
)-1] = '\0';
320 q
= (char *) rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf
,
321 SIZEOF_20KBUF
, buftmp
);
327 snprintf(description
, sizeof(description
), "%s%s%s%s", type_desc(a
->body
->type
, a
->body
->subtype
, a
->body
->parameter
, a
->body
->disposition
.type
? a
->body
->disposition
.parameter
: NULL
, 1), q
? ", \"" : "", q
? q
: "", q
? "\"" : "");
328 description
[sizeof(description
)-1] = '\0';
330 utf8_snprintf(ctmp
->dstring
, len
+1,
331 "%*.*s%*.*w%*.*s%-*.*w%*.*s%*.*w%*.*s%-*.*w",
334 msgno_part_deleted(ps
->mail_stream
, msgno
, a
->number
) ? "D" : "",
336 maxnumwid
, maxnumwid
,
338 ? short_str(a
->number
, numbuf
, sizeof(numbuf
), maxnumwid
, FrontDots
)
342 a
->size
? a
->size
: "",
344 descwid
, descwid
, description
);
346 ctmp
->dstring
[len
] = '\0';
350 ps
->mangled_header
= 1;
351 ps
->mangled_footer
= 1;
352 ps
->mangled_body
= 1;
355 /*----------- Check for new mail -----------*/
356 if(new_mail(0, NM_TIMING(ch
), NM_STATUS_MSG
| NM_DEFER_SORT
) >= 0)
357 ps
->mangled_header
= 1;
360 * If an expunge of the current message happened during the
361 * new mail check we want to bail out of here. See mm_expunged.
363 if(ps
->next_screen
!= SCREEN_FUN_NULL
)
366 if(ps
->mangled_header
){
367 update_att_screen_titlebar();
368 ps
->mangled_header
= 0;
371 if(ps
->mangled_screen
){
373 ps
->mangled_screen
= 0;
376 dline
= attachment_screen_updater(ps
, current
, &screen
);
378 /*---- This displays new mail notification, or errors ---*/
381 mark_status_unknown();
387 mark_status_unknown();
390 if(ps
->mangled_footer
391 || current
->attp
->body
->type
!= last_type
392 || !(last_subtype
&& current
->attp
->body
->subtype
)
393 || strucmp(last_subtype
, current
->attp
->body
->subtype
)){
395 struct key_menu
*km
= &att_index_keymenu
;
399 ps
->mangled_footer
= 0;
400 last_type
= current
->attp
->body
->type
;
401 last_subtype
= current
->attp
->body
->subtype
;
403 snprintf(backtag
, sizeof(backtag
), "Msg #%ld", mn_get_cur(ps
->msgmap
));
404 backtag
[sizeof(backtag
)-1] = '\0';
405 km
->keys
[ATT_PARENT_KEY
].label
= backtag
;
407 if(F_OFF(F_ENABLE_PIPE
, ps
))
408 clrbitn(ATT_PIPE_KEY
, bitmap
);
411 * If message or digest, leave Reply and Save and,
412 * conditionally, Bounce on...
414 if(MIME_MSG(last_type
, last_subtype
)){
415 if(F_OFF(F_ENABLE_BOUNCE
, ps
))
416 clrbitn(ATT_BOUNCE_KEY
, bitmap
);
418 km
->keys
[ATT_EXPORT_KEY
].name
= "";
419 km
->keys
[ATT_EXPORT_KEY
].label
= "";
421 else if(MIME_DGST(last_type
, last_subtype
)){
422 clrbitn(ATT_BOUNCE_KEY
, bitmap
);
423 clrbitn(ATT_REPLY_KEY
, bitmap
);
425 km
->keys
[ATT_EXPORT_KEY
].name
= "";
426 km
->keys
[ATT_EXPORT_KEY
].label
= "";
429 clrbitn(ATT_BOUNCE_KEY
, bitmap
);
430 clrbitn(ATT_REPLY_KEY
, bitmap
);
432 if(last_type
!= TYPETEXT
)
433 clrbitn(ATT_PRINT_KEY
, bitmap
);
435 km
->keys
[ATT_EXPORT_KEY
].name
= "E";
436 km
->keys
[ATT_EXPORT_KEY
].label
= N_("Export");
444 if(F_ON(F_ARROW_NAV
, ps
)){
445 menu_add_binding(km
, KEY_LEFT
, MC_EXIT
);
446 menu_add_binding(km
, KEY_RIGHT
, MC_VIEW_ATCH
);
449 menu_clear_binding(km
, KEY_LEFT
);
450 menu_clear_binding(km
, KEY_RIGHT
);
453 draw_keymenu(km
, bitmap
, ps
->ttyo
->screen_cols
, 1-FOOTER_ROWS(ps
),
458 mark_keymenu_dirty();
462 if(F_ON(F_SHOW_CURSOR
, ps
))
463 MoveCursor(dline
, 0);
465 MoveCursor(MAX(0, ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
)), 0);
467 /*------ Prepare to read the command from the keyboard ----*/
469 mouse_in_content(KEY_MOUSE
, -1, -1, 0, 0); /* prime the handler */
470 register_mfunc(mouse_in_content
, HEADER_ROWS(ps_global
), 0,
471 ps_global
->ttyo
->screen_rows
-(FOOTER_ROWS(ps_global
)+1),
472 ps_global
->ttyo
->screen_cols
);
474 ch
= READ_COMMAND(&utf8str
);
476 clear_mfunc(mouse_in_content
);
479 cmd
= menu_command(ch
, &att_index_keymenu
);
497 if(FOOTER_ROWS(ps
) == 1 && km_popped
== 0){
499 ps
->mangled_footer
= 1;
503 helper(h_attachment_screen
, _("HELP FOR ATTACHMENT INDEX"), 0);
504 ps
->mangled_screen
= 1;
509 ps
->mangled_footer
= 1;
514 if(ps
->full_header
== 1){
515 if(!(ps
->quote_suppression_threshold
516 && (ps
->some_quoting_was_suppressed
/* || in_index != View */)))
519 else if(ps
->full_header
> 2)
522 switch(ps
->full_header
){
524 q_status_message(SM_ORDER
, 0, 3,
525 _("Display of full headers is now off."));
529 q_status_message1(SM_ORDER
, 0, 3,
530 _("Quotes displayed, use %s to see full headers"),
531 F_ON(F_USE_FK
, ps
) ? "F9" : "H");
535 q_status_message(SM_ORDER
, 0, 3,
536 _("Display of full headers is now on."));
543 case MC_EXIT
: /* exit attachment screen */
544 ps
->next_screen
= mail_view_screen
;
548 ps
->next_screen
= quit_screen
;
552 ps
->next_screen
= main_menu_screen
;
556 ps
->next_screen
= mail_index_screen
;
560 if((ctmp
= next_attline(current
)) != NULL
)
563 q_status_message(SM_ORDER
, 0, 1, _("Already on last attachment"));
568 if((ctmp
= prev_attline(current
)) != NULL
)
571 q_status_message(SM_ORDER
, 0, 1, _("Already on first attachment"));
575 case MC_PAGEDN
: /* page forward */
576 if(next_attline(current
)){
577 while(dline
++ < ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
))
578 if((ctmp
= next_attline(current
)) != NULL
)
584 q_status_message(SM_ORDER
, 0, 1,
585 _("Already on last page of attachments"));
589 case MC_PAGEUP
: /* page backward */
590 if(prev_attline(current
)){
591 while(dline
-- > HEADER_ROWS(ps
))
592 if((ctmp
= prev_attline(current
)) != NULL
)
597 while(++dline
< ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
))
598 if((ctmp
= prev_attline(current
)) != NULL
)
604 q_status_message(SM_ORDER
, 0, 1,
605 _("Already on first page of attachments"));
614 mouse_get_last (NULL
, &mp
);
615 mp
.row
-= HEADER_ROWS(ps
);
616 ctmp
= screen
.top_line
;
617 while (mp
.row
&& ctmp
!= NULL
) {
626 if(mp
.button
== M_BUTTON_LEFT
)
627 display_attachment(msgno
, current
->attp
, DA_SAVE
);
630 else if(mp
.button
== M_BUTTON_RIGHT
){
631 MPopup atmt_popup
[20];
632 int i
= -1, exoffer
= 0;
634 dline
= attachment_screen_updater(ps
,current
,&screen
);
636 if(dispatch_attachment(current
->attp
) != MCD_NONE
){
637 atmt_popup
[++i
].type
= tQueue
;
638 atmt_popup
[i
].data
.val
= 'V';
639 atmt_popup
[i
].label
.style
= lNormal
;
640 atmt_popup
[i
].label
.string
= "&View";
642 if(!(current
->attp
->can_display
& MCD_EXTERNAL
)
643 && (current
->attp
->body
->type
== TYPETEXT
644 || MIME_MSG_A(current
->attp
)
645 || MIME_DGST_A(current
->attp
))){
647 atmt_popup
[++i
].type
= tIndex
;
648 atmt_popup
[i
].label
.style
= lNormal
;
649 atmt_popup
[i
].label
.string
=
650 "View in New Window";
654 atmt_popup
[++i
].type
= tQueue
;
655 atmt_popup
[i
].data
.val
= 'S';
656 atmt_popup
[i
].label
.style
= lNormal
;
657 atmt_popup
[i
].label
.string
= "&Save";
659 atmt_popup
[++i
].type
= tQueue
;
660 atmt_popup
[i
].label
.style
= lNormal
;
661 if(current
->dstring
[1] == 'D'){
662 atmt_popup
[i
].data
.val
= 'U';
663 atmt_popup
[i
].label
.string
= "&Undelete";
666 atmt_popup
[i
].data
.val
= 'D';
667 atmt_popup
[i
].label
.string
= "&Delete";
670 if(MIME_MSG_A(current
->attp
)){
671 atmt_popup
[++i
].type
= tQueue
;
672 atmt_popup
[i
].label
.style
= lNormal
;
673 atmt_popup
[i
].label
.string
= "&Reply...";
674 atmt_popup
[i
].data
.val
= 'R';
676 atmt_popup
[++i
].type
= tQueue
;
677 atmt_popup
[i
].label
.style
= lNormal
;
678 atmt_popup
[i
].label
.string
= "&Forward...";
679 atmt_popup
[i
].data
.val
= 'F';
682 atmt_popup
[++i
].type
= tQueue
;
683 atmt_popup
[i
].label
.style
= lNormal
;
684 atmt_popup
[i
].label
.string
= "&About...";
685 atmt_popup
[i
].data
.val
= 'A';
687 atmt_popup
[++i
].type
= tSeparator
;
689 atmt_popup
[++i
].type
= tQueue
;
690 snprintf(backtag
, sizeof(backtag
), "View Message #%ld",
691 mn_get_cur(ps
->msgmap
));
692 backtag
[sizeof(backtag
)-1] = '\0';
693 atmt_popup
[i
].label
.string
= backtag
;
694 atmt_popup
[i
].label
.style
= lNormal
;
695 atmt_popup
[i
].data
.val
= '<';
697 atmt_popup
[++i
].type
= tTail
;
699 if(mswin_popup(atmt_popup
) == 1 && exoffer
)
700 display_att_window(current
->attp
);
703 else if(mp
.button
== M_BUTTON_RIGHT
){
704 MPopup atmt_popup
[2];
706 atmt_popup
[0].type
= tQueue
;
707 snprintf(backtag
, sizeof(backtag
), "View Message #%ld",
708 mn_get_cur(ps
->msgmap
));
709 backtag
[sizeof(backtag
)-1] = '\0';
710 atmt_popup
[0].label
.string
= backtag
;
711 atmt_popup
[0].label
.style
= lNormal
;
712 atmt_popup
[0].data
.val
= '<';
714 atmt_popup
[1].type
= tTail
;
716 mswin_popup(atmt_popup
);
723 case MC_WHEREIS
: /* whereis */
724 /*--- get string ---*/
726 char *result
= NULL
, buf
[64];
727 static char last
[64], tmp
[64];
730 ps
->mangled_footer
= 1;
732 snprintf(tmp
, sizeof(tmp
), "Word to find %s%s%s: ",
733 (last
[0]) ? "[" : "",
734 (last
[0]) ? last
: "",
735 (last
[0]) ? "]" : "");
736 tmp
[sizeof(tmp
)-1] = '\0';
739 int flags
= OE_APPEND_CURRENT
| OE_SEQ_SENSITIVE
;
741 rc
= optionally_enter(buf
,-FOOTER_ROWS(ps
),0,sizeof(buf
),
742 tmp
,NULL
,help
,&flags
);
744 help
= help
== NO_HELP
? h_attach_index_whereis
: NO_HELP
;
745 else if(rc
== 0 || rc
== 1 || !buf
[0]){
746 if(rc
== 0 && !buf
[0] && last
[0]){
747 strncpy(buf
, last
, sizeof(buf
));
748 buf
[sizeof(buf
)-1] = '\0';
755 if(rc
== 0 && buf
[0]){
757 while((ctmp
= next_attline(ctmp
)) != NULL
)
758 if(srchstr(ctmp
->dstring
, buf
)){
764 ctmp
= first_attline(current
);
766 while(ctmp
!= current
)
767 if(srchstr(ctmp
->dstring
, buf
)){
772 ctmp
= next_attline(ctmp
);
776 result
= _("WhereIs cancelled");
779 strncpy(last
, buf
, sizeof(last
));
780 last
[sizeof(last
)-1] = '\0';
781 result
= "Word found";
785 q_status_message(SM_ORDER
, 0, 3,
786 result
? result
: _("Word not found"));
792 if(delete_attachment(msgno
, current
->attp
)){
793 int l
= current
? strlen(current
->attp
->number
) : 0;
795 current
->dstring
[1] = 'D';
797 /* Also indicate any children that will be deleted */
799 for(ctmp
= current
; ctmp
; ctmp
= next_attline(ctmp
))
800 if(!strncmp(ctmp
->attp
->number
, current
->attp
->number
, l
)
801 && ctmp
->attp
->number
[l
] == '.'){
802 ctmp
->dstring
[1] = 'D';
803 ps
->mangled_screen
= 1;
810 if(undelete_attachment(msgno
, current
->attp
, &expbits
)){
811 int l
= current
? strlen(current
->attp
->number
) : 0;
813 current
->dstring
[1] = ' ';
815 /* And unflag anything implicitly undeleted */
816 for(ctmp
= current
; ctmp
; ctmp
= next_attline(ctmp
))
817 if(!strncmp(ctmp
->attp
->number
, current
->attp
->number
, l
)
818 && ctmp
->attp
->number
[l
] == '.'
819 && (!msgno_exceptions(ps
->mail_stream
, msgno
,
820 ctmp
->attp
->number
, &expbits
, FALSE
)
821 || !(expbits
& MSG_EX_DELETE
))){
822 ctmp
->dstring
[1] = ' ';
823 ps
->mangled_screen
= 1;
830 reply_msg_att(ps
->mail_stream
, msgno
, current
->attp
);
834 forward_attachment(ps
->mail_stream
, msgno
, current
->attp
);
838 bounce_msg_att(ps
->mail_stream
, msgno
, current
->attp
->number
,
839 current
->attp
->body
->nested
.msg
->env
->subject
);
840 ps
->mangled_footer
= 1;
844 display_attach_info(msgno
, current
->attp
);
847 case MC_VIEW_ATCH
: /* View command */
848 display_attachment(msgno
, current
->attp
, DA_SAVE
);
850 /* fall thru to repaint */
852 case MC_REPAINT
: /* redraw */
854 ps
->mangled_screen
= 1;
858 export_attachment(-FOOTER_ROWS(ps
), msgno
, current
->attp
);
859 ps
->mangled_footer
= 1;
862 case MC_SAVETEXT
: /* Save command */
863 save_attachment(-FOOTER_ROWS(ps
), msgno
, current
->attp
);
864 ps
->mangled_footer
= 1;
867 case MC_PRINTMSG
: /* Save command */
868 print_attachment(-FOOTER_ROWS(ps
), msgno
, current
->attp
);
869 ps
->mangled_footer
= 1;
872 case MC_PIPE
: /* Pipe command */
873 if(F_ON(F_ENABLE_PIPE
, ps
)){
874 pipe_attachment(msgno
, current
->attp
);
875 ps
->mangled_footer
= 1;
877 } /* fall thru to complain */
879 case MC_NONE
: /* simple timeout */
883 bogus_utf8_command(utf8str
, F_ON(F_USE_FK
, ps
) ? "F1" : "?");
894 bogus_command(ch
, F_ON(F_USE_FK
, ps
) ? "F1" : "?");
899 for(current
= first_attline(current
); current
;){ /* clean up */
900 ctmp
= current
->next
;
901 free_attline(¤t
);
905 if(screen
.titlecolor
)
906 free_color_pair(&screen
.titlecolor
);
910 /*----------------------------------------------------------------------
911 allocate and attach a fresh attachment line struct
913 Args: current -- display line to attache new struct to
915 Returns: newly alloc'd attachment display line
918 new_attline(ATDISP_S
**current
)
922 p
= (ATDISP_S
*)fs_get(sizeof(ATDISP_S
));
923 memset((void *)p
, 0, sizeof(ATDISP_S
));
926 p
->next
= (*current
)->next
;
927 (*current
)->next
= p
;
940 /*----------------------------------------------------------------------
941 Release system resources associated with attachment display line
943 Args: p -- line to free
948 free_attline(ATDISP_S
**p
)
952 fs_give((void **)&(*p
)->dstring
);
959 /*----------------------------------------------------------------------
960 Manage display of the attachment screen menu body.
962 Args: ps -- pine struct pointer
963 current -- currently selected display line
964 screen -- reference points for display painting
969 attachment_screen_updater(struct pine
*ps
, ATDISP_S
*current
, ATT_SCREEN_S
*screen
)
971 int dline
, return_line
= HEADER_ROWS(ps
);
972 ATDISP_S
*top_line
, *ctmp
;
974 /* calculate top line of display */
976 ctmp
= top_line
= first_attline(current
);
978 if(((dline
++)%(ps
->ttyo
->screen_rows
-HEADER_ROWS(ps
)-FOOTER_ROWS(ps
)))==0)
980 while(ctmp
!= current
&& (ctmp
= next_attline(ctmp
)));
983 /* Don't know how to manage scroll bar for attachment screen yet. */
984 scroll_setrange (0L, 0L);
987 /* mangled body or new page, force redraw */
988 if(ps
->mangled_body
|| screen
->top_line
!= top_line
)
989 screen
->current
= NULL
;
991 /* loop thru painting what's needed */
992 for(dline
= 0, ctmp
= top_line
;
993 dline
< ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
) - HEADER_ROWS(ps
);
994 dline
++, ctmp
= next_attline(ctmp
)){
997 * only fall thru painting if something needs painting...
999 if(!(!screen
->current
|| ctmp
== screen
->current
|| ctmp
== current
))
1002 if(ctmp
&& ctmp
->dstring
){
1003 char *p
= tmp_20k_buf
;
1004 int i
, col
, x
= 0, totlen
;
1006 if(F_ON(F_FORCE_LOW_SPEED
,ps
) || ps
->low_speed
){
1008 if(ctmp
== current
){
1009 return_line
= dline
+ HEADER_ROWS(ps
);
1010 PutLine0(dline
+ HEADER_ROWS(ps
), 0, "->");
1013 PutLine0(dline
+ HEADER_ROWS(ps
), 0, " ");
1016 * Only paint lines if we have to...
1021 else if(ctmp
== current
){
1022 return_line
= dline
+ HEADER_ROWS(ps
);
1026 totlen
= strlen(ctmp
->dstring
);
1029 * Copy the value to a temp buffer expanding tabs.
1030 * Assume the caller set the widths so as not to overflow the
1033 for(i
=0,col
=x
; ctmp
->dstring
[i
]; i
++){
1034 if(ctmp
->dstring
[i
] == TAB
){
1035 if((p
-tmp_20k_buf
) < SIZEOF_20KBUF
-8)
1038 while((++col
)&0x07);
1041 col
+= width_at_this_position((unsigned char *) &ctmp
->dstring
[i
], totlen
-i
);
1042 if((p
-tmp_20k_buf
) < SIZEOF_20KBUF
)
1043 *p
++ = ctmp
->dstring
[i
];
1048 if((p
-tmp_20k_buf
) < SIZEOF_20KBUF
)
1051 PutLine0(dline
+ HEADER_ROWS(ps
), x
, tmp_20k_buf
+ x
);
1054 && !(F_ON(F_FORCE_LOW_SPEED
,ps
) || ps
->low_speed
))
1058 ClearLine(dline
+ HEADER_ROWS(ps
));
1061 ps
->mangled_body
= 0;
1062 screen
->top_line
= top_line
;
1063 screen
->current
= current
;
1064 return(return_line
);
1068 /*----------------------------------------------------------------------
1069 Redraw the attachment screen based on the global "att_screen" struct
1076 attachment_screen_redrawer(void)
1080 update_att_screen_titlebar();
1081 ps_global
->mangled_header
= 0;
1084 ps_global
->mangled_body
= 1;
1085 (void)attachment_screen_updater(ps_global
,att_screen
->current
,att_screen
);
1088 draw_keymenu(&att_index_keymenu
, bitmap
, ps_global
->ttyo
->screen_cols
,
1089 1-FOOTER_ROWS(ps_global
), 0, SameMenu
);
1094 update_att_screen_titlebar(void)
1097 COLOR_PAIR
*returned_color
= NULL
;
1098 COLOR_PAIR
*titlecolor
= NULL
;
1100 SEARCHSET
*ss
= NULL
;
1101 PAT_STATE
*pstate
= NULL
;
1103 if(ps_global
->titlebar_color_style
!= TBAR_COLOR_DEFAULT
){
1104 raw_msgno
= mn_m2raw(ps_global
->msgmap
, mn_get_cur(ps_global
->msgmap
));
1105 ss
= mail_newsearchset();
1106 ss
->first
= ss
->last
= (unsigned long) raw_msgno
;
1109 colormatch
= get_index_line_color(ps_global
->mail_stream
,
1110 ss
, &pstate
, &returned_color
);
1111 mail_free_searchset(&ss
);
1114 * This is a bit tricky. If there is a colormatch but
1116 * is NULL, that means that the user explicitly wanted the
1117 * Normal color used in this index line, so that is what we
1118 * use. If no colormatch then we will use the TITLE color
1119 * instead of Normal.
1123 titlecolor
= returned_color
;
1125 titlecolor
= new_color_pair(ps_global
->VAR_NORM_FORE_COLOR
,
1126 ps_global
->VAR_NORM_BACK_COLOR
);
1130 && ps_global
->titlebar_color_style
== TBAR_COLOR_REV_INDEXLINE
){
1131 char cbuf
[MAXCOLORLEN
+1];
1133 strncpy(cbuf
, titlecolor
->fg
, sizeof(cbuf
));
1134 cbuf
[sizeof(cbuf
)-1] = '\0';
1135 strncpy(titlecolor
->fg
, titlecolor
->bg
, MAXCOLORLEN
);
1136 titlecolor
->fg
[MAXCOLORLEN
] = '\0';
1137 strncpy(titlecolor
->bg
, cbuf
, MAXCOLORLEN
);
1138 titlecolor
->bg
[MAXCOLORLEN
] = '\0';
1142 /* Did the color change? */
1143 if((!titlecolor
&& att_screen
->titlecolor
)
1145 (titlecolor
&& !att_screen
->titlecolor
)
1147 (titlecolor
&& att_screen
->titlecolor
1148 && (strcmp(titlecolor
->fg
, att_screen
->titlecolor
->fg
)
1149 || strcmp(titlecolor
->bg
, att_screen
->titlecolor
->bg
)))){
1151 if(att_screen
->titlecolor
)
1152 free_color_pair(&att_screen
->titlecolor
);
1154 att_screen
->titlecolor
= titlecolor
;
1159 free_color_pair(&titlecolor
);
1162 set_titlebar(_("ATTACHMENT INDEX"), ps_global
->mail_stream
,
1163 ps_global
->context_current
, ps_global
->cur_folder
,
1164 ps_global
->msgmap
, 1, MessageNumber
, 0, 0,
1165 att_screen
->titlecolor
);
1169 /*----------------------------------------------------------------------
1170 Seek back from the given display line to the beginning of the list
1172 Args: p -- display linked list
1177 first_attline(ATDISP_S
*p
)
1187 init_att_progress(char *msg
, MAILSTREAM
*stream
, struct mail_bodystruct
*body
)
1189 if((save_att_length
= body
->size
.bytes
) != 0){
1190 /* if there are display filters, factor in extra copy */
1191 if(body
->type
== TYPETEXT
&& ps_global
->VAR_DISPLAY_FILTERS
)
1192 save_att_length
+= body
->size
.bytes
;
1194 /* if remote folder and segment not cached, factor in IMAP fetch */
1195 if(stream
&& stream
->mailbox
&& IS_REMOTE(stream
->mailbox
)
1196 && !((body
->type
== TYPETEXT
&& body
->contents
.text
.data
)
1197 || ((body
->type
== TYPEMESSAGE
)
1198 && body
->nested
.msg
&& body
->nested
.msg
->text
.text
.data
)
1199 || body
->contents
.text
.data
))
1200 save_att_length
+= body
->size
.bytes
;
1202 gf_filter_init(); /* reset counters */
1205 return(busy_cue(msg
, save_att_percent
, 0));
1213 save_att_piped(int reset
)
1221 else if((y
= gf_bytes_piped()) >= x
){
1231 save_att_percent(void)
1233 int i
= (int) (((pine_gets_bytes(0) + save_att_piped(0)) * 100)
1235 return(MIN(i
, 100));
1239 /*----------------------------------------------------------------------
1240 Save the given attachment associated with the given message no
1247 save_attachment(int qline
, long int msgno
, ATTACH_S
*a
)
1249 if(ps_global
->restricted
){
1250 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
1251 "Alpine demo can't save attachments");
1256 save_msg_att(msgno
, a
);
1257 else if(MIME_DGST_A(a
))
1258 save_digest_att(msgno
, a
);
1259 else if(MIME_VCARD_A(a
))
1260 save_vcard_att(ps_global
, qline
, msgno
, a
);
1262 write_attachment(qline
, msgno
, a
, "SAVE");
1266 /*----------------------------------------------------------------------
1267 Save the given attachment associated with the given message no
1274 export_attachment(int qline
, long int msgno
, ATTACH_S
*a
)
1276 if(ps_global
->restricted
){
1277 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
1278 "Alpine demo can't export attachments");
1283 export_msg_att(msgno
, a
);
1284 else if(MIME_DGST_A(a
))
1285 export_digest_att(msgno
, a
);
1287 q_status_message1(SM_ORDER
, 0, 3,
1288 _("Can't Export %s. Use \"Save\" to write file, \"<\" to leave index."),
1289 body_type_names(a
->body
->type
));
1294 write_attachment(int qline
, long int msgno
, ATTACH_S
*a
, char *method
)
1296 char filename
[MAXPATH
+1], full_filename
[MAXPATH
+1],
1297 title_buf
[64], *err
;
1298 int r
, rflags
= GER_NONE
, we_cancel
= 0, flags
;
1299 static HISTORY_S
*history
= NULL
;
1300 static ESCKEY_S att_save_opts
[] = {
1301 {ctrl('T'), 10, "^T", N_("To Files")},
1302 {-1, 0, NULL
, NULL
},
1303 {-1, 0, NULL
, NULL
},
1304 {-1, 0, NULL
, NULL
}};
1306 /*------- Figure out suggested file name ----*/
1307 filename
[0] = full_filename
[0] = '\0';
1308 (void) get_filename_parameter(filename
, sizeof(filename
), a
->body
, NULL
);
1310 dprint((9, "export_attachment(name: %s)\n",
1311 filename
? filename
: "?"));
1314 #if !defined(DOS) && !defined(MAC) && !defined(OS2)
1315 if(ps_global
->VAR_DOWNLOAD_CMD
&& ps_global
->VAR_DOWNLOAD_CMD
[0]){
1316 att_save_opts
[++r
].ch
= ctrl('V');
1317 att_save_opts
[r
].rval
= 12;
1318 att_save_opts
[r
].name
= "^V";
1319 att_save_opts
[r
].label
= N_("Downld Msg");
1321 #endif /* !(DOS || MAC) */
1323 if(F_ON(F_ENABLE_TAB_COMPLETE
,ps_global
)){
1324 att_save_opts
[++r
].ch
= ctrl('I');
1325 att_save_opts
[r
].rval
= 11;
1326 att_save_opts
[r
].name
= "TAB";
1327 att_save_opts
[r
].label
= N_("Complete");
1330 att_save_opts
[++r
].ch
= -1;
1332 snprintf(title_buf
, sizeof(title_buf
), "%s ATTACHMENT", method
);
1333 title_buf
[sizeof(title_buf
)-1] = '\0';
1335 flags
= (a
&& a
->body
&& a
->body
->type
== TYPETEXT
? GE_BINARY
: 0)
1338 r
= get_export_filename(ps_global
, filename
, NULL
, full_filename
,
1339 sizeof(filename
), "attachment", title_buf
,
1340 att_save_opts
, &rflags
, qline
, flags
, &history
);
1345 cmd_cancelled((char *) lcase((unsigned char *) title_buf
+ 1) - 1);
1349 q_status_message1(SM_ORDER
, 0, 2,
1350 _("Can't save to file outside of %s"),
1351 ps_global
->VAR_OPER_DIR
);
1357 #if !defined(DOS) && !defined(MAC) && !defined(OS2)
1358 else if(r
== 12){ /* Download */
1359 char cmd
[MAXPATH
], *tfp
= NULL
;
1364 char prompt_buf
[256];
1366 if(ps_global
->restricted
){
1367 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
1368 "Download disallowed in restricted mode");
1373 tfp
= temp_nam(NULL
, "pd");
1374 dprint((1, "Download attachment called!\n"));
1375 if((store
= so_get(FileStar
, tfp
, WRITE_ACCESS
|OWNER_ONLY
|WRITE_TO_LOCALE
)) != NULL
){
1377 snprintf(prompt_buf
, sizeof(prompt_buf
), "Saving to \"%s\"", tfp
);
1378 prompt_buf
[sizeof(prompt_buf
)-1] = '\0';
1379 we_cancel
= init_att_progress(prompt_buf
,
1380 ps_global
->mail_stream
,
1383 gf_set_so_writec(&pc
, store
);
1384 if((err
= detach(ps_global
->mail_stream
, msgno
,
1385 a
->number
, 0L, &len
, pc
, NULL
, 0)) != NULL
)
1386 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
1387 "%s: Error writing attachment to \"%s\"",
1390 /* cancel regardless, so it doesn't get in way of xfer */
1393 gf_clear_so_writec(store
);
1394 if(so_give(&store
)) /* close file */
1395 err
= "Error writing tempfile for download";
1398 build_updown_cmd(cmd
, sizeof(cmd
), ps_global
->VAR_DOWNLOAD_CMD_PREFIX
,
1399 ps_global
->VAR_DOWNLOAD_CMD
, tfp
);
1400 if((syspipe
= open_system_pipe(cmd
, NULL
, NULL
,
1401 PIPE_USER
| PIPE_RESET
,
1402 0, pipe_callback
, pipe_report_error
)) != NULL
)
1403 (void)close_system_pipe(&syspipe
, NULL
, pipe_callback
);
1405 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
1406 err
= "Error running download command");
1410 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
1411 err
= "Error building temp file for download");
1415 fs_give((void **)&tfp
);
1419 q_status_message1(SM_ORDER
, 0, 4, "Part %s downloaded",
1424 #endif /* !(DOS || MAC) */
1426 (void) write_attachment_to_file(ps_global
->mail_stream
, msgno
, a
,
1427 rflags
, full_filename
);
1433 * msgno -- raw message number
1434 * a -- attachment struct
1435 * flags -- comes from get_export_filename
1436 * GER_OVER -- the file was truncated before we wrote
1437 * GER_APPEND -- the file was not truncated prior to our writing,
1438 * so we were appending
1439 * else -- the file didn't previously exist
1440 * file -- the full pathname of the file
1442 * Returns 1 for successful write, 0 for nothing to write, -1 for error
1445 write_attachment_to_file(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
, int flags
, char *file
)
1447 char *l_string
, sbuf
[256], *err
;
1448 int is_text
, we_cancel
= 0, dt_flags
= 0, so_flags
;
1449 long len
, orig_size
;
1453 if(!(a
&& a
->body
&& a
->number
&& a
->number
[0] && file
&& file
[0]
1457 is_text
= (a
&& a
->body
&& a
->body
->type
== TYPETEXT
);
1459 if(flags
& GER_APPEND
)
1460 orig_size
= name_file_size(file
);
1462 if(flags
& GER_BINARY
)
1463 dt_flags
|= DT_BINARY
;
1465 so_flags
= (is_text
& !(flags
& GER_BINARY
) ? WRITE_TO_LOCALE
: 0)
1468 store
= so_get(FileStar
, file
, so_flags
);
1470 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
1471 /* TRANSLATORS: Error opening destination <filename>: <error text> */
1472 _("Error opening destination %s: %s"),
1473 file
, error_description(errno
));
1477 snprintf(sbuf
, sizeof(sbuf
), "Saving to \"%s\"", file
);
1478 sbuf
[sizeof(sbuf
)-1] = '\0';
1479 we_cancel
= init_att_progress(sbuf
, stream
, a
->body
);
1481 gf_set_so_writec(&pc
, store
);
1482 err
= detach(stream
, msgno
, a
->number
, 0L, &len
, pc
, NULL
, dt_flags
);
1483 gf_clear_so_writec(store
);
1488 if(so_give(&store
)) /* close file */
1489 err
= error_description(errno
);
1492 if(!(flags
& (GER_APPEND
| GER_OVER
)))
1495 our_truncate(file
, (flags
& GER_APPEND
) ? (off_t
) orig_size
: (off_t
) 0);
1497 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
1498 /* TRANSLATORS: <error text>: Error writing attachment to <filename> */
1499 _("%s: Error writing attachment to \"%s\""),
1504 l_string
= cpystr(byte_string(len
));
1505 q_status_message8(SM_ORDER
, 0, 4,
1506 "Part %s, %s%s %s to \"%s\"%s%s%s",
1509 ? comatose(a
->body
->size
.lines
) : l_string
,
1510 is_text
? " lines" : "",
1513 : flags
& GER_APPEND
? "appended" : "written",
1515 (is_text
|| len
== a
->body
->size
.bytes
)
1516 ? "" : "(decoded from ",
1517 (is_text
|| len
== a
->body
->size
.bytes
)
1518 ? "" : byte_string(a
->body
->size
.bytes
),
1519 is_text
|| len
== a
->body
->size
.bytes
1521 fs_give((void **)&l_string
);
1528 write_attached_msg(long int msgno
, ATTACH_S
**ap
, STORE_S
*store
, int newfile
)
1531 long start_of_append
;
1535 if(ap
&& *ap
&& (*ap
)->body
&& (*ap
)->body
->nested
.msg
1536 && (*ap
)->body
->nested
.msg
->env
){
1537 start_of_append
= so_tell(store
);
1539 gf_set_so_writec(&pc
, store
);
1540 if(!(ps_global
->mail_stream
&& msgno
> 0L
1541 && msgno
<= ps_global
->mail_stream
->nmsgs
1542 && (mc
= mail_elt(ps_global
->mail_stream
, msgno
)) && mc
->valid
))
1545 if(!bezerk_delimiter((*ap
)->body
->nested
.msg
->env
, mc
, pc
, newfile
)
1546 || !format_msg_att(msgno
, ap
, NULL
, pc
, FM_NOINDENT
))
1547 err
= error_description(errno
);
1549 gf_clear_so_writec(store
);
1552 ftruncate(fileno((FILE *)store
->txt
), (off_t
) start_of_append
);
1555 err
= "Can't export message. Missing Envelope data";
1561 /*----------------------------------------------------------------------
1562 Save the attachment message/rfc822 to specified folder
1569 save_msg_att(long int msgno
, ATTACH_S
*a
)
1571 char newfolder
[MAILTMPLEN
], *save_folder
, *flags
= NULL
;
1572 char date
[64], nmsgs
[80];
1573 CONTEXT_S
*cntxt
= NULL
;
1574 int our_stream
= 0, rv
;
1575 MAILSTREAM
*save_stream
;
1578 snprintf(nmsgs
, sizeof(nmsgs
), _("Attached Msg (part %s) "), a
->number
);
1579 nmsgs
[sizeof(nmsgs
)-1] = '\0';
1580 if(save_prompt(ps_global
, &cntxt
, newfolder
, sizeof(newfolder
), nmsgs
,
1581 a
->body
->nested
.msg
->env
, msgno
, a
->number
, NULL
, NULL
)){
1582 if(strucmp(newfolder
, ps_global
->inbox_name
) == 0){
1583 save_folder
= ps_global
->VAR_INBOX_PATH
;
1587 save_folder
= newfolder
;
1589 save_stream
= save_msg_stream(cntxt
, save_folder
, &our_stream
);
1591 mc
= (msgno
> 0L && ps_global
->mail_stream
1592 && msgno
<= ps_global
->mail_stream
->nmsgs
)
1593 ? mail_elt(ps_global
->mail_stream
, msgno
) : NULL
;
1594 flags
= flag_string(ps_global
->mail_stream
, msgno
, F_ANS
|F_FLAG
|F_SEEN
|F_KEYWORD
);
1596 mail_date(date
, mc
);
1600 if(pith_opt_save_size_changed_prompt
)
1601 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_INIT
);
1603 rv
= save_msg_att_work(msgno
, a
, save_stream
, save_folder
, cntxt
, date
);
1605 if(pith_opt_save_size_changed_prompt
)
1606 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_END
);
1609 fs_give((void **) &flags
);
1612 q_status_message2(SM_ORDER
, 0, 4,
1613 _("Attached message (part %s) saved to \"%s\""),
1617 cmd_cancelled("Attached message Save");
1618 /* else whatever broke in save_fetch_append shoulda bitched */
1621 mail_close(save_stream
);
1626 /*----------------------------------------------------------------------
1627 Save the message/rfc822 in the given digest to the specified folder
1634 save_digest_att(long int msgno
, ATTACH_S
*a
)
1636 char newfolder
[MAILTMPLEN
], *save_folder
,
1637 date
[64], nmsgs
[80];
1638 CONTEXT_S
*cntxt
= NULL
;
1639 int our_stream
= 0, rv
, cnt
= 0;
1640 MAILSTREAM
*save_stream
;
1645 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
));
1647 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
))
1650 snprintf(nmsgs
, sizeof(nmsgs
), "%d Msg Digest (part %s) ", cnt
, a
->number
);
1651 nmsgs
[sizeof(nmsgs
)-1] = '\0';
1653 if(save_prompt(ps_global
, &cntxt
, newfolder
, sizeof(newfolder
),
1654 nmsgs
, NULL
, 0, NULL
, NULL
, NULL
)){
1655 save_folder
= (strucmp(newfolder
, ps_global
->inbox_name
) == 0)
1656 ? ps_global
->VAR_INBOX_PATH
: newfolder
;
1658 save_stream
= save_msg_stream(cntxt
, save_folder
, &our_stream
);
1660 if(pith_opt_save_size_changed_prompt
)
1661 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_INIT
);
1665 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
));
1667 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
)){
1669 rv
= save_msg_att_work(msgno
, ap
, save_stream
, save_folder
, cntxt
, date
);
1674 if(pith_opt_save_size_changed_prompt
)
1675 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_END
);
1678 q_status_message2(SM_ORDER
, 0, 4,
1679 _("Attached digest (part %s) saved to \"%s\""),
1683 cmd_cancelled("Attached digest Save");
1684 /* else whatever broke in save_fetch_append shoulda bitched */
1687 mail_close(save_stream
);
1693 save_msg_att_work(long int msgno
, ATTACH_S
*a
, MAILSTREAM
*save_stream
,
1694 char *save_folder
, CONTEXT_S
*cntxt
, char *date
)
1699 if(a
&& a
->body
&& MIME_MSG(a
->body
->type
, a
->body
->subtype
)){
1700 if((so
= so_get(CharStar
, NULL
, WRITE_ACCESS
)) != NULL
){
1702 rv
= save_fetch_append(ps_global
->mail_stream
, msgno
,
1704 save_stream
, save_folder
, cntxt
,
1705 a
->body
->size
.bytes
,
1709 dprint((1, "Can't allocate store for save: %s\n",
1710 error_description(errno
)));
1711 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
1712 _("Problem creating space for message text."));
1721 /*----------------------------------------------------------------------
1722 Export the attachment message/rfc822 to specified file
1729 export_msg_att(long int msgno
, ATTACH_S
*a
)
1731 char filename
[MAXPATH
+1], full_filename
[MAXPATH
+1], *err
;
1732 int rv
, rflags
= GER_NONE
, i
= 1;
1735 static HISTORY_S
*history
= NULL
;
1736 static ESCKEY_S opts
[] = {
1737 {ctrl('T'), 10, "^T", N_("To Files")},
1738 {-1, 0, NULL
, NULL
},
1739 {-1, 0, NULL
, NULL
}};
1741 if(F_ON(F_ENABLE_TAB_COMPLETE
,ps_global
)){
1742 opts
[i
].ch
= ctrl('I');
1744 opts
[i
].name
= "TAB";
1745 opts
[i
].label
= N_("Complete");
1748 filename
[0] = full_filename
[0] = '\0';
1750 rv
= get_export_filename(ps_global
, filename
, NULL
, full_filename
,
1751 sizeof(filename
), "msg attachment",
1752 /* TRANSLATORS: Message Attachment (a screen title) */
1753 _("MSG ATTACHMENT"), opts
,
1754 &rflags
, -FOOTER_ROWS(ps_global
),
1755 GE_IS_EXPORT
| GE_SEQ_SENSITIVE
, &history
);
1760 cmd_cancelled("Export");
1764 q_status_message1(SM_ORDER
, 0, 2,
1765 _("Can't export to file outside of %s"),
1766 ps_global
->VAR_OPER_DIR
);
1773 /* With name in hand, allocate storage object and save away... */
1774 if((store
= so_get(FileStar
, full_filename
, WRITE_ACCESS
)) != NULL
){
1775 if((err
= write_attached_msg(msgno
, &ap
, store
, !(rflags
& GER_APPEND
))) != NULL
)
1776 q_status_message(SM_ORDER
| SM_DING
, 3, 4, err
);
1778 q_status_message3(SM_ORDER
, 0, 4,
1779 _("Attached message (part %s) %s to \"%s\""),
1783 : rflags
& GER_APPEND
? _("appended") : _("written"),
1787 q_status_message2(SM_ORDER
| SM_DING
, 3, 4,
1788 _("Error writing %s: %s"),
1789 full_filename
, error_description(errno
));
1792 q_status_message2(SM_ORDER
| SM_DING
, 3, 4,
1793 /* TRANSLATORS: Error opening file <filename> to export message: <error text> */
1794 _("Error opening file \"%s\" to export message: %s"),
1795 full_filename
, error_description(errno
));
1799 /*----------------------------------------------------------------------
1800 Export the message/rfc822 in the given digest to the specified file
1807 export_digest_att(long int msgno
, ATTACH_S
*a
)
1809 char filename
[MAXPATH
+1], full_filename
[MAXPATH
+1], *err
= NULL
;
1810 int rv
, rflags
= GER_NONE
, i
= 1;
1813 static HISTORY_S
*history
= NULL
;
1815 static ESCKEY_S opts
[] = {
1816 {ctrl('T'), 10, "^T", N_("To Files")},
1817 {-1, 0, NULL
, NULL
},
1818 {-1, 0, NULL
, NULL
}};
1820 if(F_ON(F_ENABLE_TAB_COMPLETE
,ps_global
)){
1821 opts
[i
].ch
= ctrl('I');
1823 opts
[i
].name
= "TAB";
1824 opts
[i
].label
= N_("Complete");
1827 filename
[0] = full_filename
[0] = '\0';
1829 rv
= get_export_filename(ps_global
, filename
, NULL
, full_filename
,
1830 sizeof(filename
), "digest", _("DIGEST ATTACHMENT"),
1831 opts
, &rflags
, -FOOTER_ROWS(ps_global
),
1832 GE_IS_EXPORT
| GE_SEQ_SENSITIVE
, &history
);
1837 cmd_cancelled("Export");
1841 q_status_message1(SM_ORDER
, 0, 2,
1842 _("Can't export to file outside of %s"),
1843 ps_global
->VAR_OPER_DIR
);
1850 /* With name in hand, allocate storage object and save away... */
1851 if((store
= so_get(FileStar
, full_filename
, WRITE_ACCESS
)) != NULL
){
1856 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
))
1859 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
)){
1861 err
= write_attached_msg(msgno
, &ap
, store
,
1862 !count
&& !(rflags
& GER_APPEND
));
1867 err
= error_description(errno
);
1870 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
1871 _("Error exporting: %s"), err
);
1872 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
1873 _("%s messages exported before error occurred"), err
);
1876 q_status_message4(SM_ORDER
, 0, 4,
1877 "%s messages in digest (part %s) %s to \"%s\"",
1882 : rflags
& GER_APPEND
? "appended" : "written",
1886 q_status_message2(SM_ORDER
| SM_DING
, 3, 4,
1887 _("Error opening file \"%s\" to export digest: %s"),
1888 full_filename
, error_description(errno
));
1892 /*----------------------------------------------------------------------
1893 Print the given attachment associated with the given message no
1900 print_attachment(int qline
, long int msgno
, ATTACH_S
*a
)
1904 if(ps_global
->restricted
){
1905 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
1906 "Alpine demo can't Print attachments");
1910 snprintf(prompt
, sizeof(prompt
), "attach%s %s",
1911 (a
->body
->type
== TYPETEXT
) ? "ment" : "ed message",
1912 MIME_DGST_A(a
) ? "digest" : a
->number
);
1913 prompt
[sizeof(prompt
)-1] = '\0';
1914 if(open_printer(prompt
) >= 0){
1916 (void) print_msg_att(msgno
, a
, 1);
1917 else if(MIME_DGST_A(a
))
1918 print_digest_att(msgno
, a
);
1920 (void) decode_text(a
, msgno
, print_char
, NULL
, QStatus
, FM_NOINDENT
);
1928 * Print the attachment message/rfc822 to specified file
1930 * Returns 1 on success, 0 on failure.
1933 print_msg_att(long int msgno
, ATTACH_S
*a
, int first
)
1938 if(!(ps_global
->mail_stream
&& msgno
> 0L
1939 && msgno
<= ps_global
->mail_stream
->nmsgs
1940 && (mc
= mail_elt(ps_global
->mail_stream
, msgno
)) && mc
->valid
))
1943 if(((!first
&& F_ON(F_AGG_PRINT_FF
, ps_global
)) ? print_char(FORMFEED
) : 1)
1944 && pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
)
1945 && (F_ON(F_FROM_DELIM_IN_PRINT
, ps_global
)
1946 ? bezerk_delimiter(a
->body
->nested
.msg
->env
, mc
, print_char
, !first
)
1948 && format_msg_att(msgno
, &ap
, NULL
, print_char
, FM_NOINDENT
))
1952 q_status_message2(SM_ORDER
| SM_DING
, 3, 3,
1953 _("Error printing message %s, part %s"),
1954 long2string(msgno
), a
->number
);
1959 /*----------------------------------------------------------------------
1960 Print the attachment message/rfc822 to specified file
1967 print_digest_att(long int msgno
, ATTACH_S
*a
)
1974 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
));
1976 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
)){
1977 char *p
= part_desc(ap
->number
, ap
->body
->nested
.msg
->body
,
1978 0, 80, FM_NOINDENT
, print_char
);
1980 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
1981 _("Can't print digest: %s"), p
);
1984 else if(!print_msg_att(msgno
, ap
, !next
))
1993 /*----------------------------------------------------------------------
1994 Unpack and display the given attachment associated with given message no.
1996 Args: msgno -- message no attachment is part of
1997 a -- attachment to display
1999 Returns: 0 on success, non-zero (and error message queued) otherwise
2002 display_attachment(long int msgno
, ATTACH_S
*a
, int flags
)
2004 char *filename
= NULL
;
2005 char sender_filename
[1000];
2010 int we_cancel
= 0, rv
;
2015 /*------- Display the attachment -------*/
2016 if(dispatch_attachment(a
) == MCD_NONE
){
2017 /*----- Can't display this type ------*/
2018 if(a
->body
->encoding
< ENCOTHER
)
2019 q_status_message4(SM_ORDER
| SM_DING
, 3, 5,
2020 /* TRANSLATORS: Don't know how to display <certain type> attachments. <might say Try Save.> */
2021 _("Don't know how to display %s%s%s attachments.%s"),
2022 body_type_names(a
->body
->type
),
2023 a
->body
->subtype
? "/" : "",
2024 a
->body
->subtype
? a
->body
->subtype
:"",
2025 (flags
& DA_SAVE
) ? _(" Try Save.") : "");
2027 q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2028 _("Don't know how to unpack \"%s\" encoding"),
2029 body_encodings
[(a
->body
->encoding
<= ENCMAX
)
2030 ? a
->body
->encoding
: ENCOTHER
]);
2034 else if(!(a
->can_display
& MCD_EXTERNAL
)){
2035 if(a
->body
->type
== TYPEMULTIPART
){
2036 if(a
->body
->subtype
){
2037 if(!strucmp(a
->body
->subtype
, "digest"))
2038 display_digest_att(msgno
, a
, flags
);
2040 q_status_message1(SM_ORDER
, 3, 5,
2041 _("Can't display Multipart/%s"),
2045 q_status_message(SM_ORDER
, 3, 5,
2046 _("Can't display unknown Multipart Subtype"));
2048 else if(MIME_VCARD_A(a
))
2049 display_vcard_att(msgno
, a
, flags
);
2050 else if( MIME_VCALENDAR(a
->body
->type
, a
->body
->subtype
))
2051 display_vcalendar_att(msgno
, a
, flags
);
2052 else if(a
->body
->type
== TYPETEXT
){
2054 rv
= display_text_att(msgno
, a
, flags
);
2055 } while(rv
== MC_FULLHDR
);
2057 else if(a
->body
->type
== TYPEMESSAGE
){
2059 rv
= display_msg_att(msgno
, a
, flags
);
2060 } while(rv
== MC_FULLHDR
);
2063 ps_global
->mangled_screen
= 1;
2067 /* arrive here if MCD_EXTERNAL */
2069 if(F_OFF(F_QUELL_ATTACH_EXTRA_PROMPT
, ps_global
)
2070 && (!(flags
& DA_DIDPROMPT
)))
2071 if(want_to(_("View selected Attachment"), 'y',
2072 0, NO_HELP
, WT_NORM
) == 'n'){
2073 cmd_cancelled(NULL
);
2077 sender_filename
[0] = '\0';
2081 if(F_OFF(F_QUELL_ATTACH_EXT_WARN
, ps_global
)
2082 && (a
->can_display
& MCD_EXT_PROMPT
)){
2085 (void) get_filename_parameter(sender_filename
, sizeof(sender_filename
),
2087 snprintf(prompt
, sizeof(prompt
),
2088 "Attachment %s%s unrecognized. %s%s%s",
2090 strlen(a
->body
->subtype
) > 12 ? "..." : "",
2091 (extp
&& extp
[0]) ? "Try open by file extension (." : "Try opening anyway",
2092 (extp
&& extp
[0]) ? extp
: "",
2093 (extp
&& extp
[0]) ? ")" : "");
2095 if(want_to(prompt
, 'n', 0, NO_HELP
, WT_NORM
) == 'n'){
2096 cmd_cancelled(NULL
);
2101 /*------ Write the image to a temporary file ------*/
2103 /* create type/subtype in mtype */
2104 strncpy(mtype
, body_type_names(a
->body
->type
), sizeof(mtype
));
2105 mtype
[sizeof(mtype
)-1] = '\0';
2106 if(a
->body
->subtype
){
2107 strncat(mtype
, "/", sizeof(mtype
)-strlen(mtype
)-1);
2108 mtype
[sizeof(mtype
)-1] = '\0';
2109 strncat(mtype
, a
->body
->subtype
, sizeof(mtype
)-strlen(mtype
)-1);
2110 mtype
[sizeof(mtype
)-1] = '\0';
2114 * If we haven't already gotten the filename parameter, get it
2115 * now. It may be used in the temporary filename and possibly
2116 * for its extension.
2118 if(!sender_filename
[0])
2119 (void) get_filename_parameter(sender_filename
, sizeof(sender_filename
),
2122 if(check_mime_type_by_extension(extp
, mtype
)
2123 || (!set_mime_extension_by_type(ext
, mtype
) /* extension from type */
2124 && extp
&& extp
[0])){ /* extension from filename */
2125 strncpy(ext
, extp
, sizeof(ext
));
2126 ext
[sizeof(ext
)-1] = '\0';
2129 /* create a temp file */
2130 if(sender_filename
){
2133 /* get rid of any extension */
2134 if(mt_get_file_ext(sender_filename
, &q
) && q
&& q
> sender_filename
)
2137 /* be careful about what is allowed in the filename */
2138 for(p
= sender_filename
; *p
; p
++)
2139 if(!(isascii((unsigned char) *p
)
2140 && (isalnum((unsigned char) *p
)
2141 || *p
== '-' || *p
== '_' || *p
== '+' || *p
== '.' || *p
== '=')))
2144 if(!*p
) /* filename was ok to use */
2145 snprintf(prefix
, sizeof(prefix
), "img-%s-", sender_filename
);
2148 /* didn't get it yet */
2150 snprintf(prefix
, sizeof(prefix
), "img-%s-", (a
->body
->subtype
)
2151 ? a
->body
->subtype
: "unk");
2154 /* We are creating a temporary name. This is just a prefix. If you
2155 * need the original name, use the save command, so if the prefix
2156 * is too long, shorten it.
2158 if (strlen(prefix
) > 9){
2163 filename
= temp_nam_ext(NULL
, prefix
, ext
);
2166 q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2167 _("Error \"%s\", Can't create temporary file"),
2168 error_description(errno
));
2172 if((store
= so_get(FileStar
, filename
, WRITE_ACCESS
|OWNER_ONLY
)) == NULL
){
2173 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
2174 _("Error \"%s\", Can't write file %s"),
2175 error_description(errno
), filename
);
2177 our_unlink(filename
);
2178 fs_give((void **)&filename
);
2185 if(a
->body
->size
.bytes
){
2188 snprintf(msg_buf
, sizeof(msg_buf
), "Decoding %s%s%s%s",
2189 a
->description
? "\"" : "",
2190 a
->description
? a
->description
: "attachment number ",
2191 a
->description
? "" : a
->number
,
2192 a
->description
? "\"" : "");
2193 msg_buf
[sizeof(msg_buf
)-1] = '\0';
2194 we_cancel
= init_att_progress(msg_buf
, ps_global
->mail_stream
,
2198 if(a
->body
->type
== TYPEMULTIPART
){
2199 char *h
= mail_fetch_mime(ps_global
->mail_stream
, msgno
, a
->number
,
2202 /* Write to store while converting newlines */
2204 if(*h
== '\015' && *(h
+1) == '\012'){
2205 so_puts(store
, NEWLINE
);
2209 so_writec(*h
++, store
);
2212 gf_set_so_writec(&pc
, store
);
2214 err
= detach(ps_global
->mail_stream
, msgno
, a
->number
, 0L, NULL
, pc
, NULL
, 0);
2216 gf_clear_so_writec(store
);
2224 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
2225 "%s: Error saving image to temp file %s",
2228 our_unlink(filename
);
2229 fs_give((void **)&filename
);
2235 /*----- Run the viewer process ----*/
2236 run_viewer(filename
, a
->body
, a
->can_display
& MCD_EXT_PROMPT
);
2238 fs_give((void **)&filename
);
2244 /*----------------------------------------------------------------------
2245 Fish the required command from mailcap and run it
2247 Args: image_file -- The name of the file to pass viewer
2248 body -- body struct containing type/subtype of part
2250 A side effect may be that scrolltool is called as well if
2251 exec_mailcap_cmd has any substantial output...
2254 run_viewer(char *image_file
, struct mail_bodystruct
*body
, int chk_extension
)
2256 MCAP_CMD_S
*mc_cmd
= NULL
;
2257 int needs_terminal
= 0, we_cancel
= 0;
2259 we_cancel
= busy_cue("Displaying attachment", NULL
, 0);
2261 if((mc_cmd
= mailcap_build_command(body
->type
, body
->subtype
,
2263 &needs_terminal
, chk_extension
)) != NULL
){
2265 cancel_busy_cue(-1);
2267 exec_mailcap_cmd(mc_cmd
, image_file
, needs_terminal
);
2269 fs_give((void **)&mc_cmd
->command
);
2270 fs_give((void **)&mc_cmd
);
2274 cancel_busy_cue(-1);
2276 q_status_message1(SM_ORDER
, 3, 4, _("Cannot display %s attachment"),
2277 type_desc(body
->type
, body
->subtype
,
2278 body
->parameter
, NULL
, 1));
2283 /*----------------------------------------------------------------------
2284 Detach and provide for browsing a text body part
2286 Args: msgno -- raw message number to get part from
2287 a -- attachment struct for the desired part
2292 format_text_att(long int msgno
, ATTACH_S
*a
, HANDLE_S
**handlesp
)
2297 if((store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) != NULL
){
2299 init_handles(handlesp
);
2301 gf_set_so_writec(&pc
, store
);
2302 (void) decode_text(a
, msgno
, pc
, handlesp
, QStatus
, FM_DISPLAY
);
2303 gf_clear_so_writec(store
);
2310 /*----------------------------------------------------------------------
2311 Detach and provide for browsing a text body part
2313 Args: msgno -- raw message number to get part from
2314 a -- attachment struct for the desired part
2319 display_text_att(long int msgno
, ATTACH_S
*a
, int flags
)
2322 HANDLE_S
*handles
= NULL
;
2326 clear_index_cache_ent(ps_global
->mail_stream
, msgno
, 0);
2328 if((store
= format_text_att(msgno
, a
, &handles
)) != NULL
){
2329 rv
= scroll_attachment("ATTACHED TEXT", store
, CharStar
, handles
, a
, flags
);
2330 free_handles(&handles
);
2331 so_give(&store
); /* free resources associated with store */
2334 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2335 _("Error allocating space for attachment."));
2341 /*----------------------------------------------------------------------
2342 Detach and provide for browsing a body part of type "MESSAGE"
2344 Args: msgno -- message number to get partrom
2345 a -- attachment struct for the desired part
2350 display_msg_att(long int msgno
, ATTACH_S
*a
, int flags
)
2355 HANDLE_S
*handles
= NULL
;
2359 clear_index_cache_ent(ps_global
->mail_stream
, msgno
, 0);
2361 /* BUG, should check this return code */
2362 (void) pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
);
2364 /* initialize a storage object */
2365 if(!(store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
2366 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2367 _("Error allocating space for message."));
2371 gf_set_so_writec(&pc
, store
);
2373 if(format_msg_att(msgno
, &ap
, &handles
, pc
, FM_DISPLAY
)){
2374 if(ps_global
->full_header
== 2)
2375 q_status_message(SM_INFO
, 0, 3,
2376 _("Full header mode ON. All header text being included"));
2378 rv
= scroll_attachment((a
->body
->subtype
2379 && !strucmp(a
->body
->subtype
, "delivery-status"))
2380 ? "DELIVERY STATUS REPORT" : "ATTACHED MESSAGE",
2381 store
, CharStar
, handles
, a
, flags
);
2382 free_handles(&handles
);
2385 gf_clear_so_writec(store
);
2387 so_give(&store
); /* free resources associated with store */
2392 /*----------------------------------------------------------------------
2393 Detach and provide for browsing a multipart body part of type "DIGEST"
2395 Args: msgno -- message number to get partrom
2396 a -- attachment struct for the desired part
2401 display_digest_att(long int msgno
, ATTACH_S
*a
, int flags
)
2405 HANDLE_S
*handles
= NULL
;
2407 SourceType src
= CharStar
;
2411 clear_index_cache_ent(ps_global
->mail_stream
, msgno
, 0);
2413 /* BUG, should check this return code */
2414 (void) pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
);
2416 if(!(store
= so_get(src
, NULL
, EDIT_ACCESS
))){
2417 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2418 _("Error allocating space for message."));
2422 gf_set_so_writec(&pc
, store
);
2425 * While in a subtype of this message
2429 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
))
2432 if(ap
->body
->type
== TYPEMESSAGE
){
2435 if(ap
->body
->subtype
&& strucmp(ap
->body
->subtype
, "rfc822")){
2438 tsub
= cpystr(ap
->body
->subtype
);
2439 convert_possibly_encoded_str_to_utf8((char **) &tsub
);
2440 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "Unknown Message subtype: %s", tsub
);
2441 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
2443 if((errstr
= format_editorial(tmp_20k_buf
,
2444 ps_global
->ttyo
->screen_cols
, 0,
2445 NULL
, pc
)) != NULL
){
2446 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
2447 _("Can't format digest: %s"), errstr
);
2450 else if(!gf_puts(NEWLINE
, pc
))
2453 fs_give((void **) &tsub
);
2456 if((errstr
= part_desc(ap
->number
, ap
->body
->nested
.msg
->body
,
2457 0, ps_global
->ttyo
->screen_cols
, FM_DISPLAY
, pc
)) != NULL
){
2458 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
2459 _("Can't format digest: %s"), errstr
);
2462 else if(!format_msg_att(msgno
, &ap
, &handles
, pc
, FM_DISPLAY
))
2466 else if(ap
->body
->type
== TYPETEXT
2467 && decode_text(ap
, msgno
, pc
, NULL
, QStatus
, FM_DISPLAY
))
2469 else if(!gf_puts("Unknown type in Digest", pc
))
2474 if(ps_global
->full_header
== 2)
2475 q_status_message(SM_INFO
, 0, 3,
2476 _("Full header mode ON. All header text being included"));
2478 scroll_attachment(_("ATTACHED MESSAGES"), store
, src
, handles
, a
, flags
);
2481 free_handles(&handles
);
2483 gf_clear_so_writec(store
);
2484 so_give(&store
); /* free resources associated with store */
2489 scroll_attachment(char *title
, STORE_S
*store
, SourceType src
, HANDLE_S
*handles
, ATTACH_S
*a
, int flags
)
2493 memset(&sargs
, 0, sizeof(SCROLL_S
));
2494 sargs
.text
.text
= so_text(store
);
2495 sargs
.text
.src
= src
;
2496 sargs
.text
.desc
= "attachment";
2497 sargs
.text
.handles
= handles
;
2498 sargs
.bar
.title
= title
;
2499 sargs
.proc
.tool
= process_attachment_cmd
;
2500 sargs
.proc
.data
.p
= (void *) a
;
2501 sargs
.help
.text
= h_mail_text_att_view
;
2502 sargs
.help
.title
= _("HELP FOR ATTACHED TEXT VIEW");
2503 sargs
.keys
.menu
= &att_view_keymenu
;
2504 setbitmap(sargs
.keys
.bitmap
);
2506 /* First, fix up "back" key */
2507 if(flags
& DA_FROM_VIEW
){
2508 att_view_keymenu
.keys
[ATV_BACK_KEY
].label
= N_("MsgText");
2511 att_view_keymenu
.keys
[ATV_BACK_KEY
].label
= N_("AttchIndex");
2515 clrbitn(ATV_VIEW_HILITE
, sargs
.keys
.bitmap
);
2516 clrbitn(ATV_PREV_URL
, sargs
.keys
.bitmap
);
2517 clrbitn(ATV_NEXT_URL
, sargs
.keys
.bitmap
);
2520 if(F_OFF(F_ENABLE_PIPE
, ps_global
))
2521 clrbitn(ATV_PIPE_KEY
, sargs
.keys
.bitmap
);
2523 if(!(a
->body
->type
== TYPETEXT
|| MIME_MSG_A(a
) || MIME_DGST_A(a
)))
2524 clrbitn(ATV_PRINT_KEY
, sargs
.keys
.bitmap
);
2527 * If message or digest, leave Reply and Save and,
2528 * conditionally, Bounce on...
2531 if(F_OFF(F_ENABLE_BOUNCE
, ps_global
))
2532 clrbitn(ATV_BOUNCE_KEY
, sargs
.keys
.bitmap
);
2535 clrbitn(ATV_BOUNCE_KEY
, sargs
.keys
.bitmap
);
2536 clrbitn(ATV_REPLY_KEY
, sargs
.keys
.bitmap
);
2537 clrbitn(ATV_EXPORT_KEY
, sargs
.keys
.bitmap
);
2540 if(!(ps_global
->smime
&& ps_global
->smime
->need_passphrase
))
2541 clrbitn(ATV_DECRYPT_KEY
, sargs
.keys
.bitmap
);
2543 if(F_ON(F_DONT_DO_SMIME
, ps_global
) || !MIME_MSG_A(a
)){
2544 clrbitn(ATV_DECRYPT_KEY
, sargs
.keys
.bitmap
);
2545 clrbitn(ATV_SECURITY_KEY
, sargs
.keys
.bitmap
);
2549 sargs
.use_indexline_color
= 1;
2551 if(DA_RESIZE
& flags
)
2552 sargs
.resize_exit
= 1;
2556 sargs
.mouse
.popup
= scroll_att_popup
;
2559 return(scrolltool(&sargs
));
2564 display_smime_info_att(struct pine
*ps
, ATTACH_S
*a
)
2566 if(smime_check(a
->body
->nested
.msg
->body
) == 0){
2567 q_status_message(SM_ORDER
| SM_DING
, 0, 3,
2568 _("Not a signed or encrypted message"));
2572 display_smime_info(ps
, a
->body
->nested
.msg
->env
, a
->body
->nested
.msg
->body
);
2577 process_attachment_cmd(int cmd
, MSGNO_S
*msgmap
, SCROLL_S
*sparms
)
2580 long rawno
= mn_m2raw(msgmap
, mn_get_cur(msgmap
));
2581 #define AD(X) ((ATTACH_S *) (X)->proc.data.p)
2589 ps_global
->next_screen
= quit_screen
;
2593 ps_global
->next_screen
= main_menu_screen
;
2597 reply_msg_att(ps_global
->mail_stream
, rawno
, sparms
->proc
.data
.p
);
2601 forward_attachment(ps_global
->mail_stream
, rawno
, sparms
->proc
.data
.p
);
2605 bounce_msg_att(ps_global
->mail_stream
, rawno
, AD(sparms
)->number
,
2606 AD(sparms
)->body
->nested
.msg
->env
->subject
);
2607 ps_global
->mangled_footer
= 1;
2611 delete_attachment(rawno
, sparms
->proc
.data
.p
);
2615 if(undelete_attachment(rawno
, sparms
->proc
.data
.p
, &n
))
2616 q_status_message1(SM_ORDER
, 0, 3,
2617 "Part %s UNdeleted", AD(sparms
)->number
);
2622 save_attachment(-FOOTER_ROWS(ps_global
), rawno
, sparms
->proc
.data
.p
);
2623 ps_global
->mangled_footer
= 1;
2627 export_attachment(-FOOTER_ROWS(ps_global
), rawno
, sparms
->proc
.data
.p
);
2628 ps_global
->mangled_footer
= 1;
2632 print_attachment(-FOOTER_ROWS(ps_global
), rawno
, sparms
->proc
.data
.p
);
2633 ps_global
->mangled_footer
= 1;
2637 pipe_attachment(rawno
, sparms
->proc
.data
.p
);
2638 ps_global
->mangled_footer
= 1;
2642 ps_global
->full_header
++;
2643 if(ps_global
->full_header
== 1){
2644 if(!(ps_global
->quote_suppression_threshold
2645 && (ps_global
->some_quoting_was_suppressed
/* || in_index != View*/)))
2646 ps_global
->full_header
++;
2648 else if(ps_global
->full_header
> 2)
2649 ps_global
->full_header
= 0;
2651 switch(ps_global
->full_header
){
2653 q_status_message(SM_ORDER
, 0, 3,
2654 _("Display of full headers is now off."));
2658 q_status_message1(SM_ORDER
, 0, 3,
2659 _("Quotes displayed, use %s to see full headers"),
2660 F_ON(F_USE_FK
, ps_global
) ? "F9" : "H");
2664 q_status_message(SM_ORDER
, 0, 3,
2665 _("Display of full headers is now on."));
2675 if(ps_global
->smime
&& ps_global
->smime
->need_passphrase
)
2676 smime_get_passphrase();
2680 display_smime_info_att(ps_global
, sparms
->proc
.data
.p
);
2685 alpine_panic("Unexpected command case");
2694 * Returns 1 on success, 0 on error.
2697 format_msg_att(long int msgno
, ATTACH_S
**a
, HANDLE_S
**handlesp
, gf_io_t pc
, int flags
)
2701 if((*a
)->body
->type
!= TYPEMESSAGE
)
2702 return(gf_puts("[ Undisplayed Attachment of Type ", pc
)
2703 && gf_puts(body_type_names((*a
)->body
->type
), pc
)
2704 && gf_puts(" ]", pc
) && gf_puts(NEWLINE
, pc
));
2706 if((*a
)->body
->subtype
&& strucmp((*a
)->body
->subtype
, "rfc822") == 0){
2709 HD_INIT(&h
, ps_global
->VAR_VIEW_HEADERS
, ps_global
->view_all_except
,
2711 switch(format_header(ps_global
->mail_stream
, msgno
, (*a
)->number
,
2712 (*a
)->body
->nested
.msg
->env
, &h
, NULL
, NULL
,
2714 case -1 : /* write error */
2717 case 1 : /* fetch error */
2718 if(!(gf_puts("[ Error fetching header ]", pc
)
2719 && !gf_puts(NEWLINE
, pc
)))
2725 gf_puts(NEWLINE
, pc
);
2727 if(((*a
)+1)->description
)
2730 if(!(gf_puts("[Can't display missing text segment]", pc
)
2731 && gf_puts(NEWLINE
, pc
)))
2737 if((*a
)->body
&& (*a
)->body
->subtype
&& (strucmp((*a
)->body
->subtype
, OUR_PKCS7_ENCLOSURE_SUBTYPE
)==0)){
2738 if((*a
)->description
){
2739 if(!(!format_editorial((*a
)->description
,
2740 ps_global
->ttyo
->screen_cols
,
2742 && gf_puts(NEWLINE
, pc
) && gf_puts(NEWLINE
, pc
)))
2746 if(((*a
)+1)->description
)
2749 if(!(gf_puts("[Can't display missing text segment]", pc
)
2750 && gf_puts(NEWLINE
, pc
)))
2757 if(((*a
))->description
2758 && (*a
)->body
&& (*a
)->body
->type
== TYPETEXT
){
2759 if(decode_text(*a
, msgno
, pc
, NULL
, QStatus
, flags
))
2762 else if(!(gf_puts("[Can't display ", pc
)
2763 && gf_puts(((*a
)->description
&& (*a
)->body
)
2764 ? "first non-" : "missing ", pc
)
2765 && gf_puts("text segment]", pc
)
2766 && gf_puts(NEWLINE
, pc
)))
2769 if(((*a
)+1)->description
)
2772 if(!(gf_puts("[Can't display missing text segment]", pc
)
2773 && gf_puts(NEWLINE
, pc
)))
2779 else if((*a
)->body
->subtype
2780 && strucmp((*a
)->body
->subtype
, "external-body") == 0) {
2781 if(format_editorial("This part is not included and can be fetched as follows:",
2782 ps_global
->ttyo
->screen_cols
, flags
, NULL
, pc
)
2783 || !gf_puts(NEWLINE
, pc
)
2784 || format_editorial(display_parameters((*a
)->body
->parameter
),
2785 ps_global
->ttyo
->screen_cols
, flags
, handlesp
, pc
))
2788 else if(decode_text(*a
, msgno
, pc
, NULL
, QStatus
, flags
))
2796 display_vcard_att(long int msgno
, ATTACH_S
*a
, int flags
)
2798 STORE_S
*in_store
, *out_store
= NULL
;
2799 HANDLE_S
*handles
= NULL
;
2802 char **lines
, **ll
, *errstr
= NULL
, tmp
[MAILTMPLEN
], *p
;
2803 int cmd
, indent
, begins
= 0;
2805 lines
= detach_vcard_att(ps_global
->mail_stream
,
2806 msgno
, a
->body
, a
->number
);
2808 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2809 _("Error accessing attachment."));
2813 if(!(in_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
2814 free_list_array(&lines
);
2815 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2816 _("Error allocating space for attachment."));
2820 for(ll
= lines
, indent
= 0; ll
&& *ll
; ll
++)
2821 if((p
= strindex(*ll
, ':')) && p
- *ll
> indent
)
2825 for(ll
= lines
; ll
&& *ll
; ll
++){
2826 if((p
= strindex(*ll
, ':')) != NULL
){
2827 if(begins
< 2 && struncmp(*ll
, "begin:", 6) == 0)
2830 snprintf(tmp
, sizeof(tmp
), " %-*.*s : ", indent
- 5,
2831 (int) MIN(p
- *ll
, sizeof(tmp
)-5), *ll
);
2832 tmp
[sizeof(tmp
)-1] = '\0';
2833 so_puts(in_store
, tmp
);
2838 so_puts(in_store
, repeat_char(indent
, SPACE
));
2841 snprintf(tmp
, sizeof(tmp
), "%.200s", p
);
2842 tmp
[sizeof(tmp
)-1] = '\0';
2844 (char *)rfc1522_decode_to_utf8((unsigned char *)tmp_20k_buf
,
2845 SIZEOF_20KBUF
, tmp
));
2846 so_puts(in_store
, "\015\012");
2849 free_list_array(&lines
);
2851 so_puts(in_store
, "\015\012\015\012");
2854 if((out_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) != NULL
){
2855 so_seek(in_store
, 0L, 0);
2857 init_handles(&handles
);
2860 if(F_ON(F_VIEW_SEL_URL
, ps_global
)
2861 || F_ON(F_VIEW_SEL_URL_HOST
, ps_global
)
2862 || F_ON(F_SCAN_ADDR
, ps_global
))
2863 gf_link_filter(gf_line_test
,
2864 gf_line_test_opt(url_hilite
,
2865 gf_url_hilite_opt(&uh
,&handles
,0)));
2867 gf_link_filter(gf_wrap
,
2868 gf_wrap_filter_opt(ps_global
->ttyo
->screen_cols
- 4,
2869 ps_global
->ttyo
->screen_cols
,
2870 NULL
, indent
, GFW_HANDLES
));
2871 gf_link_filter(gf_nvtnl_local
, NULL
);
2873 gf_set_so_readc(&gc
, in_store
);
2874 gf_set_so_writec(&pc
, out_store
);
2876 errstr
= gf_pipe(gc
, pc
);
2878 gf_clear_so_readc(in_store
);
2881 #define VCARD_TEXT_ONE _("This is a vCard which has been forwarded to you. You may add parts of it to your address book with the Save command. You will have a chance to edit it before committing it to your address book.")
2882 #define VCARD_TEXT_MORE _("This is a vCard which has been forwarded to you. You may add the entries to your address book with the Save command.")
2883 errstr
= format_editorial((begins
> 1)
2884 ? VCARD_TEXT_MORE
: VCARD_TEXT_ONE
,
2885 ps_global
->ttyo
->screen_cols
, 0, NULL
, pc
);
2888 gf_clear_so_writec(out_store
);
2891 cmd
= scroll_attachment(_("ADDRESS BOOK ATTACHMENT"), out_store
,
2892 CharStar
, handles
, a
, flags
| DA_RESIZE
);
2894 free_handles(&handles
);
2895 so_give(&out_store
);
2898 errstr
= _("Error allocating space");
2900 while(!errstr
&& (cmd
== MC_RESIZE
|| cmd
== MC_FULLHDR
));
2903 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
2904 _("Can't format entry : %s"), errstr
);
2910 display_vevent_summary(long int msgno
, ATTACH_S
*a
, int flags
, int depth
)
2913 VCALENDAR_S
*vcal
= NULL
;
2914 char *b64text
, *caltext
;
2915 unsigned long callen
;
2916 VEVENT_SUMMARY_S
*vesy
, *vsummary
; /* vevent summary */
2917 STORE_S
*in_store
, *out_store
= NULL
;
2918 HANDLE_S
*handles
= NULL
;
2921 char *errstr
= NULL
, tmp
[MAILTMPLEN
], *p
;
2924 b
= mail_body(ps_global
->mail_stream
, msgno
, a
->number
);
2925 if(b
->sparep
== NULL
){
2926 b64text
= mail_fetch_body(ps_global
->mail_stream
, msgno
, a
->number
, &callen
, 0);
2927 b64text
[callen
] = '\0'; /* chop off cookie */
2928 caltext
= rfc822_base64(b64text
, strlen(b64text
), &callen
);
2929 vcal
= ical_parse_text(caltext
);
2930 b
->sparep
= create_body_sparep(iCalType
, (void *) vcal
);
2932 else if(get_body_sparep_type(b
->sparep
) == iCalType
)
2933 vcal
= (VCALENDAR_S
*) get_body_sparep_data(b
->sparep
);
2935 vsummary
= ical_vevent_summary(vcal
);
2937 if(vsummary
== NULL
){
2938 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2939 _("Error parsing event"));
2943 if(!(in_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
2944 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2945 _("Error allocating space to process Calendar"));
2949 if((out_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) == NULL
){
2950 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2951 _("Error allocating space to write Calendar"));
2955 gf_set_so_readc(&gc
, in_store
);
2956 gf_set_so_writec(&pc
, out_store
);
2958 for(vesy
= vsummary
, k
= 0; vesy
; vesy
= vesy
->next
, k
++){
2959 if(depth
>= 0 && k
!= depth
)
2963 so_puts(in_store
, _("This event was cancelled"));
2964 so_puts(in_store
, "\015\012");
2968 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%d %s",
2969 _("Priority: "), vesy
->priority
,
2970 vesy
->priority
== 5 ? _("(Normal)")
2971 : (vesy
->priority
< 5 ? _("(High)")
2973 so_puts(in_store
, tmp_20k_buf
);
2974 so_puts(in_store
, "\015\012");
2978 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
2979 _("Summary: "), vesy
->summary
);
2980 so_puts(in_store
, tmp_20k_buf
);
2981 so_puts(in_store
, "\015\012");
2985 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
2986 _("Sender: "), vesy
->sender
);
2987 so_puts(in_store
, tmp_20k_buf
);
2988 so_puts(in_store
, "\015\012");
2991 if(vesy
->organizer
){
2992 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
2993 _("Organizer: "), vesy
->organizer
);
2994 so_puts(in_store
, tmp_20k_buf
);
2995 so_puts(in_store
, "\015\012");
2999 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3000 _("Location: "), vesy
->location
);
3001 so_puts(in_store
, tmp_20k_buf
);
3002 so_puts(in_store
, "\015\012");
3006 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3007 _("Start Date: "), vesy
->evstart
);
3008 so_puts(in_store
, tmp_20k_buf
);
3009 so_puts(in_store
, "\015\012");
3013 for(i
= 0; vesy
->duration
[i
] != NULL
; i
++){
3014 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3015 _("Duration: "), vesy
->duration
[i
]);
3016 so_puts(in_store
, tmp_20k_buf
);
3017 so_puts(in_store
, "\015\012");
3019 } else if(vesy
->evend
){
3020 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3021 _("End Date: "), vesy
->evend
);
3022 so_puts(in_store
, tmp_20k_buf
);
3023 so_puts(in_store
, "\015\012");
3027 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3028 vcal
->method
? _("Created on: ") : _("Last Revised on; "),
3030 so_puts(in_store
, tmp_20k_buf
);
3031 so_puts(in_store
, "\015\012");
3034 if(vesy
->description
){
3038 so_puts(in_store
, "\015\012");
3040 for(i
= 0; vesy
->description
[i
] != NULL
; i
++){
3041 so_puts(in_store
, _("Description: "));
3042 /* Check if empty description */
3044 for(j
=0; empty
== 1 && vesy
->description
[i
][j
] != '\0'; j
++){
3045 c
= vesy
->description
[i
][j
];
3046 if(c
!= '\n' && c
!= ' ' && c
!= '\t')
3050 so_puts(in_store
, _("[ No description provided ]"));
3051 so_puts(in_store
, "\015\012");
3054 for(j
=0; vesy
->description
[i
][j
] != '\0'; j
++){
3055 c
= vesy
->description
[i
][j
];
3057 so_puts(in_store
, "\015\012");
3060 so_writec(c
, in_store
);
3063 so_puts(in_store
, "\015\012");
3068 so_puts(in_store
, "\015\012");
3069 so_puts(in_store
, _("List of Attendees:"));
3070 so_puts(in_store
, "\015\012");
3071 for(i
= 0; vesy
->attendee
[i
] != NULL
; i
++){
3072 so_puts(in_store
, vesy
->attendee
[i
]);
3073 so_puts(in_store
, "\015\012");
3075 so_puts(in_store
, "\015\012");
3078 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
3079 _("This event was tagged as a %s entry by the sender"), vesy
->class);
3080 so_puts(in_store
, tmp_20k_buf
);
3081 so_puts(in_store
, "\015\012\015\012");
3083 if(depth
< 0 && vesy
->next
){
3084 for(i
= 0; i
< ps_global
->ttyo
->screen_cols
&& i
< 40; i
++)
3085 tmp_20k_buf
[i
] = '-';
3086 tmp_20k_buf
[i
]= '\0';
3087 so_puts(in_store
, tmp_20k_buf
);
3088 so_puts(in_store
, "\015\012");
3090 } /* end "for" loop */
3093 so_seek(in_store
, 0L, 0);
3095 init_handles(&handles
);
3098 if(F_ON(F_VIEW_SEL_URL
, ps_global
)
3099 || F_ON(F_VIEW_SEL_URL_HOST
, ps_global
)
3100 || F_ON(F_SCAN_ADDR
, ps_global
))
3101 gf_link_filter(gf_line_test
,
3102 gf_line_test_opt(url_hilite
,
3103 gf_url_hilite_opt(&uh
,&handles
,0)));
3105 gf_link_filter(gf_wrap
,
3106 gf_wrap_filter_opt(ps_global
->ttyo
->screen_cols
- 4,
3107 ps_global
->ttyo
->screen_cols
,
3108 NULL
, 0, GFW_HANDLES
));
3109 gf_link_filter(gf_nvtnl_local
, NULL
);
3111 gf_set_so_readc(&gc
, in_store
);
3112 gf_set_so_writec(&pc
, out_store
);
3114 errstr
= gf_pipe(gc
, pc
);
3116 gf_clear_so_readc(in_store
);
3118 gf_clear_so_writec(out_store
);
3121 cmd
= scroll_attachment(_("CALENDAR EVENT ATTACHMENT"), out_store
,
3122 CharStar
, handles
, a
, flags
| DA_RESIZE
);
3124 free_handles(&handles
);
3125 so_give(&out_store
);
3127 while(!errstr
&& (cmd
== MC_RESIZE
|| cmd
== MC_FULLHDR
));
3130 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
3131 _("Can't format entry : %s"), errstr
);
3133 free_vevent_summary(&vsummary
);
3134 ps_global
->mangled_screen
= 1;
3139 display_vcalendar_att(long int msgno
, ATTACH_S
*a
, int flags
)
3141 display_vevent_summary(msgno
, a
, flags
, -1);
3145 /*----------------------------------------------------------------------
3146 Display attachment information
3148 Args: msgno -- message number to get partrom
3149 a -- attachment struct for the desired part
3151 Result: a screen containing information about attachment:
3154 display_attach_info(long int msgno
, ATTACH_S
*a
)
3156 int i
, indent
, cols
;
3157 char buf1
[100], *folded
;
3162 (void) dispatch_attachment(a
);
3164 if(!(store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
3165 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
3166 _("Error allocating space for message."));
3170 cols
= ps_global
->ttyo
->screen_cols
;
3174 * 16 for text (longest is Display Method == 14)
3179 /* don't try stupid folding */
3180 cols
= MAX(indent
+10, cols
);
3182 so_puts(store
, "Details about Attachment #");
3183 so_puts(store
, a
->number
);
3184 so_puts(store
, " :\n\n");
3185 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Type");
3186 so_puts(store
, buf1
);
3187 so_puts(store
, body_type_names(a
->body
->type
));
3188 so_puts(store
, "\n");
3189 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Subtype");
3190 so_puts(store
, buf1
);
3191 so_puts(store
, a
->body
->subtype
? a
->body
->subtype
: "Unknown");
3192 so_puts(store
, "\n");
3193 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Encoding");
3194 so_puts(store
, buf1
);
3195 so_puts(store
, a
->body
->encoding
< ENCMAX
3196 ? body_encodings
[a
->body
->encoding
]
3198 so_puts(store
, "\n");
3199 if((plist
= rfc2231_newparmlist(a
->body
->parameter
)) != NULL
){
3200 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Parameters");
3201 so_puts(store
, buf1
);
3203 while(rfc2231_list_params(plist
)){
3205 so_puts(store
, repeat_char(indent
, ' '));
3207 so_puts(store
, plist
->attrib
);
3208 so_puts(store
, " = ");
3209 so_puts(store
, plist
->value
? plist
->value
: "");
3210 so_puts(store
, "\n");
3213 rfc2231_free_parmlist(&plist
);
3216 if(a
->body
->description
&& a
->body
->description
[0]){
3217 char buftmp
[MAILTMPLEN
];
3220 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Description");
3222 snprintf(buftmp
, sizeof(buftmp
), "%s", a
->body
->description
);
3223 buftmp
[sizeof(buftmp
)-1] = '\0';
3224 q
= rfc1522_decode_to_utf8((unsigned char *)tmp_20k_buf
, SIZEOF_20KBUF
, buftmp
);
3225 folded
= fold((char *) q
, cols
, cols
, buf1
, repeat_char(indent
+1, ' '), FLD_NONE
);
3228 so_puts(store
, folded
);
3229 fs_give((void **) &folded
);
3233 /* BUG: no a->body->language support */
3235 if(a
->body
->disposition
.type
){
3236 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Disposition");
3237 so_puts(store
, buf1
);
3238 so_puts(store
, a
->body
->disposition
.type
);
3239 so_puts(store
, "\n");
3240 if((plist
= rfc2231_newparmlist(a
->body
->disposition
.parameter
)) != NULL
){
3241 while(rfc2231_list_params(plist
)){
3242 so_puts(store
, repeat_char(indent
, ' '));
3243 so_puts(store
, plist
->attrib
);
3244 so_puts(store
, " = ");
3245 so_puts(store
, plist
->value
? plist
->value
: "");
3246 so_puts(store
, "\n");
3249 rfc2231_free_parmlist(&plist
);
3253 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Approx. Size");
3254 so_puts(store
, buf1
);
3255 so_puts(store
, comatose((a
->body
->encoding
== ENCBASE64
)
3256 ? ((a
->body
->size
.bytes
* 3)/4)
3257 : a
->body
->size
.bytes
));
3258 so_puts(store
, " bytes\n");
3259 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Display Method");
3260 so_puts(store
, buf1
);
3261 if(a
->can_display
== MCD_NONE
) {
3262 so_puts(store
, "Can't, ");
3263 so_puts(store
, (a
->body
->encoding
< ENCOTHER
)
3264 ? "Unknown Attachment Format"
3265 : "Unknown Encoding");
3267 else if(!(a
->can_display
& MCD_EXTERNAL
)){
3268 so_puts(store
, "Alpine's Internal Pager");
3271 int nt
, free_pretty_cmd
;
3275 if((mc_cmd
= mailcap_build_command(a
->body
->type
, a
->body
->subtype
,
3276 a
->body
, "<datafile>", &nt
,
3277 a
->can_display
& MCD_EXT_PROMPT
)) != NULL
){
3278 so_puts(store
, "\"");
3279 if((pretty_cmd
= execview_pretty_command(mc_cmd
, &free_pretty_cmd
)) != NULL
)
3280 so_puts(store
, pretty_cmd
);
3281 so_puts(store
, "\"");
3282 if(free_pretty_cmd
&& pretty_cmd
)
3283 fs_give((void **)&pretty_cmd
);
3285 fs_give((void **)&mc_cmd
->command
);
3286 fs_give((void **)&mc_cmd
);
3290 so_puts(store
, "\n");
3292 memset(&sargs
, 0, sizeof(SCROLL_S
));
3293 sargs
.text
.text
= so_text(store
);
3294 sargs
.text
.src
= CharStar
;
3295 sargs
.text
.desc
= "attachment info";
3296 sargs
.bar
.title
= _("ABOUT ATTACHMENT");
3297 sargs
.help
.text
= h_simple_text_view
;
3298 sargs
.help
.title
= _("HELP FOR \"ABOUT ATTACHMENT\"");
3300 sargs
.use_indexline_color
= 1;
3304 so_give(&store
); /* free resources associated with store */
3305 ps_global
->mangled_screen
= 1;
3309 /*----------------------------------------------------------------------
3313 forward_attachment(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
)
3321 forward_msg_att(stream
, msgno
, a
);
3324 ACTION_S
*role
= NULL
;
3325 REDRAFT_POS_S
*redraft_pos
= NULL
;
3326 long rflags
= ROLE_FORWARD
;
3329 outgoing
= mail_newenvelope();
3330 outgoing
->message_id
= generate_message_id();
3331 outgoing
->subject
= cpystr("Forwarded attachment...");
3333 if(nonempty_patterns(rflags
, &dummy
)){
3335 * There is no message, but a Current Folder Type might match.
3337 * This has been changed to check against the message
3338 * containing the attachment.
3340 role
= set_role_from_msg(ps_global
, ROLE_FORWARD
, msgno
, NULL
);
3341 if(confirm_role(rflags
, &role
))
3342 role
= combine_inherited_role(role
);
3345 cmd_cancelled("Forward");
3346 mail_free_envelope(&outgoing
);
3352 q_status_message1(SM_ORDER
, 3, 4,
3353 _("Forwarding using role \"%s\""), role
->nick
);
3356 * as with all text bound for the composer, build it in
3357 * a storage object of the type it understands...
3359 if((msgtext
= (void *) so_get(PicoText
, NULL
, EDIT_ACCESS
)) != NULL
){
3360 int impl
, template_len
= 0;
3362 if(role
&& role
->template){
3366 filtered
= detoken(role
, NULL
, 0, 0, 0, &redraft_pos
, &impl
);
3369 so_puts((STORE_S
*)msgtext
, filtered
);
3371 template_len
= strlen(filtered
);
3374 fs_give((void **)&filtered
);
3380 if((sig
= detoken(role
, NULL
, 2, 0, 1, &redraft_pos
, &impl
)) != NULL
){
3382 redraft_pos
->offset
+= template_len
;
3384 so_puts((STORE_S
*)msgtext
, *sig
? sig
: NEWLINE
);
3386 fs_give((void **)&sig
);
3389 so_puts((STORE_S
*)msgtext
, NEWLINE
);
3391 /*---- New Body to start with ----*/
3392 body
= mail_newbody();
3393 body
->type
= TYPEMULTIPART
;
3395 /*---- The TEXT part/body ----*/
3396 body
->nested
.part
= mail_newbody_part();
3397 body
->nested
.part
->body
.type
= TYPETEXT
;
3398 body
->nested
.part
->body
.contents
.text
.data
= msgtext
;
3400 /*---- The corresponding things we're attaching ----*/
3401 body
->nested
.part
->next
= mail_newbody_part();
3402 body
->nested
.part
->next
->body
.id
= generate_message_id();
3403 copy_body(&body
->nested
.part
->next
->body
, a
->body
);
3405 if(fetch_contents(stream
, msgno
, a
->number
,
3406 &body
->nested
.part
->next
->body
)){
3407 pine_send(outgoing
, &body
, "FORWARD MESSAGE",
3408 role
, NULL
, NULL
, redraft_pos
, NULL
, NULL
, 0);
3410 ps_global
->mangled_screen
= 1;
3411 pine_free_body(&body
);
3412 free_redraft_pos(&redraft_pos
);
3415 mail_free_body(&body
);
3416 so_give((STORE_S
**) &msgtext
);
3417 free_redraft_pos(&redraft_pos
);
3418 q_status_message(SM_ORDER
| SM_DING
, 4, 5,
3419 _("Error fetching message contents. Can't forward message."));
3423 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3424 _("Error allocating message text"));
3426 mail_free_envelope(&outgoing
);
3433 forward_msg_att(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
)
3435 char *p
, *sig
= NULL
;
3440 ACTION_S
*role
= NULL
;
3442 REDRAFT_POS_S
*redraft_pos
= NULL
;
3444 outgoing
= mail_newenvelope();
3445 outgoing
->message_id
= generate_message_id();
3447 memset((void *)&reply
, 0, sizeof(reply
));
3449 if((outgoing
->subject
= forward_subject(a
->body
->nested
.msg
->env
, 0)) != NULL
){
3451 * as with all text bound for the composer, build it in
3452 * a storage object of the type it understands...
3454 if((msgtext
= (void *) so_get(PicoText
, NULL
, EDIT_ACCESS
)) != NULL
){
3455 int impl
, template_len
= 0;
3456 long rflags
= ROLE_FORWARD
;
3460 if(ps_global
->full_header
== 2)
3461 ret
= want_to(_("Forward message as an attachment"), 'n', 0,
3462 NO_HELP
, WT_SEQ_SENSITIVE
);
3463 /* Setup possible role */
3464 if(nonempty_patterns(rflags
, &dummy
)){
3465 role
= set_role_from_msg(ps_global
, rflags
, msgno
, a
->number
);
3466 if(confirm_role(rflags
, &role
))
3467 role
= combine_inherited_role(role
);
3468 else{ /* cancel reply */
3470 cmd_cancelled("Forward");
3471 mail_free_envelope(&outgoing
);
3472 so_give((STORE_S
**) &msgtext
);
3478 q_status_message1(SM_ORDER
, 3, 4,
3479 _("Forwarding using role \"%s\""), role
->nick
);
3481 if(role
&& role
->template){
3485 filtered
= detoken(role
, a
->body
->nested
.msg
->env
,
3486 0, 0, 0, &redraft_pos
, &impl
);
3489 so_puts((STORE_S
*)msgtext
, filtered
);
3491 template_len
= strlen(filtered
);
3494 fs_give((void **)&filtered
);
3500 if((sig
= detoken(role
, a
->body
->nested
.msg
->env
,
3501 2, 0, 1, &redraft_pos
, &impl
)) != NULL
){
3503 redraft_pos
->offset
+= template_len
;
3505 so_puts((STORE_S
*)msgtext
, *sig
? sig
: NEWLINE
);
3507 fs_give((void **)&sig
);
3510 so_puts((STORE_S
*)msgtext
, NEWLINE
);
3513 /*---- New Body to start with ----*/
3514 body
= mail_newbody();
3515 body
->type
= TYPEMULTIPART
;
3517 /*---- The TEXT part/body ----*/
3518 body
->nested
.part
= mail_newbody_part();
3519 body
->nested
.part
->body
.type
= TYPETEXT
;
3520 body
->nested
.part
->body
.contents
.text
.data
= msgtext
;
3522 if(!forward_mime_msg(stream
, msgno
,
3523 p
= body_partno(stream
, msgno
, a
->body
),
3524 a
->body
->nested
.msg
->env
,
3525 &body
->nested
.part
->next
, msgtext
))
3526 mail_free_body(&body
);
3530 if(a
->body
->nested
.msg
->body
){
3534 = parameter_val(a
->body
->nested
.msg
->body
->parameter
,
3537 if(charset
&& strucmp(charset
, "us-ascii") != 0){
3541 * There is a non-ascii charset,
3542 * is there conversion happening?
3544 if(!(ct
=conversion_table(charset
, ps_global
->posting_charmap
))
3546 reply
.orig_charset
= charset
;
3552 fs_give((void **) &charset
);
3555 body
= forward_body(stream
, a
->body
->nested
.msg
->env
,
3556 a
->body
->nested
.msg
->body
, msgno
,
3557 p
= body_partno(stream
, msgno
, a
->body
),
3561 fs_give((void **) &p
);
3564 pine_send(outgoing
, &body
,
3567 reply
.forw
? &reply
: NULL
,
3568 redraft_pos
, NULL
, NULL
, 0);
3570 ps_global
->mangled_screen
= 1;
3571 pine_free_body(&body
);
3572 free_redraft_pos(&redraft_pos
);
3576 so_give((STORE_S
**) &msgtext
);
3577 q_status_message(SM_ORDER
| SM_DING
, 4, 5,
3578 _("Error fetching message contents. Can't forward message."));
3582 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3583 _("Error allocating message text"));
3586 q_status_message1(SM_ORDER
,3,4,
3587 _("Error fetching message %s. Can't forward it."),
3588 long2string(msgno
));
3590 if(reply
.orig_charset
)
3591 fs_give((void **)&reply
.orig_charset
);
3593 mail_free_envelope(&outgoing
);
3598 reply_msg_att(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
)
3600 ADDRESS
*saved_from
, *saved_to
, *saved_cc
, *saved_resent
;
3604 char *tp
, *prefix
= NULL
, *fcc
= NULL
, *errmsg
= NULL
;
3605 int include_text
= 0, flags
= RSF_QUERY_REPLY_ALL
;
3606 int rolemsg
= 0, copytomsg
= 0;
3609 REDRAFT_POS_S
*redraft_pos
= NULL
;
3610 ACTION_S
*role
= NULL
;
3612 outgoing
= mail_newenvelope();
3614 dprint((4,"\n - attachment reply \n"));
3616 saved_from
= (ADDRESS
*) NULL
;
3617 saved_to
= (ADDRESS
*) NULL
;
3618 saved_cc
= (ADDRESS
*) NULL
;
3619 saved_resent
= (ADDRESS
*) NULL
;
3620 outgoing
->subject
= NULL
;
3622 prefix
= reply_quote_str(a
->body
->nested
.msg
->env
);
3624 * For consistency, the first question is always "include text?"
3626 if((include_text
= reply_text_query(ps_global
, 1, NULL
, &prefix
)) >= 0
3627 && reply_news_test(a
->body
->nested
.msg
->env
, outgoing
) > 0
3628 && reply_harvest(ps_global
, msgno
, a
->number
,
3629 a
->body
->nested
.msg
->env
, &saved_from
,
3630 &saved_to
, &saved_cc
, &saved_resent
, &flags
)){
3631 outgoing
->subject
= reply_subject(a
->body
->nested
.msg
->env
->subject
,
3634 reply_seed(ps_global
, outgoing
, a
->body
->nested
.msg
->env
,
3635 saved_from
, saved_to
, saved_cc
, saved_resent
,
3636 &fcc
, flags
& RSF_FORCE_REPLY_ALL
, &errmsg
);
3639 q_status_message1(SM_ORDER
, 3, 3, "%.200s", errmsg
);
3640 display_message(NO_OP_COMMAND
);
3643 fs_give((void **)&errmsg
);
3646 if(sp_expunge_count(stream
)) /* current msg was expunged */
3649 /* Setup possible role */
3650 rflags
= ROLE_REPLY
;
3651 if(nonempty_patterns(rflags
, &dummy
)){
3652 role
= set_role_from_msg(ps_global
, rflags
, msgno
, a
->number
);
3653 if(confirm_role(rflags
, &role
))
3654 role
= combine_inherited_role(role
);
3655 else{ /* cancel reply */
3657 cmd_cancelled("Reply");
3665 /* override fcc gotten in reply_seed */
3666 if(role
->fcc
&& fcc
)
3667 fs_give((void **) &fcc
);
3670 if(F_ON(F_COPY_TO_TO_FROM
, ps_global
) && !(role
&& role
->from
)){
3671 ADDRESS
*us_in_to_and_cc
, *ap
;
3673 us_in_to_and_cc
= (ADDRESS
*) NULL
;
3674 if(a
->body
->nested
.msg
->env
&& a
->body
->nested
.msg
->env
->to
)
3675 if((ap
=reply_cp_addr(ps_global
, 0L, NULL
,
3676 NULL
, us_in_to_and_cc
, NULL
,
3677 a
->body
->nested
.msg
->env
->to
, RCA_ONLY_US
)) != NULL
)
3678 reply_append_addr(&us_in_to_and_cc
, ap
);
3680 if(a
->body
->nested
.msg
->env
&& a
->body
->nested
.msg
->env
->cc
)
3681 if((ap
=reply_cp_addr(ps_global
, 0L, NULL
,
3682 NULL
, us_in_to_and_cc
, NULL
,
3683 a
->body
->nested
.msg
->env
->cc
, RCA_ONLY_US
)) != NULL
)
3684 reply_append_addr(&us_in_to_and_cc
, ap
);
3687 * A list of all of our addresses that appear in the To
3688 * and cc fields is in us_in_to_and_cc.
3689 * If there is exactly one address in that list then
3690 * use it for the outgoing From.
3692 if(us_in_to_and_cc
&& !us_in_to_and_cc
->next
){
3693 PINEFIELD
*custom
, *pf
;
3698 * Check to see if this address is different from what
3699 * we would have used anyway. If it is, notify the user
3700 * with a status message. This is pretty hokey because we're
3701 * mimicking how pine_send would set the From address and
3702 * there is no coordination between the two.
3705 /* in case user has a custom From value */
3706 custom
= parse_custom_hdrs(ps_global
->VAR_CUSTOM_HDRS
, UseAsDef
);
3708 pf
= (PINEFIELD
*) fs_get(sizeof(*pf
));
3709 memset((void *) pf
, 0, sizeof(*pf
));
3710 pf
->name
= cpystr("From");
3712 if(set_default_hdrval(pf
, custom
) >= UseAsDef
3713 && pf
->textbuf
&& pf
->textbuf
[0]){
3714 removing_trailing_white_space(pf
->textbuf
);
3715 (void)removing_double_quotes(pf
->textbuf
);
3716 build_address(pf
->textbuf
, &addr
, NULL
, NULL
, NULL
);
3717 rfc822_parse_adrlist(pf
->addr
, addr
, ps_global
->maildomain
);
3719 fs_give((void **) &addr
);
3723 *pf
->addr
= generate_from();
3725 if(*pf
->addr
&& !address_is_same(*pf
->addr
, us_in_to_and_cc
)){
3728 role
= (ACTION_S
*) fs_get(sizeof(*role
));
3729 memset((void *) role
, 0, sizeof(*role
));
3730 role
->is_a_role
= 1;
3733 role
->from
= us_in_to_and_cc
;
3734 us_in_to_and_cc
= NULL
;
3737 free_customs(custom
);
3742 mail_free_address(&us_in_to_and_cc
);
3747 if(rolemsg
&& copytomsg
)
3748 q_status_message1(SM_ORDER
, 3, 4,
3749 _("Replying using role \"%s\" and To as From"), role
->nick
);
3751 q_status_message1(SM_ORDER
, 3, 4,
3752 _("Replying using role \"%s\""), role
->nick
);
3754 q_status_message(SM_ORDER
, 3, 4,
3755 _("Replying using incoming To as outgoing From"));
3758 outgoing
->in_reply_to
= reply_in_reply_to(a
->body
->nested
.msg
->env
);
3759 outgoing
->references
= reply_build_refs(a
->body
->nested
.msg
->env
);
3760 outgoing
->message_id
= generate_message_id();
3762 if(!outgoing
->to
&& !outgoing
->cc
3763 && !outgoing
->bcc
&& !outgoing
->newsgroups
)
3764 q_status_message(SM_ORDER
| SM_DING
, 3, 6,
3765 _("Warning: no valid addresses to reply to!"));
3768 * Now fix up the body...
3770 if((msgtext
= (void *) so_get(PicoText
, NULL
, EDIT_ACCESS
)) != NULL
){
3773 memset((void *)&reply
, 0, sizeof(reply
));
3775 if(a
->body
->nested
.msg
->body
){
3779 = parameter_val(a
->body
->nested
.msg
->body
->parameter
,
3782 if(charset
&& strucmp(charset
, "us-ascii") != 0){
3786 * There is a non-ascii charset,
3787 * is there conversion happening?
3789 if(!(ct
=conversion_table(charset
, ps_global
->posting_charmap
))
3791 reply
.orig_charset
= charset
;
3797 fs_give((void **) &charset
);
3800 if((body
= reply_body(stream
, a
->body
->nested
.msg
->env
,
3801 a
->body
->nested
.msg
->body
, msgno
,
3802 tp
= body_partno(stream
, msgno
, a
->body
),
3803 msgtext
, prefix
, include_text
, role
,
3804 1, &redraft_pos
)) != NULL
){
3805 /* partially formatted outgoing message */
3806 pine_send(outgoing
, &body
, "COMPOSE MESSAGE REPLY",
3807 role
, fcc
, &reply
, redraft_pos
, NULL
, NULL
, 0);
3809 pine_free_body(&body
);
3810 ps_global
->mangled_screen
= 1;
3813 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3814 _("Error building message body"));
3816 fs_give((void **) &tp
);
3817 if(reply
.orig_charset
)
3818 fs_give((void **)&reply
.orig_charset
);
3821 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3822 _("Error allocating message text"));
3826 mail_free_envelope(&outgoing
);
3827 mail_free_address(&saved_from
);
3828 mail_free_address(&saved_to
);
3829 mail_free_address(&saved_cc
);
3830 mail_free_address(&saved_resent
);
3833 fs_give((void **) &prefix
);
3836 fs_give((void **) &fcc
);
3838 free_redraft_pos(&redraft_pos
);
3844 bounce_msg_att(MAILSTREAM
*stream
, long int msgno
, char *part
, char *subject
)
3848 if((errstr
= bounce_msg(stream
, msgno
, part
, NULL
, NULL
, subject
, NULL
, NULL
)) != NULL
)
3849 q_status_message(SM_ORDER
| SM_DING
, 3, 3, errstr
);
3854 pipe_attachment(long int msgno
, ATTACH_S
*a
)
3856 char *err
, *resultfilename
= NULL
, prompt
[80], *p
;
3857 int rc
, capture
= 1, raw
= 0, we_cancel
= 0, j
= 0;
3861 char pipe_command
[MAXPATH
+1];
3862 unsigned flagsforhist
= 1; /* raw=2 /capture=1 */
3863 static HISTORY_S
*history
= NULL
;
3864 ESCKEY_S pipe_opt
[6];
3866 if(ps_global
->restricted
){
3867 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
3868 "Alpine demo can't pipe attachments");
3873 pipe_command
[0] = '\0';
3875 init_hist(&history
, HISTSIZE
);
3876 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
3877 if((p
= get_prev_hist(history
, "", flagsforhist
, NULL
)) != NULL
){
3878 strncpy(pipe_command
, p
, sizeof(pipe_command
));
3879 pipe_command
[sizeof(pipe_command
)-1] = '\0';
3880 if(history
->hist
[history
->curindex
]){
3881 flagsforhist
= history
->hist
[history
->curindex
]->flags
;
3882 raw
= (flagsforhist
& 0x2) ? 1 : 0;
3883 capture
= (flagsforhist
& 0x1) ? 1 : 0;
3888 pipe_opt
[j
].rval
= 0;
3889 pipe_opt
[j
].name
= "";
3890 pipe_opt
[j
++].label
= "";
3892 pipe_opt
[j
].ch
= ctrl('W');
3893 pipe_opt
[j
].rval
= 10;
3894 pipe_opt
[j
].name
= "^W";
3895 pipe_opt
[j
++].label
= NULL
;
3897 pipe_opt
[j
].ch
= ctrl('Y');
3898 pipe_opt
[j
].rval
= 11;
3899 pipe_opt
[j
].name
= "^Y";
3900 pipe_opt
[j
++].label
= NULL
;
3902 pipe_opt
[j
].ch
= KEY_UP
;
3903 pipe_opt
[j
].rval
= 30;
3904 pipe_opt
[j
].name
= "";
3906 pipe_opt
[j
++].label
= "";
3908 pipe_opt
[j
].ch
= KEY_DOWN
;
3909 pipe_opt
[j
].rval
= 31;
3910 pipe_opt
[j
].name
= "";
3911 pipe_opt
[j
++].label
= "";
3913 pipe_opt
[j
].ch
= -1;
3918 snprintf(prompt
, sizeof(prompt
), "Pipe %sattachment %s to %s: ", raw
? "RAW " : "",
3919 a
->number
, capture
? "" : "(Free Output) ");
3920 prompt
[sizeof(prompt
)-1] = '\0';
3921 pipe_opt
[1].label
= raw
? "DecodedData" : "Raw Data";
3922 pipe_opt
[2].label
= capture
? "Free Output" : "Capture Output";
3925 * 2 is really 1 because there will be one real entry and
3926 * one entry of "" because of the get_prev_hist above.
3928 if(items_in_hist(history
) > 2){
3929 pipe_opt
[ku
].name
= HISTORY_UP_KEYNAME
;
3930 pipe_opt
[ku
].label
= HISTORY_KEYLABEL
;
3931 pipe_opt
[ku
+1].name
= HISTORY_DOWN_KEYNAME
;
3932 pipe_opt
[ku
+1].label
= HISTORY_KEYLABEL
;
3935 pipe_opt
[ku
].name
= "";
3936 pipe_opt
[ku
].label
= "";
3937 pipe_opt
[ku
+1].name
= "";
3938 pipe_opt
[ku
+1].label
= "";
3941 flags
= OE_APPEND_CURRENT
| OE_SEQ_SENSITIVE
;
3942 rc
= optionally_enter(pipe_command
, -FOOTER_ROWS(ps_global
), 0,
3943 sizeof(pipe_command
), prompt
,
3944 pipe_opt
, help
, &flags
);
3946 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3947 "Internal problem encountered");
3951 raw
= !raw
; /* flip raw text */
3954 capture
= !capture
; /* flip capture output */
3957 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
3958 if((p
= get_prev_hist(history
, pipe_command
, flagsforhist
, NULL
)) != NULL
){
3959 strncpy(pipe_command
, p
, sizeof(pipe_command
));
3960 pipe_command
[sizeof(pipe_command
)-1] = '\0';
3961 if(history
->hist
[history
->curindex
]){
3962 flagsforhist
= history
->hist
[history
->curindex
]->flags
;
3963 raw
= (flagsforhist
& 0x2) ? 1 : 0;
3964 capture
= (flagsforhist
& 0x1) ? 1 : 0;
3971 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
3972 if((p
= get_next_hist(history
, pipe_command
, flagsforhist
, NULL
)) != NULL
){
3973 strncpy(pipe_command
, p
, sizeof(pipe_command
));
3974 pipe_command
[sizeof(pipe_command
)-1] = '\0';
3975 if(history
->hist
[history
->curindex
]){
3976 flagsforhist
= history
->hist
[history
->curindex
]->flags
;
3977 raw
= (flagsforhist
& 0x2) ? 1 : 0;
3978 capture
= (flagsforhist
& 0x1) ? 1 : 0;
3985 if(pipe_command
[0] == '\0'){
3986 cmd_cancelled("Pipe command");
3990 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
3991 save_hist(history
, pipe_command
, flagsforhist
, NULL
);
3993 flags
= PIPE_USER
| PIPE_WRITE
| PIPE_STDERR
;
3994 flags
|= (raw
? PIPE_RAW
: 0);
4000 ps_global
->mangled_screen
= 1;
4002 flags
|= PIPE_RESET
;
4005 if((syspipe
= open_system_pipe(pipe_command
,
4006 (flags
&PIPE_RESET
) ? NULL
: &resultfilename
,
4007 NULL
, flags
, 0, pipe_callback
, pipe_report_error
)) != NULL
){
4009 gf_io_t pc
; /* wire up a generic putchar */
4011 is_text
= (a
&& a
->body
&& a
->body
->type
== TYPETEXT
);
4013 gf_set_writec(&pc
, syspipe
, 0L, PipeStar
,
4014 (is_text
&& !raw
) ? WRITE_TO_LOCALE
: 0);
4016 /*------ Write the image to a temporary file ------*/
4017 if(raw
){ /* pipe raw text */
4018 FETCH_READC_S fetch_part
;
4023 we_cancel
= busy_cue(NULL
, NULL
, 1);
4028 fetch_readc_init(&fetch_part
, ps_global
->mail_stream
,
4029 msgno
, a
->number
, a
->body
->size
.bytes
, 0, 0);
4030 gf_link_filter(gf_nvtnl_local
, NULL
);
4031 err
= gf_pipe(FETCH_READC
, pc
);
4041 /* BUG: there's got to be a better way */
4043 ps_global
->print
= (PRINT_S
*) 1;
4046 err
= detach(ps_global
->mail_stream
, msgno
,
4047 a
->number
, 0L, (long *)NULL
, pc
, NULL
, 0);
4048 ps_global
->print
= (PRINT_S
*) NULL
;
4052 (void) close_system_pipe(&syspipe
, NULL
, pipe_callback
);
4055 q_status_message1(SM_ORDER
| SM_DING
, 3, 4,
4056 _("Error detaching for pipe: %s"), err
);
4058 display_output_file(resultfilename
,
4060 ? _("PIPE ATTACHMENT (ERROR)")
4061 : _("PIPE ATTACHMENT"),
4064 fs_give((void **) &resultfilename
);
4067 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
4068 _("Error opening pipe"));
4073 cmd_cancelled("Pipe");
4077 help
= (help
== NO_HELP
) ? h_pipe_attach
: NO_HELP
;
4083 delete_attachment(long int msgno
, ATTACH_S
*a
)
4085 int expbits
, rv
= 0;
4087 if(!msgno_exceptions(ps_global
->mail_stream
, msgno
,
4088 a
->number
, &expbits
, FALSE
)
4089 || !(expbits
& MSG_EX_DELETE
)){
4090 expbits
|= MSG_EX_DELETE
;
4091 msgno_exceptions(ps_global
->mail_stream
, msgno
,
4092 a
->number
, &expbits
, TRUE
);
4094 q_status_message1(SM_ORDER
, 0, 3,
4095 _("Part %s will be omitted only if message is Saved"),
4100 q_status_message1(SM_ORDER
, 0, 3, _("Part %s already deleted"),
4108 undelete_attachment(long int msgno
, ATTACH_S
*a
, int *expbitsp
)
4112 if(msgno_exceptions(ps_global
->mail_stream
, msgno
,
4113 a
->number
, expbitsp
, FALSE
)
4114 && ((*expbitsp
) & MSG_EX_DELETE
)){
4115 (*expbitsp
) ^= MSG_EX_DELETE
;
4116 msgno_exceptions(ps_global
->mail_stream
, msgno
,
4117 a
->number
, expbitsp
, TRUE
);
4121 q_status_message1(SM_ORDER
, 0, 3, _("Part %s already UNdeleted"),
4128 /*----------------------------------------------------------------------
4129 Resolve any deferred tests for attachment displayability
4131 Args: attachment structure
4133 Returns: undefer's attachment's displayability test
4136 dispatch_attachment(ATTACH_S
*a
)
4138 if(a
->test_deferred
){
4139 a
->test_deferred
= 0;
4140 a
->can_display
= mime_can_display(a
->body
->type
, a
->body
->subtype
, a
->body
);
4143 return(a
->can_display
);
4149 scroll_att_popup(sparms
, in_handle
)
4153 MPopup scrat_popup
[20];
4157 scrat_popup
[++i
].type
= tIndex
;
4158 scrat_popup
[i
].label
.style
= lNormal
;
4159 scrat_popup
[i
].label
.string
= "View Selectable Item";
4160 scrat_popup
[i
].data
.val
= ctrl('L');
4163 scrat_popup
[++i
].type
= tQueue
;
4164 scrat_popup
[i
].label
.style
= lNormal
;
4165 scrat_popup
[i
].label
.string
= "&Save";
4166 scrat_popup
[i
].data
.val
= 'S';
4168 scrat_popup
[++i
].type
= tQueue
;
4169 scrat_popup
[i
].label
.style
= lNormal
;
4170 if(msgno_exceptions(ps_global
->mail_stream
,
4171 mn_m2raw(ps_global
->msgmap
,
4172 mn_get_cur(ps_global
->msgmap
)),
4173 scrat_attachp
->number
, &n
, FALSE
)
4174 && (n
& MSG_EX_DELETE
)){
4175 scrat_popup
[i
].label
.string
= "&Undelete";
4176 scrat_popup
[i
].data
.val
= 'U';
4179 scrat_popup
[i
].label
.string
= "&Delete";
4180 scrat_popup
[i
].data
.val
= 'D';
4183 if(MIME_MSG_A(scrat_attachp
) || MIME_DGST_A(scrat_attachp
)){
4184 scrat_popup
[++i
].type
= tQueue
;
4185 scrat_popup
[i
].label
.style
= lNormal
;
4186 scrat_popup
[i
].label
.string
= "&Reply";
4187 scrat_popup
[i
].data
.val
= 'R';
4189 scrat_popup
[++i
].type
= tQueue
;
4190 scrat_popup
[i
].label
.style
= lNormal
;
4191 scrat_popup
[i
].label
.string
= "&Forward";
4192 scrat_popup
[i
].data
.val
= 'f';
4195 scrat_popup
[++i
].type
= tSeparator
;
4197 scrat_popup
[++i
].type
= tQueue
;
4198 scrat_popup
[i
].label
.style
= lNormal
;
4199 scrat_popup
[i
].label
.string
= "Attachment Index";
4200 scrat_popup
[i
].data
.val
= '<';
4202 scrat_popup
[++i
].type
= tTail
;
4204 return(mswin_popup(scrat_popup
) == 0 && in_handle
);
4209 display_att_window(a
)
4212 #if !defined(DOS) && !defined(OS2)
4216 if(a
->body
->type
== TYPEMULTIPART
){
4217 if(a
->body
->subtype
){
4218 /* if(!strucmp(a->body->subtype, "digest"))
4219 display_digest_att(msgno, a, flags);
4221 q_status_message1(SM_ORDER
, 3, 5,
4222 "Can't display Multipart/%s",
4226 q_status_message(SM_ORDER
, 3, 5,
4227 "Can't display unknown Multipart Subtype");
4229 /* else if(MIME_VCARD_A(a))
4230 display_vcard_att_window(msgno, a, flags);*/
4231 else if(a
->body
->type
== TYPETEXT
)
4232 display_text_att_window(a
);
4233 else if(a
->body
->type
== TYPEMESSAGE
)
4234 display_msg_att_window(a
);
4239 display_text_att_window(a
)
4245 msgno
= mn_m2raw(ps_global
->msgmap
, mn_get_cur(ps_global
->msgmap
));
4247 if(store
= format_text_att(msgno
, a
, NULL
)){
4248 if (mswin_displaytext("ATTACHED TEXT",
4250 strlen((char *) so_text(store
)),
4251 NULL
, NULL
, 0) >= 0)
4252 store
->txt
= (void *) NULL
; /* free'd in mswin_displaytext */
4254 so_give(&store
); /* free resources associated with store */
4257 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
4258 "Error allocating space for attachment.");
4263 display_msg_att_window(a
)
4271 msgno
= mn_m2raw(ps_global
->msgmap
, mn_get_cur(ps_global
->msgmap
));
4273 /* BUG, should check this return code */
4274 (void) pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
);
4276 /* initialize a storage object */
4277 if(store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)){
4279 gf_set_so_writec(&pc
, store
);
4281 if(format_msg_att(msgno
, &ap
, NULL
, pc
, FM_DISPLAY
)
4282 && mswin_displaytext("ATTACHED MESSAGE", so_text(store
),
4283 strlen((char *) so_text(store
)),
4284 NULL
, NULL
, 0) >= 0)
4285 /* free'd in mswin_displaytext */
4286 store
->txt
= (void *) NULL
;
4288 gf_clear_so_writec(store
);
4293 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
4294 "Error allocating space for message.");