2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2008 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 /*======================================================================
17 The meat and pototoes of attachment processing here.
39 #include "../pith/state.h"
40 #include "../pith/conf.h"
41 #include "../pith/store.h"
42 #include "../pith/msgno.h"
43 #include "../pith/detach.h"
44 #include "../pith/handle.h"
45 #include "../pith/filter.h"
46 #include "../pith/bitmap.h"
47 #include "../pith/charset.h"
48 #include "../pith/mimedesc.h"
49 #include "../pith/mailcap.h"
50 #include "../pith/newmail.h"
51 #include "../pith/rfc2231.h"
52 #include "../pith/flag.h"
53 #include "../pith/text.h"
54 #include "../pith/editorial.h"
55 #include "../pith/save.h"
56 #include "../pith/pipe.h"
57 #include "../pith/util.h"
58 #include "../pith/detoken.h"
59 #include "../pith/busy.h"
60 #include "../pith/mimetype.h"
61 #include "../pith/icache.h"
62 #include "../pith/list.h"
63 #include "../pith/ablookup.h"
64 #include "../pith/options.h"
65 #include "../pith/smime.h"
66 #include "../pith/ical.h"
67 #include "../pith/body.h"
68 #include "../pith/init.h"
71 * Information used to paint and maintain a line on the attachment
74 typedef struct atdisp_line
{
75 char *dstring
; /* alloc'd var value string */
76 ATTACH_S
*attp
; /* actual attachment pointer */
77 struct atdisp_line
*next
, *prev
;
82 * struct defining attachment screen's current state
84 typedef struct att_screen
{
87 COLOR_PAIR
*titlecolor
;
90 static ATT_SCREEN_S
*att_screen
;
93 #define next_attline(p) ((p) ? (p)->next : NULL)
94 #define prev_attline(p) ((p) ? (p)->prev : NULL)
99 * local global pointer to scroll attachment popup menu
101 static ATTACH_S
*scrat_attachp
;
105 #define FETCH_READC g_fr_desc->readc
108 /* used to keep track of detached MIME segments total length */
109 static long save_att_length
;
112 * Internal Prototypes
114 ATDISP_S
*new_attline(ATDISP_S
**);
115 void free_attline(ATDISP_S
**);
116 int attachment_screen_updater(struct pine
*, ATDISP_S
*, ATT_SCREEN_S
*);
117 void attachment_screen_redrawer(void);
118 void update_att_screen_titlebar(void);
119 ATDISP_S
*first_attline(ATDISP_S
*);
120 int init_att_progress(char *, MAILSTREAM
*, BODY
*);
121 long save_att_piped(int);
122 int save_att_percent(void);
123 void save_attachment(int, long, ATTACH_S
*);
124 void export_attachment(int, long, ATTACH_S
*);
125 char *write_attached_msg(long, ATTACH_S
**, STORE_S
*, int);
126 void save_msg_att(long, ATTACH_S
*);
127 void save_digest_att(long, ATTACH_S
*);
128 int save_msg_att_work(long int, ATTACH_S
*, MAILSTREAM
*, char *,
129 CONTEXT_S
*, char *);
130 void export_msg_att(long, ATTACH_S
*);
131 void export_digest_att(long, ATTACH_S
*);
132 void print_attachment(int, long, ATTACH_S
*);
133 int print_msg_att(long, ATTACH_S
*, int);
134 void print_digest_att(long, ATTACH_S
*);
135 void run_viewer(char *, BODY
*, int);
136 STORE_S
*format_text_att(long, ATTACH_S
*, HANDLE_S
**);
137 int display_text_att(long, ATTACH_S
*, int);
138 int display_msg_att(long, ATTACH_S
*, int);
139 void display_digest_att(long, ATTACH_S
*, int);
140 int scroll_attachment(char *, STORE_S
*, SourceType
, HANDLE_S
*, ATTACH_S
*, int);
141 int process_attachment_cmd(int, MSGNO_S
*, SCROLL_S
*);
142 int format_msg_att(long, ATTACH_S
**, HANDLE_S
**, gf_io_t
, int);
143 void display_vcard_att(long, ATTACH_S
*, int);
144 void display_vcalendar_att(long, ATTACH_S
*, int);
145 void display_attach_info(long, ATTACH_S
*);
146 int display_html_external_attachment(long int, ATTACH_S
*, int);
147 void forward_attachment(MAILSTREAM
*, long, ATTACH_S
*);
148 void forward_msg_att(MAILSTREAM
*, long, ATTACH_S
*);
149 void reply_msg_att(MAILSTREAM
*, long, ATTACH_S
*);
150 void bounce_msg_att(MAILSTREAM
*, long, char *, char *);
151 void pipe_attachment(long, ATTACH_S
*);
152 int delete_attachment(long, ATTACH_S
*);
153 int undelete_attachment(long, ATTACH_S
*, int *);
155 int scroll_att_popup(SCROLL_S
*, int);
156 void display_text_att_window(ATTACH_S
*);
157 void display_msg_att_window(ATTACH_S
*);
161 /*----------------------------------------------------------------------
162 Provide attachments in browser for selected action
164 Args: ps -- pointer to pine structure
165 msgmap -- struct containing current message to display
169 Handle painting and navigation of attachment index. It would be nice
170 to someday handle message/rfc822 segments in a neat way (i.e., enable
171 forwarding, take address, etc.).
174 attachment_screen(struct pine
*ps
)
178 maxnumwid
= 0, maxsizewid
= 0, old_cols
= -1, km_popped
= 0, expbits
,
179 last_type
= TYPEOTHER
;
181 char *q
, *last_subtype
= NULL
, backtag
[64], *utf8str
;
184 ATDISP_S
*current
= NULL
, *ctmp
= NULL
;
187 ps
->prev_screen
= attachment_screen
;
188 ps
->next_screen
= SCREEN_FUN_NULL
;
190 ps
->some_quoting_was_suppressed
= 0;
192 if(ps
->ttyo
->screen_rows
- HEADER_ROWS(ps
) - FOOTER_ROWS(ps
) < 1){
193 q_status_message(SM_ORDER
| SM_DING
, 0, 3,
194 _("Screen too small to view attachment"));
195 ps
->next_screen
= mail_view_screen
;
199 if(mn_total_cur(ps
->msgmap
) > 1L){
200 q_status_message(SM_ORDER
| SM_DING
, 0, 3,
201 _("Can only view one message's attachments at a time."));
204 else if(ps
->atmts
&& ps
->atmts
->description
&& !(ps
->atmts
+ 1)->description
)
205 q_status_message1(SM_ASYNC
, 0, 3,
206 _("Message %s has only one part (the message body), and no attachments."),
207 long2string(mn_get_cur(ps
->msgmap
)));
209 /*----- Figure max display widths -----*/
210 for(a
= ps
->atmts
; a
&& a
->description
!= NULL
; a
++){
211 if((n
= utf8_width(a
->number
)) > maxnumwid
)
214 if((n
= utf8_width(a
->size
)) > maxsizewid
)
219 * Then, allocate and initialize attachment line list...
221 for(a
= ps
->atmts
; a
&& a
->description
; a
++)
222 new_attline(¤t
)->attp
= a
;
224 memset(&screen
, 0, sizeof(screen
));
225 msgno
= mn_m2raw(ps
->msgmap
, mn_get_cur(ps
->msgmap
));
226 ps
->mangled_screen
= 1; /* build display */
227 ps
->redrawer
= attachment_screen_redrawer
;
228 att_screen
= &screen
;
229 current
= first_attline(current
);
233 * Advance to next attachment if it's likely that we've already
234 * shown it to the user...
237 if (current
== NULL
){
238 q_status_message1(SM_ORDER
| SM_DING
, 0, 3,
239 _("Malformed message: %s"),
240 ps
->c_client_error
? ps
->c_client_error
: "?");
241 ps
->next_screen
= mail_view_screen
;
243 else if(current
->attp
->shown
&& (ctmp
= next_attline(current
)))
246 while(ps
->next_screen
== SCREEN_FUN_NULL
){
247 ps
->user_says_cancel
= 0;
252 ps
->mangled_body
= 1;
256 if(ps
->mangled_screen
){
258 * build/rebuild display lines
260 if(old_cols
!= ps
->ttyo
->screen_cols
){
261 int avail
, s1
, s2
, s4
, s5
, dwid
, sizewid
, descwid
;
263 avail
= ps_global
->ttyo
->screen_cols
;
265 s1
= MAX(MIN(1, avail
), 0);
268 dwid
= MAX(MIN(1, avail
), 0);
271 s2
= MAX(MIN(1, avail
), 0);
274 /* Only give up a third of the display to part numbers */
275 maxnumwid
= MIN(maxnumwid
, (ps_global
->ttyo
->screen_cols
/3));
276 maxnumwid
= MAX(MIN(maxnumwid
, avail
), 0);
279 s4
= MAX(MIN(3, avail
), 0);
282 sizewid
= MAX(MIN(maxsizewid
, avail
), 0);
285 s5
= MAX(MIN(3, avail
), 0);
288 descwid
= MAX(0, avail
);
290 old_cols
= ps
->ttyo
->screen_cols
;
292 for(ctmp
= first_attline(current
);
293 ctmp
&& (a
= ctmp
->attp
) && a
->description
;
294 ctmp
= next_attline(ctmp
)){
297 char description
[1000];
300 fs_give((void **)&ctmp
->dstring
);
302 len
= 6 * MAX(80, ps
->ttyo
->screen_cols
) * sizeof(char);
303 ctmp
->dstring
= (char *)fs_get(len
+ 1);
308 q
= a
->body
->description
;
309 if(!(q
&& q
[0]) && (MIME_MSG_A(a
) && a
->body
->nested
.msg
->env
))
310 q
= a
->body
->nested
.msg
->env
->subject
;
315 strncpy(buftmp
, q
, sizeof(buftmp
));
316 buftmp
[sizeof(buftmp
)-1] = '\0';
318 q
= (char *) rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf
,
319 SIZEOF_20KBUF
, buftmp
);
325 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
? "\"" : "");
326 description
[sizeof(description
)-1] = '\0';
328 utf8_snprintf(ctmp
->dstring
, len
+1,
329 "%*.*s%*.*w%*.*s%-*.*w%*.*s%*.*w%*.*s%-*.*w",
332 msgno_part_deleted(ps
->mail_stream
, msgno
, a
->number
) ? "D" : "",
334 maxnumwid
, maxnumwid
,
336 ? short_str(a
->number
, numbuf
, sizeof(numbuf
), maxnumwid
, FrontDots
)
340 a
->size
? a
->size
: "",
342 descwid
, descwid
, description
);
344 ctmp
->dstring
[len
] = '\0';
348 ps
->mangled_header
= 1;
349 ps
->mangled_footer
= 1;
350 ps
->mangled_body
= 1;
353 /*----------- Check for new mail -----------*/
354 if(new_mail(0, NM_TIMING(ch
), NM_STATUS_MSG
| NM_DEFER_SORT
) >= 0)
355 ps
->mangled_header
= 1;
358 * If an expunge of the current message happened during the
359 * new mail check we want to bail out of here. See mm_expunged.
361 if(ps
->next_screen
!= SCREEN_FUN_NULL
)
364 if(ps
->mangled_header
){
365 update_att_screen_titlebar();
366 ps
->mangled_header
= 0;
369 if(ps
->mangled_screen
){
371 ps
->mangled_screen
= 0;
374 dline
= attachment_screen_updater(ps
, current
, &screen
);
376 /*---- This displays new mail notification, or errors ---*/
379 mark_status_unknown();
385 mark_status_unknown();
388 if(ps
->mangled_footer
389 || current
->attp
->body
->type
!= last_type
390 || !(last_subtype
&& current
->attp
->body
->subtype
)
391 || strucmp(last_subtype
, current
->attp
->body
->subtype
)){
393 struct key_menu
*km
= &att_index_keymenu
;
397 ps
->mangled_footer
= 0;
398 last_type
= current
->attp
->body
->type
;
399 last_subtype
= current
->attp
->body
->subtype
;
401 snprintf(backtag
, sizeof(backtag
), "Msg #%ld", mn_get_cur(ps
->msgmap
));
402 backtag
[sizeof(backtag
)-1] = '\0';
403 km
->keys
[ATT_PARENT_KEY
].label
= backtag
;
405 if(F_OFF(F_ENABLE_PIPE
, ps
))
406 clrbitn(ATT_PIPE_KEY
, bitmap
);
409 * If message or digest, leave Reply and Save and,
410 * conditionally, Bounce on...
412 if(MIME_MSG(last_type
, last_subtype
)){
413 if(F_OFF(F_ENABLE_BOUNCE
, ps
))
414 clrbitn(ATT_BOUNCE_KEY
, bitmap
);
416 km
->keys
[ATT_EXPORT_KEY
].name
= "";
417 km
->keys
[ATT_EXPORT_KEY
].label
= "";
419 else if(MIME_DGST(last_type
, last_subtype
)){
420 clrbitn(ATT_BOUNCE_KEY
, bitmap
);
421 clrbitn(ATT_REPLY_KEY
, bitmap
);
423 km
->keys
[ATT_EXPORT_KEY
].name
= "";
424 km
->keys
[ATT_EXPORT_KEY
].label
= "";
427 clrbitn(ATT_BOUNCE_KEY
, bitmap
);
428 clrbitn(ATT_REPLY_KEY
, bitmap
);
430 if(last_type
!= TYPETEXT
)
431 clrbitn(ATT_PRINT_KEY
, bitmap
);
433 km
->keys
[ATT_EXPORT_KEY
].name
= "E";
434 km
->keys
[ATT_EXPORT_KEY
].label
= N_("Export");
442 if(F_ON(F_ARROW_NAV
, ps
)){
443 menu_add_binding(km
, KEY_LEFT
, MC_EXIT
);
444 menu_add_binding(km
, KEY_RIGHT
, MC_VIEW_ATCH
);
447 menu_clear_binding(km
, KEY_LEFT
);
448 menu_clear_binding(km
, KEY_RIGHT
);
451 draw_keymenu(km
, bitmap
, ps
->ttyo
->screen_cols
, 1-FOOTER_ROWS(ps
),
456 mark_keymenu_dirty();
460 if(F_ON(F_SHOW_CURSOR
, ps
))
461 MoveCursor(dline
, 0);
463 MoveCursor(MAX(0, ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
)), 0);
465 /*------ Prepare to read the command from the keyboard ----*/
467 mouse_in_content(KEY_MOUSE
, -1, -1, 0, 0); /* prime the handler */
468 register_mfunc(mouse_in_content
, HEADER_ROWS(ps_global
), 0,
469 ps_global
->ttyo
->screen_rows
-(FOOTER_ROWS(ps_global
)+1),
470 ps_global
->ttyo
->screen_cols
);
472 ch
= READ_COMMAND(&utf8str
);
474 clear_mfunc(mouse_in_content
);
477 cmd
= menu_command(ch
, &att_index_keymenu
);
495 if(FOOTER_ROWS(ps
) == 1 && km_popped
== 0){
497 ps
->mangled_footer
= 1;
501 helper(h_attachment_screen
, _("HELP FOR ATTACHMENT INDEX"), 0);
502 ps
->mangled_screen
= 1;
507 ps
->mangled_footer
= 1;
512 if(ps
->full_header
== 1){
513 if(!(ps
->quote_suppression_threshold
514 && (ps
->some_quoting_was_suppressed
/* || in_index != View */)))
517 else if(ps
->full_header
> 2)
520 switch(ps
->full_header
){
522 q_status_message(SM_ORDER
, 0, 3,
523 _("Display of full headers is now off."));
527 q_status_message1(SM_ORDER
, 0, 3,
528 _("Quotes displayed, use %s to see full headers"),
529 F_ON(F_USE_FK
, ps
) ? "F9" : "H");
533 q_status_message(SM_ORDER
, 0, 3,
534 _("Display of full headers is now on."));
542 display_html_external_attachment(msgno
, current
->attp
,
543 DA_EXTERNAL
| DA_SAVE
| (F_OFF(F_EXTERNAL_INLINE_IMAGES
, ps_global
) ? DA_ALLIMAGES
: 0));
546 case MC_EXIT
: /* exit attachment screen */
547 ps
->next_screen
= mail_view_screen
;
551 ps
->next_screen
= quit_screen
;
555 ps
->next_screen
= main_menu_screen
;
559 ps
->next_screen
= mail_index_screen
;
563 if((ctmp
= next_attline(current
)) != NULL
)
566 q_status_message(SM_ORDER
, 0, 1, _("Already on last attachment"));
571 if((ctmp
= prev_attline(current
)) != NULL
)
574 q_status_message(SM_ORDER
, 0, 1, _("Already on first attachment"));
578 case MC_PAGEDN
: /* page forward */
579 if(next_attline(current
)){
580 while(dline
++ < ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
))
581 if((ctmp
= next_attline(current
)) != NULL
)
587 q_status_message(SM_ORDER
, 0, 1,
588 _("Already on last page of attachments"));
592 case MC_PAGEUP
: /* page backward */
593 if(prev_attline(current
)){
594 while(dline
-- > HEADER_ROWS(ps
))
595 if((ctmp
= prev_attline(current
)) != NULL
)
600 while(++dline
< ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
))
601 if((ctmp
= prev_attline(current
)) != NULL
)
607 q_status_message(SM_ORDER
, 0, 1,
608 _("Already on first page of attachments"));
617 mouse_get_last (NULL
, &mp
);
618 mp
.row
-= HEADER_ROWS(ps
);
619 ctmp
= screen
.top_line
;
620 while (mp
.row
&& ctmp
!= NULL
) {
629 if(mp
.button
== M_BUTTON_LEFT
)
630 display_attachment(msgno
, current
->attp
, DA_SAVE
);
633 else if(mp
.button
== M_BUTTON_RIGHT
){
634 MPopup atmt_popup
[20];
635 int i
= -1, exoffer
= 0;
637 dline
= attachment_screen_updater(ps
,current
,&screen
);
639 if(dispatch_attachment(current
->attp
) != MCD_NONE
){
640 atmt_popup
[++i
].type
= tQueue
;
641 atmt_popup
[i
].data
.val
= 'V';
642 atmt_popup
[i
].label
.style
= lNormal
;
643 atmt_popup
[i
].label
.string
= "&View";
645 if(!(current
->attp
->can_display
& MCD_EXTERNAL
)
646 && (current
->attp
->body
->type
== TYPETEXT
647 || MIME_MSG_A(current
->attp
)
648 || MIME_DGST_A(current
->attp
))){
650 atmt_popup
[++i
].type
= tIndex
;
651 atmt_popup
[i
].label
.style
= lNormal
;
652 atmt_popup
[i
].label
.string
=
653 "View in New Window";
657 atmt_popup
[++i
].type
= tQueue
;
658 atmt_popup
[i
].data
.val
= 'S';
659 atmt_popup
[i
].label
.style
= lNormal
;
660 atmt_popup
[i
].label
.string
= "&Save";
662 atmt_popup
[++i
].type
= tQueue
;
663 atmt_popup
[i
].label
.style
= lNormal
;
664 if(current
->dstring
[1] == 'D'){
665 atmt_popup
[i
].data
.val
= 'U';
666 atmt_popup
[i
].label
.string
= "&Undelete";
669 atmt_popup
[i
].data
.val
= 'D';
670 atmt_popup
[i
].label
.string
= "&Delete";
673 if(MIME_MSG_A(current
->attp
)){
674 atmt_popup
[++i
].type
= tQueue
;
675 atmt_popup
[i
].label
.style
= lNormal
;
676 atmt_popup
[i
].label
.string
= "&Reply...";
677 atmt_popup
[i
].data
.val
= 'R';
679 atmt_popup
[++i
].type
= tQueue
;
680 atmt_popup
[i
].label
.style
= lNormal
;
681 atmt_popup
[i
].label
.string
= "&Forward...";
682 atmt_popup
[i
].data
.val
= 'F';
685 atmt_popup
[++i
].type
= tQueue
;
686 atmt_popup
[i
].label
.style
= lNormal
;
687 atmt_popup
[i
].label
.string
= "&About...";
688 atmt_popup
[i
].data
.val
= 'A';
690 atmt_popup
[++i
].type
= tSeparator
;
692 atmt_popup
[++i
].type
= tQueue
;
693 snprintf(backtag
, sizeof(backtag
), "View Message #%ld",
694 mn_get_cur(ps
->msgmap
));
695 backtag
[sizeof(backtag
)-1] = '\0';
696 atmt_popup
[i
].label
.string
= backtag
;
697 atmt_popup
[i
].label
.style
= lNormal
;
698 atmt_popup
[i
].data
.val
= '<';
700 atmt_popup
[++i
].type
= tTail
;
702 if(mswin_popup(atmt_popup
) == 1 && exoffer
)
703 display_att_window(current
->attp
);
706 else if(mp
.button
== M_BUTTON_RIGHT
){
707 MPopup atmt_popup
[2];
709 atmt_popup
[0].type
= tQueue
;
710 snprintf(backtag
, sizeof(backtag
), "View Message #%ld",
711 mn_get_cur(ps
->msgmap
));
712 backtag
[sizeof(backtag
)-1] = '\0';
713 atmt_popup
[0].label
.string
= backtag
;
714 atmt_popup
[0].label
.style
= lNormal
;
715 atmt_popup
[0].data
.val
= '<';
717 atmt_popup
[1].type
= tTail
;
719 mswin_popup(atmt_popup
);
726 case MC_WHEREIS
: /* whereis */
727 /*--- get string ---*/
729 char *result
= NULL
, buf
[64];
730 static char last
[64], tmp
[64];
733 ps
->mangled_footer
= 1;
735 snprintf(tmp
, sizeof(tmp
), "Word to find %s%s%s: ",
736 (last
[0]) ? "[" : "",
737 (last
[0]) ? last
: "",
738 (last
[0]) ? "]" : "");
739 tmp
[sizeof(tmp
)-1] = '\0';
742 int flags
= OE_APPEND_CURRENT
| OE_SEQ_SENSITIVE
;
744 rc
= optionally_enter(buf
,-FOOTER_ROWS(ps
),0,sizeof(buf
),
745 tmp
,NULL
,help
,&flags
);
747 help
= help
== NO_HELP
? h_attach_index_whereis
: NO_HELP
;
748 else if(rc
== 0 || rc
== 1 || !buf
[0]){
749 if(rc
== 0 && !buf
[0] && last
[0]){
750 strncpy(buf
, last
, sizeof(buf
));
751 buf
[sizeof(buf
)-1] = '\0';
758 if(rc
== 0 && buf
[0]){
760 while((ctmp
= next_attline(ctmp
)) != NULL
)
761 if(srchstr(ctmp
->dstring
, buf
)){
767 ctmp
= first_attline(current
);
769 while(ctmp
!= current
)
770 if(srchstr(ctmp
->dstring
, buf
)){
775 ctmp
= next_attline(ctmp
);
779 result
= _("WhereIs cancelled");
782 strncpy(last
, buf
, sizeof(last
));
783 last
[sizeof(last
)-1] = '\0';
784 result
= "Word found";
788 q_status_message(SM_ORDER
, 0, 3,
789 result
? result
: _("Word not found"));
795 if(delete_attachment(msgno
, current
->attp
)){
796 int l
= current
? strlen(current
->attp
->number
) : 0;
798 current
->dstring
[1] = 'D';
800 /* Also indicate any children that will be deleted */
802 for(ctmp
= current
; ctmp
; ctmp
= next_attline(ctmp
))
803 if(!strncmp(ctmp
->attp
->number
, current
->attp
->number
, l
)
804 && ctmp
->attp
->number
[l
] == '.'){
805 ctmp
->dstring
[1] = 'D';
806 ps
->mangled_screen
= 1;
813 if(undelete_attachment(msgno
, current
->attp
, &expbits
)){
814 int l
= current
? strlen(current
->attp
->number
) : 0;
816 current
->dstring
[1] = ' ';
818 /* And unflag anything implicitly undeleted */
819 for(ctmp
= current
; ctmp
; ctmp
= next_attline(ctmp
))
820 if(!strncmp(ctmp
->attp
->number
, current
->attp
->number
, l
)
821 && ctmp
->attp
->number
[l
] == '.'
822 && (!msgno_exceptions(ps
->mail_stream
, msgno
,
823 ctmp
->attp
->number
, &expbits
, FALSE
)
824 || !(expbits
& MSG_EX_DELETE
))){
825 ctmp
->dstring
[1] = ' ';
826 ps
->mangled_screen
= 1;
833 reply_msg_att(ps
->mail_stream
, msgno
, current
->attp
);
837 forward_attachment(ps
->mail_stream
, msgno
, current
->attp
);
841 bounce_msg_att(ps
->mail_stream
, msgno
, current
->attp
->number
,
842 current
->attp
->body
->nested
.msg
->env
->subject
);
843 ps
->mangled_footer
= 1;
847 display_attach_info(msgno
, current
->attp
);
850 case MC_VIEW_ATCH
: /* View command */
851 display_attachment(msgno
, current
->attp
, DA_SAVE
);
853 /* fall thru to repaint */
855 case MC_REPAINT
: /* redraw */
857 ps
->mangled_screen
= 1;
861 export_attachment(-FOOTER_ROWS(ps
), msgno
, current
->attp
);
862 ps
->mangled_footer
= 1;
865 case MC_SAVETEXT
: /* Save command */
866 save_attachment(-FOOTER_ROWS(ps
), msgno
, current
->attp
);
867 ps
->mangled_footer
= 1;
870 case MC_PRINTMSG
: /* Save command */
871 print_attachment(-FOOTER_ROWS(ps
), msgno
, current
->attp
);
872 ps
->mangled_footer
= 1;
875 case MC_PIPE
: /* Pipe command */
876 if(F_ON(F_ENABLE_PIPE
, ps
)){
877 pipe_attachment(msgno
, current
->attp
);
878 ps
->mangled_footer
= 1;
880 } /* fall thru to complain */
882 case MC_NONE
: /* simple timeout */
886 bogus_utf8_command(utf8str
, F_ON(F_USE_FK
, ps
) ? "F1" : "?");
897 bogus_command(ch
, F_ON(F_USE_FK
, ps
) ? "F1" : "?");
902 for(current
= first_attline(current
); current
;){ /* clean up */
903 ctmp
= current
->next
;
904 free_attline(¤t
);
908 if(screen
.titlecolor
)
909 free_color_pair(&screen
.titlecolor
);
913 /*----------------------------------------------------------------------
914 allocate and attach a fresh attachment line struct
916 Args: current -- display line to attach new struct to
918 Returns: newly alloc'd attachment display line
921 new_attline(ATDISP_S
**current
)
925 p
= (ATDISP_S
*)fs_get(sizeof(ATDISP_S
));
926 memset((void *)p
, 0, sizeof(ATDISP_S
));
929 p
->next
= (*current
)->next
;
930 (*current
)->next
= p
;
943 /*----------------------------------------------------------------------
944 Release system resources associated with attachment display line
946 Args: p -- line to free
951 free_attline(ATDISP_S
**p
)
955 fs_give((void **)&(*p
)->dstring
);
962 /*----------------------------------------------------------------------
963 Manage display of the attachment screen menu body.
965 Args: ps -- pine struct pointer
966 current -- currently selected display line
967 screen -- reference points for display painting
972 attachment_screen_updater(struct pine
*ps
, ATDISP_S
*current
, ATT_SCREEN_S
*screen
)
974 int dline
, return_line
= HEADER_ROWS(ps
);
975 ATDISP_S
*top_line
, *ctmp
;
977 /* calculate top line of display */
979 ctmp
= top_line
= first_attline(current
);
981 if(((dline
++)%(ps
->ttyo
->screen_rows
-HEADER_ROWS(ps
)-FOOTER_ROWS(ps
)))==0)
983 while(ctmp
!= current
&& (ctmp
= next_attline(ctmp
)));
986 /* Don't know how to manage scroll bar for attachment screen yet. */
987 scroll_setrange (0L, 0L);
990 /* mangled body or new page, force redraw */
991 if(ps
->mangled_body
|| screen
->top_line
!= top_line
)
992 screen
->current
= NULL
;
994 /* loop thru painting what's needed */
995 for(dline
= 0, ctmp
= top_line
;
996 dline
< ps
->ttyo
->screen_rows
- FOOTER_ROWS(ps
) - HEADER_ROWS(ps
);
997 dline
++, ctmp
= next_attline(ctmp
)){
1000 * only fall thru painting if something needs painting...
1002 if(!(!screen
->current
|| ctmp
== screen
->current
|| ctmp
== current
))
1005 if(F_ON(F_ENABLE_DEL_WHEN_WRITING
, ps_global
))
1006 ClearLine(dline
+ HEADER_ROWS(ps
));
1007 if(ctmp
&& ctmp
->dstring
){
1008 char *p
= tmp_20k_buf
;
1009 int i
, col
, x
= 0, totlen
;
1011 if(F_ON(F_FORCE_LOW_SPEED
,ps
) || ps
->low_speed
){
1013 if(ctmp
== current
){
1014 return_line
= dline
+ HEADER_ROWS(ps
);
1015 PutLine0(dline
+ HEADER_ROWS(ps
), 0, "->");
1018 PutLine0(dline
+ HEADER_ROWS(ps
), 0, " ");
1021 * Only paint lines if we have to...
1026 else if(ctmp
== current
){
1027 return_line
= dline
+ HEADER_ROWS(ps
);
1031 totlen
= strlen(ctmp
->dstring
);
1034 * Copy the value to a temp buffer expanding tabs.
1035 * Assume the caller set the widths so as not to overflow the
1038 for(i
=0,col
=x
; ctmp
->dstring
[i
]; i
++){
1039 if(ctmp
->dstring
[i
] == TAB
){
1040 if((p
-tmp_20k_buf
) < SIZEOF_20KBUF
-8)
1043 while((++col
)&0x07);
1046 col
+= width_at_this_position((unsigned char *) &ctmp
->dstring
[i
], totlen
-i
);
1047 if((p
-tmp_20k_buf
) < SIZEOF_20KBUF
)
1048 *p
++ = ctmp
->dstring
[i
];
1053 if((p
-tmp_20k_buf
) < SIZEOF_20KBUF
)
1056 PutLine0(dline
+ HEADER_ROWS(ps
), x
, tmp_20k_buf
+ x
);
1059 && !(F_ON(F_FORCE_LOW_SPEED
,ps
) || ps
->low_speed
))
1062 else if(F_OFF(F_ENABLE_DEL_WHEN_WRITING
, ps_global
))
1063 ClearLine(dline
+ HEADER_ROWS(ps
));
1066 ps
->mangled_body
= 0;
1067 screen
->top_line
= top_line
;
1068 screen
->current
= current
;
1069 return(return_line
);
1073 /*----------------------------------------------------------------------
1074 Redraw the attachment screen based on the global "att_screen" struct
1081 attachment_screen_redrawer(void)
1085 update_att_screen_titlebar();
1086 ps_global
->mangled_header
= 0;
1089 ps_global
->mangled_body
= 1;
1090 (void)attachment_screen_updater(ps_global
,att_screen
->current
,att_screen
);
1093 draw_keymenu(&att_index_keymenu
, bitmap
, ps_global
->ttyo
->screen_cols
,
1094 1-FOOTER_ROWS(ps_global
), 0, SameMenu
);
1099 update_att_screen_titlebar(void)
1102 COLOR_PAIR
*returned_color
= NULL
;
1103 COLOR_PAIR
*titlecolor
= NULL
;
1105 SEARCHSET
*ss
= NULL
;
1106 PAT_STATE
*pstate
= NULL
;
1108 if(ps_global
->titlebar_color_style
!= TBAR_COLOR_DEFAULT
){
1109 raw_msgno
= mn_m2raw(ps_global
->msgmap
, mn_get_cur(ps_global
->msgmap
));
1110 ss
= mail_newsearchset();
1111 ss
->first
= ss
->last
= (unsigned long) raw_msgno
;
1114 colormatch
= get_index_line_color(ps_global
->mail_stream
,
1115 ss
, &pstate
, &returned_color
);
1116 mail_free_searchset(&ss
);
1119 * This is a bit tricky. If there is a colormatch but
1121 * is NULL, that means that the user explicitly wanted the
1122 * Normal color used in this index line, so that is what we
1123 * use. If no colormatch then we will use the TITLE color
1124 * instead of Normal.
1128 titlecolor
= returned_color
;
1130 titlecolor
= new_color_pair(ps_global
->VAR_NORM_FORE_COLOR
,
1131 ps_global
->VAR_NORM_BACK_COLOR
);
1135 && ps_global
->titlebar_color_style
== TBAR_COLOR_REV_INDEXLINE
){
1136 char cbuf
[MAXCOLORLEN
+1];
1138 strncpy(cbuf
, titlecolor
->fg
, sizeof(cbuf
));
1139 cbuf
[sizeof(cbuf
)-1] = '\0';
1140 strncpy(titlecolor
->fg
, titlecolor
->bg
, MAXCOLORLEN
);
1141 titlecolor
->fg
[MAXCOLORLEN
] = '\0';
1142 strncpy(titlecolor
->bg
, cbuf
, MAXCOLORLEN
);
1143 titlecolor
->bg
[MAXCOLORLEN
] = '\0';
1147 /* Did the color change? */
1148 if((!titlecolor
&& att_screen
->titlecolor
)
1150 (titlecolor
&& !att_screen
->titlecolor
)
1152 (titlecolor
&& att_screen
->titlecolor
1153 && (strcmp(titlecolor
->fg
, att_screen
->titlecolor
->fg
)
1154 || strcmp(titlecolor
->bg
, att_screen
->titlecolor
->bg
)))){
1156 if(att_screen
->titlecolor
)
1157 free_color_pair(&att_screen
->titlecolor
);
1159 att_screen
->titlecolor
= titlecolor
;
1164 free_color_pair(&titlecolor
);
1167 set_titlebar(_("ATTACHMENT INDEX"), ps_global
->mail_stream
,
1168 ps_global
->context_current
, ps_global
->cur_folder
,
1169 ps_global
->msgmap
, 1, MessageNumber
, 0, 0,
1170 att_screen
->titlecolor
);
1174 /*----------------------------------------------------------------------
1175 Seek back from the given display line to the beginning of the list
1177 Args: p -- display linked list
1182 first_attline(ATDISP_S
*p
)
1192 init_att_progress(char *msg
, MAILSTREAM
*stream
, struct mail_bodystruct
*body
)
1194 if((save_att_length
= body
->size
.bytes
) != 0){
1195 /* if there are display filters, factor in extra copy */
1196 if(body
->type
== TYPETEXT
&& ps_global
->VAR_DISPLAY_FILTERS
)
1197 save_att_length
+= body
->size
.bytes
;
1199 /* if remote folder and segment not cached, factor in IMAP fetch */
1200 if(stream
&& stream
->mailbox
&& IS_REMOTE(stream
->mailbox
)
1201 && !((body
->type
== TYPETEXT
&& body
->contents
.text
.data
)
1202 || ((body
->type
== TYPEMESSAGE
)
1203 && body
->nested
.msg
&& body
->nested
.msg
->text
.text
.data
)
1204 || body
->contents
.text
.data
))
1205 save_att_length
+= body
->size
.bytes
;
1207 gf_filter_init(); /* reset counters */
1210 return(busy_cue(msg
, save_att_percent
, 0));
1218 save_att_piped(int reset
)
1226 else if((y
= gf_bytes_piped()) >= x
){
1236 save_att_percent(void)
1238 int i
= (int) (((pine_gets_bytes(0) + save_att_piped(0)) * 100)
1240 return(MIN(i
, 100));
1244 /*----------------------------------------------------------------------
1245 Save the given attachment associated with the given message no
1252 save_attachment(int qline
, long int msgno
, ATTACH_S
*a
)
1254 if(ps_global
->restricted
){
1255 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
1256 "Alpine demo can't save attachments");
1261 save_msg_att(msgno
, a
);
1262 else if(MIME_DGST_A(a
))
1263 save_digest_att(msgno
, a
);
1264 else if(MIME_VCARD_A(a
))
1265 save_vcard_att(ps_global
, qline
, msgno
, a
);
1267 write_attachment(qline
, msgno
, a
, "SAVE");
1271 /*----------------------------------------------------------------------
1272 Save the given attachment associated with the given message no
1279 export_attachment(int qline
, long int msgno
, ATTACH_S
*a
)
1281 if(ps_global
->restricted
){
1282 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
1283 "Alpine demo can't export attachments");
1288 export_msg_att(msgno
, a
);
1289 else if(MIME_DGST_A(a
))
1290 export_digest_att(msgno
, a
);
1292 q_status_message1(SM_ORDER
, 0, 3,
1293 _("Can't Export %s. Use \"Save\" to write file, \"<\" to leave index."),
1294 body_type_names(a
->body
->type
));
1299 write_attachment(int qline
, long int msgno
, ATTACH_S
*a
, char *method
)
1301 char filename
[MAXPATH
+1], full_filename
[MAXPATH
+1],
1302 title_buf
[64], *err
;
1303 int r
, rflags
= GER_NONE
, we_cancel
= 0, flags
;
1304 static HISTORY_S
*history
= NULL
;
1305 static ESCKEY_S att_save_opts
[] = {
1306 {ctrl('T'), 10, "^T", N_("To Files")},
1307 {-1, 0, NULL
, NULL
},
1308 {-1, 0, NULL
, NULL
},
1309 {-1, 0, NULL
, NULL
}};
1311 /*------- Figure out suggested file name ----*/
1312 filename
[0] = full_filename
[0] = '\0';
1313 (void) get_filename_parameter(filename
, sizeof(filename
), a
->body
, NULL
);
1315 dprint((9, "export_attachment(name: %s)\n",
1316 filename
? filename
: "?"));
1319 #if !defined(DOS) && !defined(MAC) && !defined(OS2)
1320 if(ps_global
->VAR_DOWNLOAD_CMD
&& ps_global
->VAR_DOWNLOAD_CMD
[0]){
1321 att_save_opts
[++r
].ch
= ctrl('V');
1322 att_save_opts
[r
].rval
= 12;
1323 att_save_opts
[r
].name
= "^V";
1324 att_save_opts
[r
].label
= N_("Downld Msg");
1326 #endif /* !(DOS || MAC) */
1328 if(F_ON(F_ENABLE_TAB_COMPLETE
,ps_global
)){
1329 att_save_opts
[++r
].ch
= ctrl('I');
1330 att_save_opts
[r
].rval
= 11;
1331 att_save_opts
[r
].name
= "TAB";
1332 att_save_opts
[r
].label
= N_("Complete");
1335 att_save_opts
[++r
].ch
= -1;
1337 snprintf(title_buf
, sizeof(title_buf
), "%s ATTACHMENT", method
);
1338 title_buf
[sizeof(title_buf
)-1] = '\0';
1340 flags
= (a
&& a
->body
&& a
->body
->type
== TYPETEXT
? GE_BINARY
: 0)
1343 r
= get_export_filename(ps_global
, filename
, NULL
, full_filename
,
1344 sizeof(filename
), "attachment", title_buf
,
1345 att_save_opts
, &rflags
, qline
, flags
, &history
);
1350 cmd_cancelled((char *) lcase((unsigned char *) title_buf
+ 1) - 1);
1354 q_status_message1(SM_ORDER
, 0, 2,
1355 _("Can't save to file outside of %s"),
1356 ps_global
->VAR_OPER_DIR
);
1362 #if !defined(DOS) && !defined(MAC) && !defined(OS2)
1363 else if(r
== 12){ /* Download */
1364 char cmd
[MAXPATH
], *tfp
= NULL
;
1369 char prompt_buf
[256];
1371 if(ps_global
->restricted
){
1372 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
1373 "Download disallowed in restricted mode");
1378 tfp
= temp_nam(NULL
, "pd");
1379 dprint((1, "Download attachment called!\n"));
1380 if((store
= so_get(FileStar
, tfp
, WRITE_ACCESS
|OWNER_ONLY
|WRITE_TO_LOCALE
)) != NULL
){
1382 snprintf(prompt_buf
, sizeof(prompt_buf
), "Saving to \"%s\"", tfp
);
1383 prompt_buf
[sizeof(prompt_buf
)-1] = '\0';
1384 we_cancel
= init_att_progress(prompt_buf
,
1385 ps_global
->mail_stream
,
1388 gf_set_so_writec(&pc
, store
);
1389 if((err
= detach(ps_global
->mail_stream
, msgno
,
1390 a
->number
, 0L, &len
, pc
, NULL
, 0)) != NULL
)
1391 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
1392 "%s: Error writing attachment to \"%s\"",
1395 /* cancel regardless, so it doesn't get in way of xfer */
1398 gf_clear_so_writec(store
);
1399 if(so_give(&store
)) /* close file */
1400 err
= "Error writing tempfile for download";
1403 build_updown_cmd(cmd
, sizeof(cmd
), ps_global
->VAR_DOWNLOAD_CMD_PREFIX
,
1404 ps_global
->VAR_DOWNLOAD_CMD
, tfp
);
1405 if((syspipe
= open_system_pipe(cmd
, NULL
, NULL
,
1406 PIPE_USER
| PIPE_RESET
,
1407 0, pipe_callback
, pipe_report_error
)) != NULL
)
1408 (void)close_system_pipe(&syspipe
, NULL
, pipe_callback
);
1410 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
1411 err
= "Error running download command");
1415 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
1416 err
= "Error building temp file for download");
1420 fs_give((void **)&tfp
);
1424 q_status_message1(SM_ORDER
, 0, 4, "Part %s downloaded",
1429 #endif /* !(DOS || MAC) */
1431 (void) write_attachment_to_file(ps_global
->mail_stream
, msgno
, a
,
1432 rflags
, full_filename
);
1438 * msgno -- raw message number
1439 * a -- attachment struct
1440 * flags -- comes from get_export_filename
1441 * GER_OVER -- the file was truncated before we wrote
1442 * GER_APPEND -- the file was not truncated prior to our writing,
1443 * so we were appending
1444 * else -- the file didn't previously exist
1445 * file -- the full pathname of the file
1447 * Returns 1 for successful write, 0 for nothing to write, -1 for error
1450 write_attachment_to_file(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
, int flags
, char *file
)
1452 char *l_string
, sbuf
[256], *err
, *err2
= NULL
;
1453 int is_text
, we_cancel
= 0, dt_flags
= 0, so_flags
;
1454 long len
, orig_size
;
1458 if(!(a
&& a
->body
&& a
->number
&& a
->number
[0] && file
&& file
[0]
1462 is_text
= (a
&& a
->body
&& a
->body
->type
== TYPETEXT
);
1464 if(flags
& GER_APPEND
)
1465 orig_size
= name_file_size(file
);
1467 if(flags
& GER_BINARY
)
1468 dt_flags
|= DT_BINARY
;
1470 so_flags
= ((is_text
&& !(flags
& GER_BINARY
)) ? WRITE_TO_LOCALE
: 0)
1473 store
= so_get(FileStar
, file
, so_flags
);
1475 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
1476 /* TRANSLATORS: Error opening destination <filename>: <error text> */
1477 _("Error opening destination %s: %s"),
1478 file
, error_description(errno
));
1482 snprintf(sbuf
, sizeof(sbuf
), "Saving to \"%s\"", file
);
1483 sbuf
[sizeof(sbuf
)-1] = '\0';
1484 we_cancel
= init_att_progress(sbuf
, stream
, a
->body
);
1486 gf_set_so_writec(&pc
, store
);
1487 err
= detach(stream
, msgno
, a
->number
, 0L, &len
, pc
, NULL
, dt_flags
);
1488 gf_clear_so_writec(store
);
1493 if(so_give(&store
)) /* close file */
1494 err2
= error_description(errno
);
1497 if(!(flags
& (GER_APPEND
| GER_OVER
)))
1500 our_truncate(file
, (flags
& GER_APPEND
) ? (off_t
) orig_size
: (off_t
) 0);
1502 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
1503 /* TRANSLATORS: <error text>: Error writing attachment to <filename> */
1504 _("%s: Error writing attachment to \"%s\""),
1505 err
? err
: err2
, file
);
1509 l_string
= cpystr(byte_string(len
));
1510 q_status_message8(SM_ORDER
, 0, 4,
1511 "Part %s, %s%s %s to \"%s\"%s%s%s",
1514 ? comatose(a
->body
->size
.lines
) : l_string
,
1515 is_text
? " lines" : "",
1518 : flags
& GER_APPEND
? "appended" : "written",
1520 (is_text
|| len
== a
->body
->size
.bytes
)
1521 ? "" : "(decoded from ",
1522 (is_text
|| len
== a
->body
->size
.bytes
)
1523 ? "" : byte_string(a
->body
->size
.bytes
),
1524 is_text
|| len
== a
->body
->size
.bytes
1526 fs_give((void **)&l_string
);
1533 write_attached_msg(long int msgno
, ATTACH_S
**ap
, STORE_S
*store
, int newfile
)
1536 long start_of_append
;
1540 if(ap
&& *ap
&& (*ap
)->body
&& (*ap
)->body
->nested
.msg
1541 && (*ap
)->body
->nested
.msg
->env
){
1542 start_of_append
= so_tell(store
);
1544 gf_set_so_writec(&pc
, store
);
1545 if(!(ps_global
->mail_stream
&& msgno
> 0L
1546 && msgno
<= ps_global
->mail_stream
->nmsgs
1547 && (mc
= mail_elt(ps_global
->mail_stream
, msgno
)) && mc
->valid
))
1550 if(!bezerk_delimiter((*ap
)->body
->nested
.msg
->env
, mc
, pc
, newfile
)
1551 || !format_msg_att(msgno
, ap
, NULL
, pc
, FM_NOINDENT
))
1552 err
= error_description(errno
);
1554 gf_clear_so_writec(store
);
1557 ftruncate(fileno((FILE *)store
->txt
), (off_t
) start_of_append
);
1560 err
= "Can't export message. Missing Envelope data";
1566 /*----------------------------------------------------------------------
1567 Save the attachment message/rfc822 to specified folder
1574 save_msg_att(long int msgno
, ATTACH_S
*a
)
1576 char newfolder
[MAILTMPLEN
], *save_folder
, *flags
= NULL
;
1577 char date
[64], nmsgs
[80];
1578 CONTEXT_S
*cntxt
= NULL
;
1579 int our_stream
= 0, rv
;
1580 MAILSTREAM
*save_stream
;
1583 snprintf(nmsgs
, sizeof(nmsgs
), _("Attached Msg (part %s) "), a
->number
);
1584 nmsgs
[sizeof(nmsgs
)-1] = '\0';
1585 if(save_prompt(ps_global
, &cntxt
, newfolder
, sizeof(newfolder
), nmsgs
,
1586 a
->body
->nested
.msg
->env
, msgno
, a
->number
, NULL
, NULL
)){
1587 if(strucmp(newfolder
, ps_global
->inbox_name
) == 0){
1588 save_folder
= ps_global
->VAR_INBOX_PATH
;
1592 save_folder
= newfolder
;
1594 save_stream
= save_msg_stream(cntxt
, save_folder
, &our_stream
);
1596 mc
= (msgno
> 0L && ps_global
->mail_stream
1597 && msgno
<= ps_global
->mail_stream
->nmsgs
)
1598 ? mail_elt(ps_global
->mail_stream
, msgno
) : NULL
;
1599 flags
= flag_string(ps_global
->mail_stream
, msgno
, F_ANS
|F_FLAG
|F_SEEN
|F_KEYWORD
);
1601 mail_date(date
, mc
);
1605 if(pith_opt_save_size_changed_prompt
)
1606 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_INIT
);
1608 rv
= save_msg_att_work(msgno
, a
, save_stream
, save_folder
, cntxt
, date
);
1610 if(pith_opt_save_size_changed_prompt
)
1611 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_END
);
1614 fs_give((void **) &flags
);
1617 q_status_message2(SM_ORDER
, 0, 4,
1618 _("Attached message (part %s) saved to \"%s\""),
1622 cmd_cancelled("Attached message Save");
1623 /* else whatever broke in save_fetch_append shoulda bitched */
1626 mail_close(save_stream
);
1631 /*----------------------------------------------------------------------
1632 Save the message/rfc822 in the given digest to the specified folder
1639 save_digest_att(long int msgno
, ATTACH_S
*a
)
1641 char newfolder
[MAILTMPLEN
], *save_folder
,
1642 date
[64], nmsgs
[80];
1643 CONTEXT_S
*cntxt
= NULL
;
1644 int our_stream
= 0, rv
, cnt
= 0;
1645 MAILSTREAM
*save_stream
;
1650 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
));
1652 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
))
1655 snprintf(nmsgs
, sizeof(nmsgs
), "%d Msg Digest (part %s) ", cnt
, a
->number
);
1656 nmsgs
[sizeof(nmsgs
)-1] = '\0';
1658 if(save_prompt(ps_global
, &cntxt
, newfolder
, sizeof(newfolder
),
1659 nmsgs
, NULL
, 0, NULL
, NULL
, NULL
)){
1660 save_folder
= (strucmp(newfolder
, ps_global
->inbox_name
) == 0)
1661 ? ps_global
->VAR_INBOX_PATH
: newfolder
;
1663 save_stream
= save_msg_stream(cntxt
, save_folder
, &our_stream
);
1665 if(pith_opt_save_size_changed_prompt
)
1666 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_INIT
);
1670 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
));
1672 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
)){
1674 rv
= save_msg_att_work(msgno
, ap
, save_stream
, save_folder
, cntxt
, date
);
1679 if(pith_opt_save_size_changed_prompt
)
1680 (*pith_opt_save_size_changed_prompt
)(0L, SSCP_END
);
1683 q_status_message2(SM_ORDER
, 0, 4,
1684 _("Attached digest (part %s) saved to \"%s\""),
1688 cmd_cancelled("Attached digest Save");
1689 /* else whatever broke in save_fetch_append shoulda bitched */
1692 mail_close(save_stream
);
1698 save_msg_att_work(long int msgno
, ATTACH_S
*a
, MAILSTREAM
*save_stream
,
1699 char *save_folder
, CONTEXT_S
*cntxt
, char *date
)
1704 if(a
&& a
->body
&& MIME_MSG(a
->body
->type
, a
->body
->subtype
)){
1705 if((so
= so_get(CharStar
, NULL
, WRITE_ACCESS
)) != NULL
){
1707 rv
= save_fetch_append(ps_global
->mail_stream
, msgno
,
1709 save_stream
, save_folder
, cntxt
,
1710 a
->body
->size
.bytes
,
1714 dprint((1, "Can't allocate store for save: %s\n",
1715 error_description(errno
)));
1716 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
1717 _("Problem creating space for message text."));
1726 /*----------------------------------------------------------------------
1727 Export the attachment message/rfc822 to specified file
1734 export_msg_att(long int msgno
, ATTACH_S
*a
)
1736 char filename
[MAXPATH
+1], full_filename
[MAXPATH
+1], *err
;
1737 int rv
, rflags
= GER_NONE
, i
= 1;
1740 static HISTORY_S
*history
= NULL
;
1741 static ESCKEY_S opts
[] = {
1742 {ctrl('T'), 10, "^T", N_("To Files")},
1743 {-1, 0, NULL
, NULL
},
1744 {-1, 0, NULL
, NULL
}};
1746 if(F_ON(F_ENABLE_TAB_COMPLETE
,ps_global
)){
1747 opts
[i
].ch
= ctrl('I');
1749 opts
[i
].name
= "TAB";
1750 opts
[i
].label
= N_("Complete");
1753 filename
[0] = full_filename
[0] = '\0';
1755 rv
= get_export_filename(ps_global
, filename
, NULL
, full_filename
,
1756 sizeof(filename
), "msg attachment",
1757 /* TRANSLATORS: Message Attachment (a screen title) */
1758 _("MSG ATTACHMENT"), opts
,
1759 &rflags
, -FOOTER_ROWS(ps_global
),
1760 GE_IS_EXPORT
| GE_SEQ_SENSITIVE
, &history
);
1765 cmd_cancelled("Export");
1769 q_status_message1(SM_ORDER
, 0, 2,
1770 _("Can't export to file outside of %s"),
1771 ps_global
->VAR_OPER_DIR
);
1778 /* With name in hand, allocate storage object and save away... */
1779 if((store
= so_get(FileStar
, full_filename
, WRITE_ACCESS
)) != NULL
){
1780 if((err
= write_attached_msg(msgno
, &ap
, store
, !(rflags
& GER_APPEND
))) != NULL
)
1781 q_status_message(SM_ORDER
| SM_DING
, 3, 4, err
);
1783 q_status_message3(SM_ORDER
, 0, 4,
1784 _("Attached message (part %s) %s to \"%s\""),
1788 : rflags
& GER_APPEND
? _("appended") : _("written"),
1792 q_status_message2(SM_ORDER
| SM_DING
, 3, 4,
1793 _("Error writing %s: %s"),
1794 full_filename
, error_description(errno
));
1797 q_status_message2(SM_ORDER
| SM_DING
, 3, 4,
1798 /* TRANSLATORS: Error opening file <filename> to export message: <error text> */
1799 _("Error opening file \"%s\" to export message: %s"),
1800 full_filename
, error_description(errno
));
1804 /*----------------------------------------------------------------------
1805 Export the message/rfc822 in the given digest to the specified file
1812 export_digest_att(long int msgno
, ATTACH_S
*a
)
1814 char filename
[MAXPATH
+1], full_filename
[MAXPATH
+1], *err
= NULL
;
1815 int rv
, rflags
= GER_NONE
, i
= 1;
1818 static HISTORY_S
*history
= NULL
;
1820 static ESCKEY_S opts
[] = {
1821 {ctrl('T'), 10, "^T", N_("To Files")},
1822 {-1, 0, NULL
, NULL
},
1823 {-1, 0, NULL
, NULL
}};
1825 if(F_ON(F_ENABLE_TAB_COMPLETE
,ps_global
)){
1826 opts
[i
].ch
= ctrl('I');
1828 opts
[i
].name
= "TAB";
1829 opts
[i
].label
= N_("Complete");
1832 filename
[0] = full_filename
[0] = '\0';
1834 rv
= get_export_filename(ps_global
, filename
, NULL
, full_filename
,
1835 sizeof(filename
), "digest", _("DIGEST ATTACHMENT"),
1836 opts
, &rflags
, -FOOTER_ROWS(ps_global
),
1837 GE_IS_EXPORT
| GE_SEQ_SENSITIVE
, &history
);
1842 cmd_cancelled("Export");
1846 q_status_message1(SM_ORDER
, 0, 2,
1847 _("Can't export to file outside of %s"),
1848 ps_global
->VAR_OPER_DIR
);
1855 /* With name in hand, allocate storage object and save away... */
1856 if((store
= so_get(FileStar
, full_filename
, WRITE_ACCESS
)) != NULL
){
1861 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
))
1864 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
)){
1866 err
= write_attached_msg(msgno
, &ap
, store
,
1867 !count
&& !(rflags
& GER_APPEND
));
1872 err
= error_description(errno
);
1875 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
1876 _("Error exporting: %s"), err
);
1877 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
1878 _("%s messages exported before error occurred"), err
);
1881 q_status_message4(SM_ORDER
, 0, 4,
1882 "%s messages in digest (part %s) %s to \"%s\"",
1887 : rflags
& GER_APPEND
? "appended" : "written",
1891 q_status_message2(SM_ORDER
| SM_DING
, 3, 4,
1892 _("Error opening file \"%s\" to export digest: %s"),
1893 full_filename
, error_description(errno
));
1897 /*----------------------------------------------------------------------
1898 Print the given attachment associated with the given message no
1905 print_attachment(int qline
, long int msgno
, ATTACH_S
*a
)
1909 if(ps_global
->restricted
){
1910 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
1911 "Alpine demo can't Print attachments");
1915 snprintf(prompt
, sizeof(prompt
), "attach%s %s",
1916 (a
->body
->type
== TYPETEXT
) ? "ment" : "ed message",
1917 MIME_DGST_A(a
) ? "digest" : a
->number
);
1918 prompt
[sizeof(prompt
)-1] = '\0';
1919 if(open_printer(prompt
) >= 0){
1921 (void) print_msg_att(msgno
, a
, 1);
1922 else if(MIME_DGST_A(a
))
1923 print_digest_att(msgno
, a
);
1925 (void) decode_text(a
, msgno
, print_char
, NULL
, QStatus
, FM_NOINDENT
);
1933 * Print the attachment message/rfc822 to specified file
1935 * Returns 1 on success, 0 on failure.
1938 print_msg_att(long int msgno
, ATTACH_S
*a
, int first
)
1943 if(!(ps_global
->mail_stream
&& msgno
> 0L
1944 && msgno
<= ps_global
->mail_stream
->nmsgs
1945 && (mc
= mail_elt(ps_global
->mail_stream
, msgno
)) && mc
->valid
))
1948 if(((!first
&& F_ON(F_AGG_PRINT_FF
, ps_global
)) ? print_char(FORMFEED
) : 1)
1949 && pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
)
1950 && (F_ON(F_FROM_DELIM_IN_PRINT
, ps_global
)
1951 ? bezerk_delimiter(a
->body
->nested
.msg
->env
, mc
, print_char
, !first
)
1953 && format_msg_att(msgno
, &ap
, NULL
, print_char
, FM_NOINDENT
))
1957 q_status_message2(SM_ORDER
| SM_DING
, 3, 3,
1958 _("Error printing message %s, part %s"),
1959 long2string(msgno
), a
->number
);
1964 /*----------------------------------------------------------------------
1965 Print the attachment message/rfc822 to specified file
1972 print_digest_att(long int msgno
, ATTACH_S
*a
)
1979 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
));
1981 if(MIME_MSG(ap
->body
->type
, ap
->body
->subtype
)){
1982 char *p
= part_desc(ap
->number
, ap
->body
->nested
.msg
->body
,
1983 0, 80, FM_NOINDENT
, print_char
);
1985 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
1986 _("Can't print digest: %s"), p
);
1989 else if(!print_msg_att(msgno
, ap
, !next
))
1998 display_html_external_attachment(long int msgno
, ATTACH_S
*a
, int flags
)
2000 char dir_path
[MAXPATH
+1];
2001 char *filename
= NULL
;
2002 char *file_path
; /* file:///some/path/ */
2006 int we_cancel
= 0, errs
;
2009 unsigned long rawno
;
2011 if(a
->body
== NULL
){
2012 q_status_message(SM_ORDER
| SM_DING
, 3, 5, _("Attachment has no body!"));
2014 } else if (a
->body
->type
!= TYPETEXT
2015 || a
->body
->subtype
== NULL
2016 || strucmp(a
->body
->subtype
, "HTML")){
2017 q_status_message(SM_ORDER
| SM_DING
, 3, 5, _("Not a TEXT/HTML attachment"));
2021 /* zero these variables, just in case. Do not try freeing them. They have short lives */
2022 for(att
= ps_global
->atmts
; att
->description
!= NULL
; att
++){
2023 att
->cid_tmpfile
= NULL
;
2027 /* setup the environment first */
2028 if(!ps_global
->html_dir
){
2029 if(!html_directory_path(ps_global
->VAR_HTML_DIRECTORY
, dir_path
, MAXPATH
)){
2030 q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2031 _("Error creating full path for %s"), ps_global
->VAR_HTML_DIRECTORY
);
2033 } else if (init_html_directory(dir_path
) < 0){
2034 q_status_message1(SM_ORDER
| SM_DING
, 3, 5, _("Error initializing %s"), dir_path
);
2037 ps_global
->html_dir
= cpystr(dir_path
);
2040 strncpy(dir_path
, ps_global
->html_dir
, sizeof(dir_path
));
2041 dir_path
[sizeof(dir_path
)-1] = '\0';
2044 if(create_random_dir(dir_path
, sizeof(dir_path
)) < 0){
2045 q_status_message1(SM_ORDER
| SM_DING
, 3, 5, _("Error creating temp dir in %s"), dir_path
);
2049 a
->tmpdir
= cpystr(dir_path
);
2050 add_html_log(&ps_global
->html_dir_list
, a
->tmpdir
);
2052 /* Process the text/html part */
2053 filename
= temp_nam_ext(a
->tmpdir
, "tmp-html-", HTML_EXT
);
2056 q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2057 _("Error \"%s\", Can't create temporary file"),
2058 error_description(errno
));
2062 if((store
= so_get(FileStar
, filename
, WRITE_ACCESS
|OWNER_ONLY
)) == NULL
){
2063 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
2064 _("Error \"%s\", Can't write file %s"),
2065 error_description(errno
), filename
);
2067 our_unlink(filename
);
2068 fs_give((void **)&filename
);
2073 if(a
->body
->size
.bytes
){
2076 snprintf(msg_buf
, sizeof(msg_buf
), "Decoding %s%s%s%s",
2077 a
->description
? "\"" : "",
2078 a
->description
? a
->description
: "attachment number ",
2079 a
->description
? "" : a
->number
,
2080 a
->description
? "\"" : "");
2081 msg_buf
[sizeof(msg_buf
)-1] = '\0';
2082 we_cancel
= init_att_progress(msg_buf
, ps_global
->mail_stream
, a
->body
);
2085 gf_set_so_writec(&pc
, store
);
2087 err
= detach(ps_global
->mail_stream
, msgno
, a
->number
, 0L, NULL
, pc
, NULL
,
2088 DT_EXTERNAL
| ((flags
& DA_ALLIMAGES
) ? DT_ALLIMAGES
: 0));
2090 gf_clear_so_writec(store
);
2097 /*----- Download all needed inline attachments ------*/
2099 rawno
= mn_m2raw(ps_global
->msgmap
, msgno
);
2100 for (att
= ps_global
->atmts
; rawno
> 0 && att
->description
!= NULL
; att
++){
2101 if(att
->cid_tmpfile
){
2102 if(write_attachment_to_file(ps_global
->mail_stream
, rawno
,
2103 att
, GER_NONE
, att
->cid_tmpfile
) != 1
2104 || name_file_size(att
->cid_tmpfile
) == 0L)
2106 fs_give((void **) &att
->cid_tmpfile
);
2109 fs_give((void **) &att
->tmpdir
);
2113 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
2114 "%s: Error saving message to temp file %s",
2117 our_unlink(filename
);
2118 fs_give((void **)&filename
);
2125 case 1 : q_status_message(SM_ORDER
| SM_DING
, 3, 5,
2126 "Failed to download one image. Continuing...");
2128 default: q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2129 "Failed to download %s images. Continuing...",
2134 tool
= get_url_external_handler("http://", 1);
2135 if(tool
== NULL
) tool
= get_url_external_handler("http://", 0);
2136 if(tool
== NULL
) tool
= get_url_external_handler("https://", 1);
2137 if(tool
== NULL
) tool
= get_url_external_handler("https://", 0);
2139 file_path
= fs_get((strlen(filename
) + strlen("file://") + 1)*sizeof(char));
2140 sprintf(file_path
, "file://%s", filename
);
2142 /*----- Run the viewer process ----*/
2143 if(do_url_launch(tool
, file_path
) == 0)
2144 q_status_message(SM_ORDER
, 3, 3, "Opened message in external browser");
2146 q_status_message(SM_ORDER
|SM_DING
, 3, 5, "Failed to open message in external browser");
2149 fs_give((void **)&filename
);
2152 fs_give((void **)&file_path
);
2154 ps_global
->mangled_screen
= 1;
2160 /*----------------------------------------------------------------------
2161 Unpack and display the given attachment associated with given message no.
2163 Args: msgno -- message no attachment is part of
2164 a -- attachment to display
2166 Returns: 0 on success, non-zero (and error message queued) otherwise
2169 display_attachment(long int msgno
, ATTACH_S
*a
, int flags
)
2171 char *filename
= NULL
;
2172 char sender_filename
[1000];
2177 int we_cancel
= 0, rv
;
2178 char prefix
[70 + 1000]; /* 1000 = sizeof(sender_filename) */
2182 if(flags
& DA_EXTERNAL
)
2183 return display_html_external_attachment(msgno
, a
, flags
);
2185 /*------- Display the attachment -------*/
2186 if(dispatch_attachment(a
) == MCD_NONE
){
2187 /*----- Can't display this type ------*/
2188 if(a
->body
->encoding
< ENCOTHER
)
2189 q_status_message4(SM_ORDER
| SM_DING
, 3, 5,
2190 /* TRANSLATORS: Don't know how to display <certain type> attachments. <might say Try Save.> */
2191 _("Don't know how to display %s%s%s attachments.%s"),
2192 body_type_names(a
->body
->type
),
2193 a
->body
->subtype
? "/" : "",
2194 a
->body
->subtype
? a
->body
->subtype
:"",
2195 (flags
& DA_SAVE
) ? _(" Try Save.") : "");
2197 q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2198 _("Don't know how to unpack \"%s\" encoding"),
2199 body_encodings
[(a
->body
->encoding
<= ENCMAX
)
2200 ? a
->body
->encoding
: ENCOTHER
]);
2204 else if(!(a
->can_display
& MCD_EXTERNAL
)){
2205 if(a
->body
->type
== TYPEMULTIPART
){
2206 if(a
->body
->subtype
){
2207 if(!strucmp(a
->body
->subtype
, "digest"))
2208 display_digest_att(msgno
, a
, flags
);
2210 q_status_message1(SM_ORDER
, 3, 5,
2211 _("Can't display Multipart/%s"),
2215 q_status_message(SM_ORDER
, 3, 5,
2216 _("Can't display unknown Multipart Subtype"));
2218 else if(MIME_VCARD_A(a
))
2219 display_vcard_att(msgno
, a
, flags
);
2220 else if( MIME_VCALENDAR(a
->body
->type
, a
->body
->subtype
))
2221 display_vcalendar_att(msgno
, a
, flags
);
2222 else if(a
->body
->type
== TYPETEXT
){
2224 rv
= display_text_att(msgno
, a
, flags
);
2225 } while(rv
== MC_FULLHDR
);
2227 else if(a
->body
->type
== TYPEMESSAGE
){
2229 rv
= display_msg_att(msgno
, a
, flags
);
2230 } while(rv
== MC_FULLHDR
);
2233 ps_global
->mangled_screen
= 1;
2237 /* arrive here if MCD_EXTERNAL */
2239 if(F_OFF(F_QUELL_ATTACH_EXTRA_PROMPT
, ps_global
)
2240 && (!(flags
& DA_DIDPROMPT
)))
2241 if(want_to(_("View selected Attachment"), 'y',
2242 0, NO_HELP
, WT_NORM
) == 'n'){
2243 cmd_cancelled(NULL
);
2247 sender_filename
[0] = '\0';
2251 if(F_OFF(F_QUELL_ATTACH_EXT_WARN
, ps_global
)
2252 && (a
->can_display
& MCD_EXT_PROMPT
)){
2255 (void) get_filename_parameter(sender_filename
, sizeof(sender_filename
),
2257 snprintf(prompt
, sizeof(prompt
),
2258 "Attachment %s%s unrecognized. %s%s%s",
2260 strlen(a
->body
->subtype
) > 12 ? "..." : "",
2261 (extp
&& extp
[0]) ? "Try open by file extension (." : "Try opening anyway",
2262 (extp
&& extp
[0]) ? extp
: "",
2263 (extp
&& extp
[0]) ? ")" : "");
2265 if(want_to(prompt
, 'n', 0, NO_HELP
, WT_NORM
) == 'n'){
2266 cmd_cancelled(NULL
);
2271 /*------ Write the image to a temporary file ------*/
2273 /* create type/subtype in mtype */
2274 strncpy(mtype
, body_type_names(a
->body
->type
), sizeof(mtype
));
2275 mtype
[sizeof(mtype
)-1] = '\0';
2276 if(a
->body
->subtype
){
2277 strncat(mtype
, "/", sizeof(mtype
)-strlen(mtype
)-1);
2278 mtype
[sizeof(mtype
)-1] = '\0';
2279 strncat(mtype
, a
->body
->subtype
, sizeof(mtype
)-strlen(mtype
)-1);
2280 mtype
[sizeof(mtype
)-1] = '\0';
2284 * If we haven't already gotten the filename parameter, get it
2285 * now. It may be used in the temporary filename and possibly
2286 * for its extension.
2288 if(!sender_filename
[0])
2289 (void) get_filename_parameter(sender_filename
, sizeof(sender_filename
),
2292 if(check_mime_type_by_extension(extp
, mtype
)
2293 || (!set_mime_extension_by_type(ext
, mtype
) /* extension from type */
2294 && extp
&& extp
[0])){ /* extension from filename */
2295 strncpy(ext
, extp
, sizeof(ext
));
2296 ext
[sizeof(ext
)-1] = '\0';
2299 /* create a temp file */
2300 if(sender_filename
){
2303 /* get rid of any extension */
2304 if(mt_get_file_ext(sender_filename
, &q
) && q
&& q
> sender_filename
)
2307 /* be careful about what is allowed in the filename */
2308 for(p
= sender_filename
; *p
; p
++)
2309 if(!(isascii((unsigned char) *p
)
2310 && (isalnum((unsigned char) *p
)
2311 || *p
== '-' || *p
== '_' || *p
== '+' || *p
== '.' || *p
== '=')))
2314 if(!*p
) /* filename was ok to use */
2315 snprintf(prefix
, sizeof(prefix
), "img-%s-", sender_filename
);
2318 /* didn't get it yet */
2320 snprintf(prefix
, sizeof(prefix
), "img-%s-", (a
->body
->subtype
)
2321 ? a
->body
->subtype
: "unk");
2324 /* We are creating a temporary name. This is just a prefix. If you
2325 * need the original name, use the save command, so if the prefix
2326 * is too long, shorten it.
2328 if (strlen(prefix
) > 9){
2333 filename
= temp_nam_ext(NULL
, prefix
, ext
);
2336 q_status_message1(SM_ORDER
| SM_DING
, 3, 5,
2337 _("Error \"%s\", Can't create temporary file"),
2338 error_description(errno
));
2342 if((store
= so_get(FileStar
, filename
, WRITE_ACCESS
|OWNER_ONLY
)) == NULL
){
2343 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
2344 _("Error \"%s\", Can't write file %s"),
2345 error_description(errno
), filename
);
2347 our_unlink(filename
);
2348 fs_give((void **)&filename
);
2355 if(a
->body
->size
.bytes
){
2358 snprintf(msg_buf
, sizeof(msg_buf
), "Decoding %s%s%s%s",
2359 a
->description
? "\"" : "",
2360 a
->description
? a
->description
: "attachment number ",
2361 a
->description
? "" : a
->number
,
2362 a
->description
? "\"" : "");
2363 msg_buf
[sizeof(msg_buf
)-1] = '\0';
2364 we_cancel
= init_att_progress(msg_buf
, ps_global
->mail_stream
,
2368 if(a
->body
->type
== TYPEMULTIPART
){
2369 char *h
= mail_fetch_mime(ps_global
->mail_stream
, msgno
, a
->number
,
2372 /* Write to store while converting newlines */
2374 if(*h
== '\015' && *(h
+1) == '\012'){
2375 so_puts(store
, NEWLINE
);
2379 so_writec(*h
++, store
);
2382 gf_set_so_writec(&pc
, store
);
2384 err
= detach(ps_global
->mail_stream
, msgno
, a
->number
, 0L, NULL
, pc
, NULL
, 0);
2386 gf_clear_so_writec(store
);
2394 q_status_message2(SM_ORDER
| SM_DING
, 3, 5,
2395 "%s: Error saving image to temp file %s",
2398 our_unlink(filename
);
2399 fs_give((void **)&filename
);
2405 /*----- Run the viewer process ----*/
2406 run_viewer(filename
, a
->body
, a
->can_display
& MCD_EXT_PROMPT
);
2408 fs_give((void **)&filename
);
2414 /*----------------------------------------------------------------------
2415 Fish the required command from mailcap and run it
2417 Args: image_file -- The name of the file to pass viewer
2418 body -- body struct containing type/subtype of part
2420 A side effect may be that scrolltool is called as well if
2421 exec_mailcap_cmd has any substantial output...
2424 run_viewer(char *image_file
, struct mail_bodystruct
*body
, int chk_extension
)
2426 MCAP_CMD_S
*mc_cmd
= NULL
;
2427 int needs_terminal
= 0, we_cancel
= 0;
2429 we_cancel
= busy_cue("Displaying attachment", NULL
, 0);
2431 if((mc_cmd
= mailcap_build_command(body
->type
, body
->subtype
,
2433 &needs_terminal
, chk_extension
)) != NULL
){
2435 cancel_busy_cue(-1);
2437 exec_mailcap_cmd(mc_cmd
, image_file
, needs_terminal
);
2439 fs_give((void **)&mc_cmd
->command
);
2440 fs_give((void **)&mc_cmd
);
2444 cancel_busy_cue(-1);
2446 q_status_message1(SM_ORDER
, 3, 4, _("Cannot display %s attachment"),
2447 type_desc(body
->type
, body
->subtype
,
2448 body
->parameter
, NULL
, 1));
2453 /*----------------------------------------------------------------------
2454 Detach and provide for browsing a text body part
2456 Args: msgno -- raw message number to get part from
2457 a -- attachment struct for the desired part
2462 format_text_att(long int msgno
, ATTACH_S
*a
, HANDLE_S
**handlesp
)
2467 if((store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) != NULL
){
2469 init_handles(handlesp
);
2471 gf_set_so_writec(&pc
, store
);
2472 (void) decode_text(a
, msgno
, pc
, handlesp
, QStatus
, FM_DISPLAY
);
2473 gf_clear_so_writec(store
);
2480 /*----------------------------------------------------------------------
2481 Detach and provide for browsing a text body part
2483 Args: msgno -- raw message number to get part from
2484 a -- attachment struct for the desired part
2489 display_text_att(long int msgno
, ATTACH_S
*a
, int flags
)
2492 HANDLE_S
*handles
= NULL
;
2496 clear_index_cache_ent(ps_global
->mail_stream
, msgno
, 0);
2498 if((store
= format_text_att(msgno
, a
, &handles
)) != NULL
){
2499 rv
= scroll_attachment("ATTACHED TEXT", store
, CharStar
, handles
, a
, flags
);
2500 free_handles(&handles
);
2501 so_give(&store
); /* free resources associated with store */
2504 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2505 _("Error allocating space for attachment."));
2511 /*----------------------------------------------------------------------
2512 Detach and provide for browsing a body part of type "MESSAGE"
2514 Args: msgno -- message number to get partrom
2515 a -- attachment struct for the desired part
2520 display_msg_att(long int msgno
, ATTACH_S
*a
, int flags
)
2525 HANDLE_S
*handles
= NULL
;
2529 clear_index_cache_ent(ps_global
->mail_stream
, msgno
, 0);
2531 /* BUG, should check this return code */
2532 (void) pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
);
2534 /* initialize a storage object */
2535 if(!(store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
2536 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2537 _("Error allocating space for message."));
2541 gf_set_so_writec(&pc
, store
);
2543 if(format_msg_att(msgno
, &ap
, &handles
, pc
, FM_DISPLAY
)){
2544 if(ps_global
->full_header
== 2)
2545 q_status_message(SM_INFO
, 0, 3,
2546 _("Full header mode ON. All header text being included"));
2548 rv
= scroll_attachment((a
->body
->subtype
2549 && !strucmp(a
->body
->subtype
, "delivery-status"))
2550 ? "DELIVERY STATUS REPORT" : "ATTACHED MESSAGE",
2551 store
, CharStar
, handles
, a
, flags
);
2552 free_handles(&handles
);
2555 gf_clear_so_writec(store
);
2557 so_give(&store
); /* free resources associated with store */
2562 /*----------------------------------------------------------------------
2563 Detach and provide for browsing a multipart body part of type "DIGEST"
2565 Args: msgno -- message number to get partrom
2566 a -- attachment struct for the desired part
2571 display_digest_att(long int msgno
, ATTACH_S
*a
, int flags
)
2575 HANDLE_S
*handles
= NULL
;
2577 SourceType src
= CharStar
;
2581 clear_index_cache_ent(ps_global
->mail_stream
, msgno
, 0);
2583 /* BUG, should check this return code */
2584 (void) pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
);
2586 if(!(store
= so_get(src
, NULL
, EDIT_ACCESS
))){
2587 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2588 _("Error allocating space for message."));
2592 gf_set_so_writec(&pc
, store
);
2595 * While in a subtype of this message
2599 && !strncmp(a
->number
, ap
->number
, strlen(a
->number
))
2602 if(ap
->body
->type
== TYPEMESSAGE
){
2605 if(ap
->body
->subtype
&& strucmp(ap
->body
->subtype
, "rfc822")){
2608 tsub
= cpystr(ap
->body
->subtype
);
2609 convert_possibly_encoded_str_to_utf8((char **) &tsub
);
2610 snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "Unknown Message subtype: %s", tsub
);
2611 tmp_20k_buf
[SIZEOF_20KBUF
-1] = '\0';
2613 if((errstr
= format_editorial(tmp_20k_buf
,
2614 ps_global
->ttyo
->screen_cols
, 0,
2615 NULL
, pc
)) != NULL
){
2616 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
2617 _("Can't format digest: %s"), errstr
);
2620 else if(!gf_puts(NEWLINE
, pc
))
2623 fs_give((void **) &tsub
);
2626 if((errstr
= part_desc(ap
->number
, ap
->body
->nested
.msg
->body
,
2627 0, ps_global
->ttyo
->screen_cols
, FM_DISPLAY
, pc
)) != NULL
){
2628 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
2629 _("Can't format digest: %s"), errstr
);
2632 else if(!format_msg_att(msgno
, &ap
, &handles
, pc
, FM_DISPLAY
))
2636 else if(ap
->body
->type
== TYPETEXT
2637 && decode_text(ap
, msgno
, pc
, NULL
, QStatus
, FM_DISPLAY
))
2639 else if(!gf_puts("Unknown type in Digest", pc
))
2644 if(ps_global
->full_header
== 2)
2645 q_status_message(SM_INFO
, 0, 3,
2646 _("Full header mode ON. All header text being included"));
2648 scroll_attachment(_("ATTACHED MESSAGES"), store
, src
, handles
, a
, flags
);
2651 free_handles(&handles
);
2653 gf_clear_so_writec(store
);
2654 so_give(&store
); /* free resources associated with store */
2659 scroll_attachment(char *title
, STORE_S
*store
, SourceType src
, HANDLE_S
*handles
, ATTACH_S
*a
, int flags
)
2663 memset(&sargs
, 0, sizeof(SCROLL_S
));
2664 sargs
.text
.text
= so_text(store
);
2665 sargs
.text
.src
= src
;
2666 sargs
.text
.desc
= "attachment";
2667 sargs
.text
.handles
= handles
;
2668 sargs
.bar
.title
= title
;
2669 sargs
.proc
.tool
= process_attachment_cmd
;
2670 sargs
.proc
.data
.p
= (void *) a
;
2671 sargs
.help
.text
= h_mail_text_att_view
;
2672 sargs
.help
.title
= _("HELP FOR ATTACHED TEXT VIEW");
2673 sargs
.keys
.menu
= &att_view_keymenu
;
2674 setbitmap(sargs
.keys
.bitmap
);
2676 /* First, fix up "back" key */
2677 if(flags
& DA_FROM_VIEW
){
2678 att_view_keymenu
.keys
[ATV_BACK_KEY
].label
= N_("MsgText");
2681 att_view_keymenu
.keys
[ATV_BACK_KEY
].label
= N_("AttchIndex");
2685 clrbitn(ATV_VIEW_HILITE
, sargs
.keys
.bitmap
);
2686 clrbitn(ATV_PREV_URL
, sargs
.keys
.bitmap
);
2687 clrbitn(ATV_NEXT_URL
, sargs
.keys
.bitmap
);
2690 if(F_OFF(F_ENABLE_PIPE
, ps_global
))
2691 clrbitn(ATV_PIPE_KEY
, sargs
.keys
.bitmap
);
2693 if(!(a
->body
->type
== TYPETEXT
|| MIME_MSG_A(a
) || MIME_DGST_A(a
)))
2694 clrbitn(ATV_PRINT_KEY
, sargs
.keys
.bitmap
);
2697 * If message or digest, leave Reply and Save and,
2698 * conditionally, Bounce on...
2701 if(F_OFF(F_ENABLE_BOUNCE
, ps_global
))
2702 clrbitn(ATV_BOUNCE_KEY
, sargs
.keys
.bitmap
);
2705 clrbitn(ATV_BOUNCE_KEY
, sargs
.keys
.bitmap
);
2706 clrbitn(ATV_REPLY_KEY
, sargs
.keys
.bitmap
);
2707 clrbitn(ATV_EXPORT_KEY
, sargs
.keys
.bitmap
);
2710 if(!(ps_global
->smime
&& ps_global
->smime
->need_passphrase
))
2711 clrbitn(ATV_DECRYPT_KEY
, sargs
.keys
.bitmap
);
2713 if(F_ON(F_DONT_DO_SMIME
, ps_global
) || !MIME_MSG_A(a
)){
2714 clrbitn(ATV_DECRYPT_KEY
, sargs
.keys
.bitmap
);
2715 clrbitn(ATV_SECURITY_KEY
, sargs
.keys
.bitmap
);
2719 sargs
.use_indexline_color
= 1;
2721 if(DA_RESIZE
& flags
)
2722 sargs
.resize_exit
= 1;
2726 sargs
.mouse
.popup
= scroll_att_popup
;
2729 return(scrolltool(&sargs
));
2734 display_smime_info_att(struct pine
*ps
, ATTACH_S
*a
)
2736 if(smime_check(a
->body
->nested
.msg
->body
) == 0){
2737 q_status_message(SM_ORDER
| SM_DING
, 0, 3,
2738 _("Not a signed or encrypted message"));
2742 display_smime_info(ps
, a
->body
->nested
.msg
->env
, a
->body
->nested
.msg
->body
);
2747 process_attachment_cmd(int cmd
, MSGNO_S
*msgmap
, SCROLL_S
*sparms
)
2750 long rawno
= mn_m2raw(msgmap
, mn_get_cur(msgmap
));
2751 #define AD(X) ((ATTACH_S *) (X)->proc.data.p)
2759 ps_global
->next_screen
= quit_screen
;
2763 ps_global
->next_screen
= main_menu_screen
;
2767 reply_msg_att(ps_global
->mail_stream
, rawno
, sparms
->proc
.data
.p
);
2771 forward_attachment(ps_global
->mail_stream
, rawno
, sparms
->proc
.data
.p
);
2775 bounce_msg_att(ps_global
->mail_stream
, rawno
, AD(sparms
)->number
,
2776 AD(sparms
)->body
->nested
.msg
->env
->subject
);
2777 ps_global
->mangled_footer
= 1;
2781 delete_attachment(rawno
, sparms
->proc
.data
.p
);
2785 if(undelete_attachment(rawno
, sparms
->proc
.data
.p
, &n
))
2786 q_status_message1(SM_ORDER
, 0, 3,
2787 "Part %s UNdeleted", AD(sparms
)->number
);
2792 save_attachment(-FOOTER_ROWS(ps_global
), rawno
, sparms
->proc
.data
.p
);
2793 ps_global
->mangled_footer
= 1;
2797 export_attachment(-FOOTER_ROWS(ps_global
), rawno
, sparms
->proc
.data
.p
);
2798 ps_global
->mangled_footer
= 1;
2802 print_attachment(-FOOTER_ROWS(ps_global
), rawno
, sparms
->proc
.data
.p
);
2803 ps_global
->mangled_footer
= 1;
2807 pipe_attachment(rawno
, sparms
->proc
.data
.p
);
2808 ps_global
->mangled_footer
= 1;
2812 ps_global
->full_header
++;
2813 if(ps_global
->full_header
== 1){
2814 if(!(ps_global
->quote_suppression_threshold
2815 && (ps_global
->some_quoting_was_suppressed
/* || in_index != View*/)))
2816 ps_global
->full_header
++;
2818 else if(ps_global
->full_header
> 2)
2819 ps_global
->full_header
= 0;
2821 switch(ps_global
->full_header
){
2823 q_status_message(SM_ORDER
, 0, 3,
2824 _("Display of full headers is now off."));
2828 q_status_message1(SM_ORDER
, 0, 3,
2829 _("Quotes displayed, use %s to see full headers"),
2830 F_ON(F_USE_FK
, ps_global
) ? "F9" : "H");
2834 q_status_message(SM_ORDER
, 0, 3,
2835 _("Display of full headers is now on."));
2845 if(ps_global
->smime
&& ps_global
->smime
->need_passphrase
)
2846 smime_get_passphrase();
2850 display_smime_info_att(ps_global
, sparms
->proc
.data
.p
);
2855 alpine_panic("Unexpected command case");
2864 * Returns 1 on success, 0 on error.
2867 format_msg_att(long int msgno
, ATTACH_S
**a
, HANDLE_S
**handlesp
, gf_io_t pc
, int flags
)
2871 if((*a
)->body
->type
!= TYPEMESSAGE
)
2872 return(gf_puts("[ Undisplayed Attachment of Type ", pc
)
2873 && gf_puts(body_type_names((*a
)->body
->type
), pc
)
2874 && gf_puts(" ]", pc
) && gf_puts(NEWLINE
, pc
));
2876 if((*a
)->body
->subtype
&& strucmp((*a
)->body
->subtype
, "rfc822") == 0){
2879 HD_INIT(&h
, ps_global
->VAR_VIEW_HEADERS
, ps_global
->view_all_except
,
2881 switch(format_header(ps_global
->mail_stream
, msgno
, (*a
)->number
,
2882 (*a
)->body
->nested
.msg
->env
, &h
, NULL
, NULL
,
2884 case -1 : /* write error */
2887 case 1 : /* fetch error */
2888 if(!(gf_puts("[ Error fetching header ]", pc
)
2889 && !gf_puts(NEWLINE
, pc
)))
2895 gf_puts(NEWLINE
, pc
);
2897 if(((*a
)+1)->description
)
2900 if(!(gf_puts("[Can't display missing text segment]", pc
)
2901 && gf_puts(NEWLINE
, pc
)))
2907 if((*a
)->body
&& (*a
)->body
->subtype
&& (strucmp((*a
)->body
->subtype
, OUR_PKCS7_ENCLOSURE_SUBTYPE
)==0)){
2908 if((*a
)->description
){
2909 if(!(!format_editorial((*a
)->description
,
2910 ps_global
->ttyo
->screen_cols
,
2912 && gf_puts(NEWLINE
, pc
) && gf_puts(NEWLINE
, pc
)))
2916 if(((*a
)+1)->description
)
2919 if(!(gf_puts("[Can't display missing text segment]", pc
)
2920 && gf_puts(NEWLINE
, pc
)))
2927 if(((*a
))->description
2928 && (*a
)->body
&& (*a
)->body
->type
== TYPETEXT
){
2929 if(decode_text(*a
, msgno
, pc
, NULL
, QStatus
, flags
))
2932 else if(!(gf_puts("[Can't display ", pc
)
2933 && gf_puts(((*a
)->description
&& (*a
)->body
)
2934 ? "first non-" : "missing ", pc
)
2935 && gf_puts("text segment]", pc
)
2936 && gf_puts(NEWLINE
, pc
)))
2939 if(((*a
)+1)->description
)
2942 if(!(gf_puts("[Can't display missing text segment]", pc
)
2943 && gf_puts(NEWLINE
, pc
)))
2949 else if((*a
)->body
->subtype
2950 && strucmp((*a
)->body
->subtype
, "external-body") == 0) {
2951 if(format_editorial("This part is not included and can be fetched as follows:",
2952 ps_global
->ttyo
->screen_cols
, flags
, NULL
, pc
)
2953 || !gf_puts(NEWLINE
, pc
)
2954 || format_editorial(display_parameters((*a
)->body
->parameter
),
2955 ps_global
->ttyo
->screen_cols
, flags
, handlesp
, pc
))
2958 else if(decode_text(*a
, msgno
, pc
, NULL
, QStatus
, flags
))
2966 display_vcard_att(long int msgno
, ATTACH_S
*a
, int flags
)
2968 STORE_S
*in_store
, *out_store
= NULL
;
2969 HANDLE_S
*handles
= NULL
;
2972 char **lines
, **ll
, *errstr
= NULL
, tmp
[MAILTMPLEN
], *p
;
2973 int cmd
= MC_RESIZE
, indent
, begins
= 0;
2975 lines
= detach_vcard_att(ps_global
->mail_stream
,
2976 msgno
, a
->body
, a
->number
);
2978 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2979 _("Error accessing attachment."));
2983 if(!(in_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
2984 free_list_array(&lines
);
2985 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
2986 _("Error allocating space for attachment."));
2990 for(ll
= lines
, indent
= 0; ll
&& *ll
; ll
++)
2991 if((p
= strindex(*ll
, ':')) && p
- *ll
> indent
)
2995 for(ll
= lines
; ll
&& *ll
; ll
++){
2996 if((p
= strindex(*ll
, ':')) != NULL
){
2997 if(begins
< 2 && struncmp(*ll
, "begin:", 6) == 0)
3000 snprintf(tmp
, sizeof(tmp
), " %-*.*s : ", indent
- 5,
3001 (int) MIN(p
- *ll
, sizeof(tmp
)-5), *ll
);
3002 tmp
[sizeof(tmp
)-1] = '\0';
3003 so_puts(in_store
, tmp
);
3008 so_puts(in_store
, repeat_char(indent
, SPACE
));
3011 snprintf(tmp
, sizeof(tmp
), "%.200s", p
);
3012 tmp
[sizeof(tmp
)-1] = '\0';
3014 (char *)rfc1522_decode_to_utf8((unsigned char *)tmp_20k_buf
,
3015 SIZEOF_20KBUF
, tmp
));
3016 so_puts(in_store
, "\015\012");
3019 free_list_array(&lines
);
3021 so_puts(in_store
, "\015\012\015\012");
3024 if((out_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) != NULL
){
3025 so_seek(in_store
, 0L, 0);
3027 init_handles(&handles
);
3030 if(F_ON(F_VIEW_SEL_URL
, ps_global
)
3031 || F_ON(F_VIEW_SEL_URL_HOST
, ps_global
)
3032 || F_ON(F_SCAN_ADDR
, ps_global
))
3033 gf_link_filter(gf_line_test
,
3034 gf_line_test_opt(url_hilite
,
3035 gf_url_hilite_opt(&uh
,&handles
,0)));
3037 gf_link_filter(gf_wrap
,
3038 gf_wrap_filter_opt(ps_global
->ttyo
->screen_cols
- 4,
3039 ps_global
->ttyo
->screen_cols
,
3040 NULL
, indent
, GFW_HANDLES
));
3041 gf_link_filter(gf_nvtnl_local
, NULL
);
3043 gf_set_so_readc(&gc
, in_store
);
3044 gf_set_so_writec(&pc
, out_store
);
3046 errstr
= gf_pipe(gc
, pc
);
3048 gf_clear_so_readc(in_store
);
3051 #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.")
3052 #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.")
3053 errstr
= format_editorial((begins
> 1)
3054 ? VCARD_TEXT_MORE
: VCARD_TEXT_ONE
,
3055 ps_global
->ttyo
->screen_cols
, 0, NULL
, pc
);
3058 gf_clear_so_writec(out_store
);
3061 cmd
= scroll_attachment(_("ADDRESS BOOK ATTACHMENT"), out_store
,
3062 CharStar
, handles
, a
, flags
| DA_RESIZE
);
3064 free_handles(&handles
);
3065 so_give(&out_store
);
3068 errstr
= _("Error allocating space");
3070 while(!errstr
&& (cmd
== MC_RESIZE
|| cmd
== MC_FULLHDR
));
3073 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
3074 _("Can't format entry : %s"), errstr
);
3080 display_vevent_summary(long int msgno
, ATTACH_S
*a
, int flags
, int depth
)
3083 VCALENDAR_S
*vcal
= NULL
;
3084 char *b64text
, *caltext
;
3085 unsigned long callen
;
3086 VEVENT_SUMMARY_S
*vesy
, *vsummary
; /* vevent summary */
3087 STORE_S
*in_store
, *out_store
= NULL
;
3088 HANDLE_S
*handles
= NULL
;
3091 char *errstr
= NULL
;
3094 b
= mail_body(ps_global
->mail_stream
, msgno
, (unsigned char *) a
->number
);
3095 if(b
->sparep
== NULL
){
3096 b64text
= mail_fetch_body(ps_global
->mail_stream
, msgno
, a
->number
, &callen
, 0);
3097 b64text
[callen
] = '\0'; /* chop off cookie */
3098 caltext
= rfc822_base64((unsigned char *)b64text
, strlen(b64text
), &callen
);
3099 vcal
= ical_parse_text(caltext
);
3100 b
->sparep
= create_body_sparep(iCalType
, (void *) vcal
);
3102 else if(get_body_sparep_type(b
->sparep
) == iCalType
)
3103 vcal
= (VCALENDAR_S
*) get_body_sparep_data(b
->sparep
);
3105 vsummary
= ical_vevent_summary(vcal
);
3107 if(vsummary
== NULL
){
3108 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
3109 _("Error parsing event"));
3113 if(!(in_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
3114 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
3115 _("Error allocating space to process Calendar"));
3119 gf_set_so_readc(&gc
, in_store
);
3121 for(vesy
= vsummary
, k
= 0; vesy
; vesy
= vesy
->next
, k
++){
3122 if(depth
>= 0 && k
!= depth
)
3126 so_puts(in_store
, _("This event was cancelled"));
3127 so_puts(in_store
, "\015\012");
3131 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%d %s",
3132 _("Priority: "), vesy
->priority
,
3133 vesy
->priority
== 5 ? _("(Normal)")
3134 : (vesy
->priority
< 5 ? _("(High)")
3136 so_puts(in_store
, tmp_20k_buf
);
3137 so_puts(in_store
, "\015\012");
3141 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3142 _("Summary: "), vesy
->summary
);
3143 so_puts(in_store
, tmp_20k_buf
);
3144 so_puts(in_store
, "\015\012");
3148 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3149 _("Sender: "), vesy
->sender
);
3150 so_puts(in_store
, tmp_20k_buf
);
3151 so_puts(in_store
, "\015\012");
3154 if(vesy
->organizer
){
3155 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3156 _("Organizer: "), vesy
->organizer
);
3157 so_puts(in_store
, tmp_20k_buf
);
3158 so_puts(in_store
, "\015\012");
3162 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3163 _("Location: "), vesy
->location
);
3164 so_puts(in_store
, tmp_20k_buf
);
3165 so_puts(in_store
, "\015\012");
3169 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3170 _("Start Date: "), vesy
->evstart
);
3171 so_puts(in_store
, tmp_20k_buf
);
3172 so_puts(in_store
, "\015\012");
3176 for(i
= 0; vesy
->duration
[i
] != NULL
; i
++){
3177 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3178 _("Duration: "), vesy
->duration
[i
]);
3179 so_puts(in_store
, tmp_20k_buf
);
3180 so_puts(in_store
, "\015\012");
3182 } else if(vesy
->evend
){
3183 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3184 _("End Date: "), vesy
->evend
);
3185 so_puts(in_store
, tmp_20k_buf
);
3186 so_puts(in_store
, "\015\012");
3190 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
, "%s%s",
3191 vcal
->method
? _("Created on: ") : _("Last Revised on; "),
3193 so_puts(in_store
, tmp_20k_buf
);
3194 so_puts(in_store
, "\015\012");
3197 if(vesy
->description
){
3201 so_puts(in_store
, "\015\012");
3202 so_puts(in_store
, _("Description: "));
3204 /* Check if empty description */
3206 for(j
= 0; empty
== 1 && vesy
->description
[j
] != '\0'; j
++){
3207 c
= vesy
->description
[j
];
3208 if(c
!= '\n' && c
!= ' ' && c
!= '\t')
3212 so_puts(in_store
, _("[ No description provided ]"));
3213 so_puts(in_store
, "\015\012");
3216 for(j
=0; vesy
->description
[j
] != '\0'; j
++){
3217 c
= vesy
->description
[j
];
3219 so_puts(in_store
, "\015\012");
3222 so_writec(c
, in_store
);
3225 so_puts(in_store
, "\015\012");
3229 so_puts(in_store
, "\015\012");
3230 so_puts(in_store
, _("List of Attendees:"));
3231 so_puts(in_store
, "\015\012");
3232 for(i
= 0; vesy
->attendee
[i
] != NULL
; i
++){
3233 so_puts(in_store
, vesy
->attendee
[i
]);
3234 so_puts(in_store
, "\015\012");
3236 so_puts(in_store
, "\015\012");
3239 utf8_snprintf(tmp_20k_buf
, SIZEOF_20KBUF
,
3240 _("This event was tagged as a %s entry by the sender"), vesy
->class);
3241 so_puts(in_store
, tmp_20k_buf
);
3242 so_puts(in_store
, "\015\012\015\012");
3244 if(depth
< 0 && vesy
->next
){
3245 for(i
= 0; i
< ps_global
->ttyo
->screen_cols
&& i
< 40; i
++)
3246 tmp_20k_buf
[i
] = '-';
3247 tmp_20k_buf
[i
]= '\0';
3248 so_puts(in_store
, tmp_20k_buf
);
3249 so_puts(in_store
, "\015\012");
3251 } /* end "for" loop */
3254 so_seek(in_store
, 0L, 0);
3255 if((out_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) == NULL
){
3256 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
3257 _("Error allocating space to write Calendar"));
3261 gf_set_so_writec(&pc
, out_store
);
3263 init_handles(&handles
);
3266 if(F_ON(F_VIEW_SEL_URL
, ps_global
)
3267 || F_ON(F_VIEW_SEL_URL_HOST
, ps_global
)
3268 || F_ON(F_SCAN_ADDR
, ps_global
))
3269 gf_link_filter(gf_line_test
,
3270 gf_line_test_opt(url_hilite
,
3271 gf_url_hilite_opt(&uh
,&handles
,0)));
3273 gf_link_filter(gf_wrap
,
3274 gf_wrap_filter_opt(ps_global
->ttyo
->screen_cols
- 4,
3275 ps_global
->ttyo
->screen_cols
,
3276 NULL
, 0, GFW_HANDLES
));
3277 gf_link_filter(gf_nvtnl_local
, NULL
);
3279 gf_set_so_readc(&gc
, in_store
);
3280 gf_set_so_writec(&pc
, out_store
);
3282 errstr
= gf_pipe(gc
, pc
);
3284 gf_clear_so_readc(in_store
);
3286 gf_clear_so_writec(out_store
);
3289 cmd
= scroll_attachment(_("CALENDAR EVENT ATTACHMENT"), out_store
,
3290 CharStar
, handles
, a
, flags
| DA_RESIZE
);
3292 free_handles(&handles
);
3293 so_give(&out_store
);
3295 while(!errstr
&& (cmd
== MC_RESIZE
|| cmd
== MC_FULLHDR
));
3298 q_status_message1(SM_ORDER
| SM_DING
, 3, 3,
3299 _("Can't format entry : %s"), errstr
);
3301 free_vevent_summary(&vsummary
);
3302 ps_global
->mangled_screen
= 1;
3307 display_vcalendar_att(long int msgno
, ATTACH_S
*a
, int flags
)
3309 display_vevent_summary(msgno
, a
, flags
, -1);
3313 /*----------------------------------------------------------------------
3314 Display attachment information
3316 Args: msgno -- message number to get partrom
3317 a -- attachment struct for the desired part
3319 Result: a screen containing information about attachment:
3322 display_attach_info(long int msgno
, ATTACH_S
*a
)
3324 int i
, indent
, cols
;
3325 char buf1
[100], *folded
;
3330 (void) dispatch_attachment(a
);
3332 if(!(store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
3333 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
3334 _("Error allocating space for message."));
3338 cols
= ps_global
->ttyo
->screen_cols
;
3342 * 16 for text (longest is Display Method == 14)
3347 /* don't try stupid folding */
3348 cols
= MAX(indent
+10, cols
);
3350 so_puts(store
, "Details about Attachment #");
3351 so_puts(store
, a
->number
);
3352 so_puts(store
, " :\n\n");
3353 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Type");
3354 so_puts(store
, buf1
);
3355 so_puts(store
, body_type_names(a
->body
->type
));
3356 so_puts(store
, "\n");
3357 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Subtype");
3358 so_puts(store
, buf1
);
3359 so_puts(store
, a
->body
->subtype
? a
->body
->subtype
: "Unknown");
3360 so_puts(store
, "\n");
3361 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Encoding");
3362 so_puts(store
, buf1
);
3363 so_puts(store
, a
->body
->encoding
< ENCMAX
3364 ? body_encodings
[a
->body
->encoding
]
3366 so_puts(store
, "\n");
3367 if((plist
= rfc2231_newparmlist(a
->body
->parameter
)) != NULL
){
3368 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Parameters");
3369 so_puts(store
, buf1
);
3371 while(rfc2231_list_params(plist
)){
3373 so_puts(store
, repeat_char(indent
, ' '));
3375 so_puts(store
, plist
->attrib
);
3376 so_puts(store
, " = ");
3377 so_puts(store
, plist
->value
? plist
->value
: "");
3378 so_puts(store
, "\n");
3381 rfc2231_free_parmlist(&plist
);
3384 if(a
->body
->description
&& a
->body
->description
[0]){
3385 char buftmp
[MAILTMPLEN
];
3388 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Description");
3390 snprintf(buftmp
, sizeof(buftmp
), "%s", a
->body
->description
);
3391 buftmp
[sizeof(buftmp
)-1] = '\0';
3392 q
= rfc1522_decode_to_utf8((unsigned char *)tmp_20k_buf
, SIZEOF_20KBUF
, buftmp
);
3393 folded
= fold((char *) q
, cols
, cols
, buf1
, repeat_char(indent
+1, ' '), FLD_NONE
);
3396 so_puts(store
, folded
);
3397 fs_give((void **) &folded
);
3401 /* BUG: no a->body->language support */
3403 if(a
->body
->disposition
.type
){
3404 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Disposition");
3405 so_puts(store
, buf1
);
3406 so_puts(store
, a
->body
->disposition
.type
);
3407 so_puts(store
, "\n");
3408 if((plist
= rfc2231_newparmlist(a
->body
->disposition
.parameter
)) != NULL
){
3409 while(rfc2231_list_params(plist
)){
3410 so_puts(store
, repeat_char(indent
, ' '));
3411 so_puts(store
, plist
->attrib
);
3412 so_puts(store
, " = ");
3413 so_puts(store
, plist
->value
? plist
->value
: "");
3414 so_puts(store
, "\n");
3417 rfc2231_free_parmlist(&plist
);
3421 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Approx. Size");
3422 so_puts(store
, buf1
);
3423 so_puts(store
, comatose((a
->body
->encoding
== ENCBASE64
)
3424 ? ((a
->body
->size
.bytes
* 3)/4)
3425 : a
->body
->size
.bytes
));
3426 so_puts(store
, " bytes\n");
3427 utf8_snprintf(buf1
, sizeof(buf1
), " %-*.*w: ", indent
-4, indent
-4, "Display Method");
3428 so_puts(store
, buf1
);
3429 if(a
->can_display
== MCD_NONE
) {
3430 so_puts(store
, "Can't, ");
3431 so_puts(store
, (a
->body
->encoding
< ENCOTHER
)
3432 ? "Unknown Attachment Format"
3433 : "Unknown Encoding");
3435 else if(!(a
->can_display
& MCD_EXTERNAL
)){
3436 so_puts(store
, "Alpine's Internal Pager");
3439 int nt
, free_pretty_cmd
;
3443 if((mc_cmd
= mailcap_build_command(a
->body
->type
, a
->body
->subtype
,
3444 a
->body
, "<datafile>", &nt
,
3445 a
->can_display
& MCD_EXT_PROMPT
)) != NULL
){
3446 so_puts(store
, "\"");
3447 if((pretty_cmd
= execview_pretty_command(mc_cmd
, &free_pretty_cmd
)) != NULL
)
3448 so_puts(store
, pretty_cmd
);
3449 so_puts(store
, "\"");
3450 if(free_pretty_cmd
&& pretty_cmd
)
3451 fs_give((void **)&pretty_cmd
);
3453 fs_give((void **)&mc_cmd
->command
);
3454 fs_give((void **)&mc_cmd
);
3458 so_puts(store
, "\n");
3460 memset(&sargs
, 0, sizeof(SCROLL_S
));
3461 sargs
.text
.text
= so_text(store
);
3462 sargs
.text
.src
= CharStar
;
3463 sargs
.text
.desc
= "attachment info";
3464 sargs
.bar
.title
= _("ABOUT ATTACHMENT");
3465 sargs
.help
.text
= h_simple_text_view
;
3466 sargs
.help
.title
= _("HELP FOR \"ABOUT ATTACHMENT\"");
3468 sargs
.use_indexline_color
= 1;
3472 so_give(&store
); /* free resources associated with store */
3473 ps_global
->mangled_screen
= 1;
3477 /*----------------------------------------------------------------------
3481 forward_attachment(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
)
3489 forward_msg_att(stream
, msgno
, a
);
3492 ACTION_S
*role
= NULL
;
3493 REDRAFT_POS_S
*redraft_pos
= NULL
;
3494 long rflags
= ROLE_FORWARD
;
3497 outgoing
= mail_newenvelope();
3498 outgoing
->subject
= cpystr("Forwarded attachment...");
3500 if(nonempty_patterns(rflags
, &dummy
)){
3502 * There is no message, but a Current Folder Type might match.
3504 * This has been changed to check against the message
3505 * containing the attachment.
3507 role
= set_role_from_msg(ps_global
, ROLE_FORWARD
, msgno
, NULL
);
3508 if(confirm_role(rflags
, &role
))
3509 role
= combine_inherited_role(role
);
3512 cmd_cancelled("Forward");
3513 mail_free_envelope(&outgoing
);
3519 q_status_message1(SM_ORDER
, 3, 4,
3520 _("Forwarding using role \"%s\""), role
->nick
);
3522 outgoing
->message_id
= generate_message_id(role
);
3524 * as with all text bound for the composer, build it in
3525 * a storage object of the type it understands...
3527 if((msgtext
= (void *) so_get(PicoText
, NULL
, EDIT_ACCESS
)) != NULL
){
3528 int impl
, template_len
= 0;
3530 if(role
&& role
->template){
3534 filtered
= detoken(role
, NULL
, 0, 0, 0, &redraft_pos
, &impl
);
3537 so_puts((STORE_S
*)msgtext
, filtered
);
3539 template_len
= strlen(filtered
);
3542 fs_give((void **)&filtered
);
3548 if((sig
= detoken(role
, NULL
, 2, 0, 1, &redraft_pos
, &impl
)) != NULL
){
3550 redraft_pos
->offset
+= template_len
;
3552 so_puts((STORE_S
*)msgtext
, *sig
? sig
: NEWLINE
);
3554 fs_give((void **)&sig
);
3557 so_puts((STORE_S
*)msgtext
, NEWLINE
);
3559 /*---- New Body to start with ----*/
3560 body
= mail_newbody();
3561 body
->type
= TYPEMULTIPART
;
3563 /*---- The TEXT part/body ----*/
3564 body
->nested
.part
= mail_newbody_part();
3565 body
->nested
.part
->body
.type
= TYPETEXT
;
3566 body
->nested
.part
->body
.contents
.text
.data
= msgtext
;
3568 /*---- The corresponding things we're attaching ----*/
3569 body
->nested
.part
->next
= mail_newbody_part();
3570 body
->nested
.part
->next
->body
.id
= generate_message_id(role
);
3571 copy_body(&body
->nested
.part
->next
->body
, a
->body
);
3573 if(fetch_contents(stream
, msgno
, a
->number
,
3574 &body
->nested
.part
->next
->body
)){
3575 pine_send(outgoing
, &body
, "FORWARD MESSAGE",
3576 role
, NULL
, NULL
, redraft_pos
, NULL
, NULL
, 0);
3578 ps_global
->mangled_screen
= 1;
3579 pine_free_body(&body
);
3580 free_redraft_pos(&redraft_pos
);
3583 mail_free_body(&body
);
3584 so_give((STORE_S
**) &msgtext
);
3585 free_redraft_pos(&redraft_pos
);
3586 q_status_message(SM_ORDER
| SM_DING
, 4, 5,
3587 _("Error fetching message contents. Can't forward message."));
3591 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3592 _("Error allocating message text"));
3594 mail_free_envelope(&outgoing
);
3601 forward_msg_att(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
)
3603 char *p
, *sig
= NULL
;
3608 ACTION_S
*role
= NULL
;
3610 REDRAFT_POS_S
*redraft_pos
= NULL
;
3612 outgoing
= mail_newenvelope();
3613 memset((void *)&reply
, 0, sizeof(reply
));
3615 if((outgoing
->subject
= forward_subject(a
->body
->nested
.msg
->env
, 0)) != NULL
){
3617 * as with all text bound for the composer, build it in
3618 * a storage object of the type it understands...
3620 if((msgtext
= (void *) so_get(PicoText
, NULL
, EDIT_ACCESS
)) != NULL
){
3621 int impl
, template_len
= 0;
3622 long rflags
= ROLE_FORWARD
;
3626 if(ps_global
->full_header
== 2)
3627 ret
= want_to(_("Forward message as an attachment"), 'n', 0,
3628 NO_HELP
, WT_SEQ_SENSITIVE
);
3629 /* Setup possible role */
3630 if(nonempty_patterns(rflags
, &dummy
)){
3631 role
= set_role_from_msg(ps_global
, rflags
, msgno
, a
->number
);
3632 if(confirm_role(rflags
, &role
))
3633 role
= combine_inherited_role(role
);
3634 else{ /* cancel reply */
3636 cmd_cancelled("Forward");
3637 mail_free_envelope(&outgoing
);
3638 so_give((STORE_S
**) &msgtext
);
3644 q_status_message1(SM_ORDER
, 3, 4,
3645 _("Forwarding using role \"%s\""), role
->nick
);
3647 outgoing
->message_id
= generate_message_id(role
);
3649 if(role
&& role
->template){
3653 filtered
= detoken(role
, a
->body
->nested
.msg
->env
,
3654 0, 0, 0, &redraft_pos
, &impl
);
3657 so_puts((STORE_S
*)msgtext
, filtered
);
3659 template_len
= strlen(filtered
);
3662 fs_give((void **)&filtered
);
3668 if((sig
= detoken(role
, a
->body
->nested
.msg
->env
,
3669 2, 0, 1, &redraft_pos
, &impl
)) != NULL
){
3671 redraft_pos
->offset
+= template_len
;
3673 so_puts((STORE_S
*)msgtext
, *sig
? sig
: NEWLINE
);
3675 fs_give((void **)&sig
);
3678 so_puts((STORE_S
*)msgtext
, NEWLINE
);
3681 /*---- New Body to start with ----*/
3682 body
= mail_newbody();
3683 body
->type
= TYPEMULTIPART
;
3685 /*---- The TEXT part/body ----*/
3686 body
->nested
.part
= mail_newbody_part();
3687 body
->nested
.part
->body
.type
= TYPETEXT
;
3688 body
->nested
.part
->body
.contents
.text
.data
= msgtext
;
3690 if(!forward_mime_msg(stream
, msgno
,
3691 p
= body_partno(stream
, msgno
, a
->body
),
3692 a
->body
->nested
.msg
->env
,
3693 &body
->nested
.part
->next
, msgtext
))
3694 mail_free_body(&body
);
3698 if(a
->body
->nested
.msg
->body
){
3702 = parameter_val(a
->body
->nested
.msg
->body
->parameter
,
3705 if(charset
&& strucmp(charset
, "us-ascii") != 0){
3709 * There is a non-ascii charset,
3710 * is there conversion happening?
3712 if(!(ct
=conversion_table(charset
, ps_global
->posting_charmap
))
3714 reply
.orig_charset
= charset
;
3720 fs_give((void **) &charset
);
3723 body
= forward_body(stream
, a
->body
->nested
.msg
->env
,
3724 a
->body
->nested
.msg
->body
, msgno
,
3725 p
= body_partno(stream
, msgno
, a
->body
),
3729 fs_give((void **) &p
);
3732 pine_send(outgoing
, &body
,
3735 reply
.forw
? &reply
: NULL
,
3736 redraft_pos
, NULL
, NULL
, 0);
3738 ps_global
->mangled_screen
= 1;
3739 pine_free_body(&body
);
3740 free_redraft_pos(&redraft_pos
);
3744 so_give((STORE_S
**) &msgtext
);
3745 q_status_message(SM_ORDER
| SM_DING
, 4, 5,
3746 _("Error fetching message contents. Can't forward message."));
3750 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3751 _("Error allocating message text"));
3754 q_status_message1(SM_ORDER
,3,4,
3755 _("Error fetching message %s. Can't forward it."),
3756 long2string(msgno
));
3758 if(reply
.orig_charset
)
3759 fs_give((void **)&reply
.orig_charset
);
3761 mail_free_envelope(&outgoing
);
3766 reply_msg_att(MAILSTREAM
*stream
, long int msgno
, ATTACH_S
*a
)
3768 ADDRESS
*saved_from
, *saved_to
, *saved_cc
, *saved_resent
;
3772 char *tp
, *prefix
= NULL
, *fcc
= NULL
, *errmsg
= NULL
;
3773 int include_text
= 0, flags
= RSF_QUERY_REPLY_ALL
;
3774 int rolemsg
= 0, copytomsg
= 0;
3777 REDRAFT_POS_S
*redraft_pos
= NULL
;
3778 ACTION_S
*role
= NULL
;
3780 outgoing
= mail_newenvelope();
3782 dprint((4,"\n - attachment reply \n"));
3784 saved_from
= (ADDRESS
*) NULL
;
3785 saved_to
= (ADDRESS
*) NULL
;
3786 saved_cc
= (ADDRESS
*) NULL
;
3787 saved_resent
= (ADDRESS
*) NULL
;
3788 outgoing
->subject
= NULL
;
3790 prefix
= reply_quote_str(a
->body
->nested
.msg
->env
);
3792 * For consistency, the first question is always "include text?"
3794 if((include_text
= reply_text_query(ps_global
, 1, NULL
, &prefix
)) >= 0
3795 && reply_news_test(a
->body
->nested
.msg
->env
, outgoing
) > 0
3796 && reply_harvest(ps_global
, msgno
, a
->number
,
3797 a
->body
->nested
.msg
->env
, &saved_from
,
3798 &saved_to
, &saved_cc
, &saved_resent
, &flags
)){
3799 outgoing
->subject
= reply_subject(a
->body
->nested
.msg
->env
->subject
,
3802 reply_seed(ps_global
, outgoing
, a
->body
->nested
.msg
->env
,
3803 saved_from
, saved_to
, saved_cc
, saved_resent
,
3804 &fcc
, flags
& RSF_FORCE_REPLY_ALL
, &errmsg
);
3807 q_status_message1(SM_ORDER
, 3, 3, "%.200s", errmsg
);
3808 display_message(NO_OP_COMMAND
);
3811 fs_give((void **)&errmsg
);
3814 if(sp_expunge_count(stream
)) /* current msg was expunged */
3817 /* Setup possible role */
3818 rflags
= ROLE_REPLY
;
3819 if(nonempty_patterns(rflags
, &dummy
)){
3820 role
= set_role_from_msg(ps_global
, rflags
, msgno
, a
->number
);
3821 if(confirm_role(rflags
, &role
))
3822 role
= combine_inherited_role(role
);
3823 else{ /* cancel reply */
3825 cmd_cancelled("Reply");
3833 /* override fcc gotten in reply_seed */
3834 if(role
->fcc
&& fcc
)
3835 fs_give((void **) &fcc
);
3838 if(F_ON(F_COPY_TO_TO_FROM
, ps_global
) && !(role
&& role
->from
)){
3839 ADDRESS
*us_in_to_and_cc
, *ap
;
3841 us_in_to_and_cc
= (ADDRESS
*) NULL
;
3842 if(a
->body
->nested
.msg
->env
&& a
->body
->nested
.msg
->env
->to
)
3843 if((ap
=reply_cp_addr(ps_global
, 0L, NULL
,
3844 NULL
, us_in_to_and_cc
, NULL
,
3845 a
->body
->nested
.msg
->env
->to
, RCA_ONLY_US
)) != NULL
)
3846 reply_append_addr(&us_in_to_and_cc
, ap
);
3848 if(a
->body
->nested
.msg
->env
&& a
->body
->nested
.msg
->env
->cc
)
3849 if((ap
=reply_cp_addr(ps_global
, 0L, NULL
,
3850 NULL
, us_in_to_and_cc
, NULL
,
3851 a
->body
->nested
.msg
->env
->cc
, RCA_ONLY_US
)) != NULL
)
3852 reply_append_addr(&us_in_to_and_cc
, ap
);
3855 * A list of all of our addresses that appear in the To
3856 * and cc fields is in us_in_to_and_cc.
3857 * If there is exactly one address in that list then
3858 * use it for the outgoing From.
3860 if(us_in_to_and_cc
&& !us_in_to_and_cc
->next
){
3861 PINEFIELD
*custom
, *pf
;
3866 * Check to see if this address is different from what
3867 * we would have used anyway. If it is, notify the user
3868 * with a status message. This is pretty hokey because we're
3869 * mimicking how pine_send would set the From address and
3870 * there is no coordination between the two.
3873 /* in case user has a custom From value */
3874 custom
= parse_custom_hdrs(ps_global
->VAR_CUSTOM_HDRS
, UseAsDef
);
3876 pf
= (PINEFIELD
*) fs_get(sizeof(*pf
));
3877 memset((void *) pf
, 0, sizeof(*pf
));
3878 pf
->name
= cpystr("From");
3880 if(set_default_hdrval(pf
, custom
) >= UseAsDef
3881 && pf
->textbuf
&& pf
->textbuf
[0]){
3882 removing_trailing_white_space(pf
->textbuf
);
3883 (void)removing_double_quotes(pf
->textbuf
);
3884 build_address(pf
->textbuf
, &addr
, NULL
, NULL
, NULL
);
3885 rfc822_parse_adrlist(pf
->addr
, addr
, ps_global
->maildomain
);
3887 fs_give((void **) &addr
);
3891 *pf
->addr
= generate_from();
3893 if(*pf
->addr
&& !address_is_same(*pf
->addr
, us_in_to_and_cc
)){
3896 role
= (ACTION_S
*) fs_get(sizeof(*role
));
3897 memset((void *) role
, 0, sizeof(*role
));
3898 role
->is_a_role
= 1;
3901 role
->from
= us_in_to_and_cc
;
3902 us_in_to_and_cc
= NULL
;
3905 free_customs(custom
);
3910 mail_free_address(&us_in_to_and_cc
);
3915 if(rolemsg
&& copytomsg
)
3916 q_status_message1(SM_ORDER
, 3, 4,
3917 _("Replying using role \"%s\" and To as From"), role
->nick
);
3919 q_status_message1(SM_ORDER
, 3, 4,
3920 _("Replying using role \"%s\""), role
->nick
);
3922 q_status_message(SM_ORDER
, 3, 4,
3923 _("Replying using incoming To as outgoing From"));
3926 outgoing
->in_reply_to
= reply_in_reply_to(a
->body
->nested
.msg
->env
);
3927 outgoing
->references
= reply_build_refs(a
->body
->nested
.msg
->env
);
3928 outgoing
->message_id
= generate_message_id(role
);
3930 if(!outgoing
->to
&& !outgoing
->cc
3931 && !outgoing
->bcc
&& !outgoing
->newsgroups
)
3932 q_status_message(SM_ORDER
| SM_DING
, 3, 6,
3933 _("Warning: no valid addresses to reply to!"));
3936 * Now fix up the body...
3938 if((msgtext
= (void *) so_get(PicoText
, NULL
, EDIT_ACCESS
)) != NULL
){
3941 memset((void *)&reply
, 0, sizeof(reply
));
3943 if(a
->body
->nested
.msg
->body
){
3947 = parameter_val(a
->body
->nested
.msg
->body
->parameter
,
3950 if(charset
&& strucmp(charset
, "us-ascii") != 0){
3954 * There is a non-ascii charset,
3955 * is there conversion happening?
3957 if(!(ct
=conversion_table(charset
, ps_global
->posting_charmap
))
3959 reply
.orig_charset
= charset
;
3965 fs_give((void **) &charset
);
3968 if((body
= reply_body(stream
, a
->body
->nested
.msg
->env
,
3969 a
->body
->nested
.msg
->body
, msgno
,
3970 tp
= body_partno(stream
, msgno
, a
->body
),
3971 msgtext
, prefix
, include_text
, role
,
3972 1, &redraft_pos
)) != NULL
){
3973 /* partially formatted outgoing message */
3974 pine_send(outgoing
, &body
, "COMPOSE MESSAGE REPLY",
3975 role
, fcc
, &reply
, redraft_pos
, NULL
, NULL
, 0);
3977 pine_free_body(&body
);
3978 ps_global
->mangled_screen
= 1;
3981 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3982 _("Error building message body"));
3984 fs_give((void **) &tp
);
3985 if(reply
.orig_charset
)
3986 fs_give((void **)&reply
.orig_charset
);
3989 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
3990 _("Error allocating message text"));
3994 mail_free_envelope(&outgoing
);
3995 mail_free_address(&saved_from
);
3996 mail_free_address(&saved_to
);
3997 mail_free_address(&saved_cc
);
3998 mail_free_address(&saved_resent
);
4001 fs_give((void **) &prefix
);
4004 fs_give((void **) &fcc
);
4006 free_redraft_pos(&redraft_pos
);
4012 bounce_msg_att(MAILSTREAM
*stream
, long int msgno
, char *part
, char *subject
)
4016 if((errstr
= bounce_msg(stream
, msgno
, part
, NULL
, NULL
, subject
, NULL
, NULL
)) != NULL
)
4017 q_status_message(SM_ORDER
| SM_DING
, 3, 3, errstr
);
4022 pipe_attachment(long int msgno
, ATTACH_S
*a
)
4024 char *err
, *resultfilename
= NULL
, prompt
[80], *p
;
4025 int rc
, capture
= 1, raw
= 0, we_cancel
= 0, j
= 0;
4029 char pipe_command
[MAXPATH
+1];
4030 unsigned flagsforhist
= 1; /* raw=2 /capture=1 */
4031 static HISTORY_S
*history
= NULL
;
4032 ESCKEY_S pipe_opt
[6];
4034 if(ps_global
->restricted
){
4035 q_status_message(SM_ORDER
| SM_DING
, 0, 4,
4036 "Alpine demo can't pipe attachments");
4041 pipe_command
[0] = '\0';
4043 init_hist(&history
, HISTSIZE
);
4044 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
4045 if((p
= get_prev_hist(history
, "", flagsforhist
, NULL
)) != NULL
){
4046 strncpy(pipe_command
, p
, sizeof(pipe_command
));
4047 pipe_command
[sizeof(pipe_command
)-1] = '\0';
4048 if(history
->hist
[history
->curindex
]){
4049 flagsforhist
= history
->hist
[history
->curindex
]->flags
;
4050 raw
= (flagsforhist
& 0x2) ? 1 : 0;
4051 capture
= (flagsforhist
& 0x1) ? 1 : 0;
4056 pipe_opt
[j
].rval
= 0;
4057 pipe_opt
[j
].name
= "";
4058 pipe_opt
[j
++].label
= "";
4060 pipe_opt
[j
].ch
= ctrl('W');
4061 pipe_opt
[j
].rval
= 10;
4062 pipe_opt
[j
].name
= "^W";
4063 pipe_opt
[j
++].label
= NULL
;
4065 pipe_opt
[j
].ch
= ctrl('Y');
4066 pipe_opt
[j
].rval
= 11;
4067 pipe_opt
[j
].name
= "^Y";
4068 pipe_opt
[j
++].label
= NULL
;
4070 pipe_opt
[j
].ch
= KEY_UP
;
4071 pipe_opt
[j
].rval
= 30;
4072 pipe_opt
[j
].name
= "";
4074 pipe_opt
[j
++].label
= "";
4076 pipe_opt
[j
].ch
= KEY_DOWN
;
4077 pipe_opt
[j
].rval
= 31;
4078 pipe_opt
[j
].name
= "";
4079 pipe_opt
[j
++].label
= "";
4081 pipe_opt
[j
].ch
= -1;
4086 snprintf(prompt
, sizeof(prompt
), "Pipe %sattachment %s to %s: ", raw
? "RAW " : "",
4087 a
->number
, capture
? "" : "(Free Output) ");
4088 prompt
[sizeof(prompt
)-1] = '\0';
4089 pipe_opt
[1].label
= raw
? "DecodedData" : "Raw Data";
4090 pipe_opt
[2].label
= capture
? "Free Output" : "Capture Output";
4093 * 2 is really 1 because there will be one real entry and
4094 * one entry of "" because of the get_prev_hist above.
4096 if(items_in_hist(history
) > 2){
4097 pipe_opt
[ku
].name
= HISTORY_UP_KEYNAME
;
4098 pipe_opt
[ku
].label
= HISTORY_KEYLABEL
;
4099 pipe_opt
[ku
+1].name
= HISTORY_DOWN_KEYNAME
;
4100 pipe_opt
[ku
+1].label
= HISTORY_KEYLABEL
;
4103 pipe_opt
[ku
].name
= "";
4104 pipe_opt
[ku
].label
= "";
4105 pipe_opt
[ku
+1].name
= "";
4106 pipe_opt
[ku
+1].label
= "";
4109 flags
= OE_APPEND_CURRENT
| OE_SEQ_SENSITIVE
;
4110 rc
= optionally_enter(pipe_command
, -FOOTER_ROWS(ps_global
), 0,
4111 sizeof(pipe_command
), prompt
,
4112 pipe_opt
, help
, &flags
);
4114 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
4115 "Internal problem encountered");
4119 raw
= !raw
; /* flip raw text */
4122 capture
= !capture
; /* flip capture output */
4125 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
4126 if((p
= get_prev_hist(history
, pipe_command
, flagsforhist
, NULL
)) != NULL
){
4127 strncpy(pipe_command
, p
, sizeof(pipe_command
));
4128 pipe_command
[sizeof(pipe_command
)-1] = '\0';
4129 if(history
->hist
[history
->curindex
]){
4130 flagsforhist
= history
->hist
[history
->curindex
]->flags
;
4131 raw
= (flagsforhist
& 0x2) ? 1 : 0;
4132 capture
= (flagsforhist
& 0x1) ? 1 : 0;
4139 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
4140 if((p
= get_next_hist(history
, pipe_command
, flagsforhist
, NULL
)) != NULL
){
4141 strncpy(pipe_command
, p
, sizeof(pipe_command
));
4142 pipe_command
[sizeof(pipe_command
)-1] = '\0';
4143 if(history
->hist
[history
->curindex
]){
4144 flagsforhist
= history
->hist
[history
->curindex
]->flags
;
4145 raw
= (flagsforhist
& 0x2) ? 1 : 0;
4146 capture
= (flagsforhist
& 0x1) ? 1 : 0;
4153 if(pipe_command
[0] == '\0'){
4154 cmd_cancelled("Pipe command");
4158 flagsforhist
= (raw
? 0x2 : 0) + (capture
? 0x1 : 0);
4159 save_hist(history
, pipe_command
, flagsforhist
, NULL
);
4161 flags
= PIPE_USER
| PIPE_WRITE
| PIPE_STDERR
;
4162 flags
|= (raw
? PIPE_RAW
: 0);
4168 ps_global
->mangled_screen
= 1;
4170 flags
|= PIPE_RESET
;
4173 if((syspipe
= open_system_pipe(pipe_command
,
4174 (flags
&PIPE_RESET
) ? NULL
: &resultfilename
,
4175 NULL
, flags
, 0, pipe_callback
, pipe_report_error
)) != NULL
){
4177 gf_io_t pc
; /* wire up a generic putchar */
4179 is_text
= (a
&& a
->body
&& a
->body
->type
== TYPETEXT
);
4181 gf_set_writec(&pc
, syspipe
, 0L, PipeStar
,
4182 (is_text
&& !raw
) ? WRITE_TO_LOCALE
: 0);
4184 /*------ Write the image to a temporary file ------*/
4185 if(raw
){ /* pipe raw text */
4186 FETCH_READC_S fetch_part
;
4191 we_cancel
= busy_cue(NULL
, NULL
, 1);
4196 fetch_readc_init(&fetch_part
, ps_global
->mail_stream
,
4197 msgno
, a
->number
, a
->body
->size
.bytes
, 0, 0);
4198 gf_link_filter(gf_nvtnl_local
, NULL
);
4199 err
= gf_pipe(FETCH_READC
, pc
);
4209 /* BUG: there's got to be a better way */
4211 ps_global
->print
= (PRINT_S
*) 1;
4214 err
= detach(ps_global
->mail_stream
, msgno
,
4215 a
->number
, 0L, (long *)NULL
, pc
, NULL
, 0);
4216 ps_global
->print
= (PRINT_S
*) NULL
;
4220 (void) close_system_pipe(&syspipe
, NULL
, pipe_callback
);
4223 q_status_message1(SM_ORDER
| SM_DING
, 3, 4,
4224 _("Error detaching for pipe: %s"), err
);
4226 display_output_file(resultfilename
,
4228 ? _("PIPE ATTACHMENT (ERROR)")
4229 : _("PIPE ATTACHMENT"),
4232 fs_give((void **) &resultfilename
);
4235 q_status_message(SM_ORDER
| SM_DING
, 3, 4,
4236 _("Error opening pipe"));
4241 cmd_cancelled("Pipe");
4245 help
= (help
== NO_HELP
) ? h_pipe_attach
: NO_HELP
;
4251 delete_attachment(long int msgno
, ATTACH_S
*a
)
4253 int expbits
, rv
= 0;
4255 if(!msgno_exceptions(ps_global
->mail_stream
, msgno
,
4256 a
->number
, &expbits
, FALSE
)
4257 || !(expbits
& MSG_EX_DELETE
)){
4258 expbits
|= MSG_EX_DELETE
;
4259 msgno_exceptions(ps_global
->mail_stream
, msgno
,
4260 a
->number
, &expbits
, TRUE
);
4262 q_status_message1(SM_ORDER
, 0, 3,
4263 _("Part %s will be omitted only if message is Saved"),
4268 q_status_message1(SM_ORDER
, 0, 3, _("Part %s already deleted"),
4276 undelete_attachment(long int msgno
, ATTACH_S
*a
, int *expbitsp
)
4280 if(msgno_exceptions(ps_global
->mail_stream
, msgno
,
4281 a
->number
, expbitsp
, FALSE
)
4282 && ((*expbitsp
) & MSG_EX_DELETE
)){
4283 (*expbitsp
) ^= MSG_EX_DELETE
;
4284 msgno_exceptions(ps_global
->mail_stream
, msgno
,
4285 a
->number
, expbitsp
, TRUE
);
4289 q_status_message1(SM_ORDER
, 0, 3, _("Part %s already UNdeleted"),
4296 /*----------------------------------------------------------------------
4297 Resolve any deferred tests for attachment displayability
4299 Args: attachment structure
4301 Returns: undefer's attachment's displayability test
4304 dispatch_attachment(ATTACH_S
*a
)
4306 if(a
->test_deferred
){
4307 a
->test_deferred
= 0;
4308 a
->can_display
= mime_can_display(a
->body
->type
, a
->body
->subtype
, a
->body
);
4311 return(a
->can_display
);
4317 scroll_att_popup(sparms
, in_handle
)
4321 MPopup scrat_popup
[20];
4325 scrat_popup
[++i
].type
= tIndex
;
4326 scrat_popup
[i
].label
.style
= lNormal
;
4327 scrat_popup
[i
].label
.string
= "View Selectable Item";
4328 scrat_popup
[i
].data
.val
= ctrl('L');
4331 scrat_popup
[++i
].type
= tQueue
;
4332 scrat_popup
[i
].label
.style
= lNormal
;
4333 scrat_popup
[i
].label
.string
= "&Save";
4334 scrat_popup
[i
].data
.val
= 'S';
4336 scrat_popup
[++i
].type
= tQueue
;
4337 scrat_popup
[i
].label
.style
= lNormal
;
4338 if(msgno_exceptions(ps_global
->mail_stream
,
4339 mn_m2raw(ps_global
->msgmap
,
4340 mn_get_cur(ps_global
->msgmap
)),
4341 scrat_attachp
->number
, &n
, FALSE
)
4342 && (n
& MSG_EX_DELETE
)){
4343 scrat_popup
[i
].label
.string
= "&Undelete";
4344 scrat_popup
[i
].data
.val
= 'U';
4347 scrat_popup
[i
].label
.string
= "&Delete";
4348 scrat_popup
[i
].data
.val
= 'D';
4351 if(MIME_MSG_A(scrat_attachp
) || MIME_DGST_A(scrat_attachp
)){
4352 scrat_popup
[++i
].type
= tQueue
;
4353 scrat_popup
[i
].label
.style
= lNormal
;
4354 scrat_popup
[i
].label
.string
= "&Reply";
4355 scrat_popup
[i
].data
.val
= 'R';
4357 scrat_popup
[++i
].type
= tQueue
;
4358 scrat_popup
[i
].label
.style
= lNormal
;
4359 scrat_popup
[i
].label
.string
= "&Forward";
4360 scrat_popup
[i
].data
.val
= 'f';
4363 scrat_popup
[++i
].type
= tSeparator
;
4365 scrat_popup
[++i
].type
= tQueue
;
4366 scrat_popup
[i
].label
.style
= lNormal
;
4367 scrat_popup
[i
].label
.string
= "Attachment Index";
4368 scrat_popup
[i
].data
.val
= '<';
4370 scrat_popup
[++i
].type
= tTail
;
4372 return(mswin_popup(scrat_popup
) == 0 && in_handle
);
4377 display_att_window(a
)
4380 #if !defined(DOS) && !defined(OS2)
4384 if(a
->body
->type
== TYPEMULTIPART
){
4385 if(a
->body
->subtype
){
4386 /* if(!strucmp(a->body->subtype, "digest"))
4387 display_digest_att(msgno, a, flags);
4389 q_status_message1(SM_ORDER
, 3, 5,
4390 "Can't display Multipart/%s",
4394 q_status_message(SM_ORDER
, 3, 5,
4395 "Can't display unknown Multipart Subtype");
4397 /* else if(MIME_VCARD_A(a))
4398 display_vcard_att_window(msgno, a, flags);*/
4399 else if(a
->body
->type
== TYPETEXT
)
4400 display_text_att_window(a
);
4401 else if(a
->body
->type
== TYPEMESSAGE
)
4402 display_msg_att_window(a
);
4407 display_text_att_window(a
)
4413 msgno
= mn_m2raw(ps_global
->msgmap
, mn_get_cur(ps_global
->msgmap
));
4415 if(store
= format_text_att(msgno
, a
, NULL
)){
4416 if (mswin_displaytext("ATTACHED TEXT",
4418 strlen((char *) so_text(store
)),
4419 NULL
, NULL
, 0) >= 0)
4420 store
->txt
= (void *) NULL
; /* free'd in mswin_displaytext */
4422 so_give(&store
); /* free resources associated with store */
4425 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
4426 "Error allocating space for attachment.");
4431 display_msg_att_window(a
)
4439 msgno
= mn_m2raw(ps_global
->msgmap
, mn_get_cur(ps_global
->msgmap
));
4441 /* BUG, should check this return code */
4442 (void) pine_mail_fetchstructure(ps_global
->mail_stream
, msgno
, NULL
);
4444 /* initialize a storage object */
4445 if(store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)){
4447 gf_set_so_writec(&pc
, store
);
4449 if(format_msg_att(msgno
, &ap
, NULL
, pc
, FM_DISPLAY
)
4450 && mswin_displaytext("ATTACHED MESSAGE", so_text(store
),
4451 strlen((char *) so_text(store
)),
4452 NULL
, NULL
, 0) >= 0)
4453 /* free'd in mswin_displaytext */
4454 store
->txt
= (void *) NULL
;
4456 gf_clear_so_writec(store
);
4461 q_status_message(SM_ORDER
| SM_DING
, 3, 3,
4462 "Error allocating space for message.");