2 * ========================================================================
3 * Copyright 2006-2008 University of Washington
4 * Copyright 2013-2022 Eduardo Chappa
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 * ========================================================================
21 #include "../pith/msgno.h"
22 #include "../pith/filter.h"
23 #include "../pith/util.h"
24 #include "../pith/conf.h"
25 #include "../pith/tempfile.h"
26 #include "../pith/margin.h"
32 int rd_answer_forge_warning(int, MSGNO_S
*, SCROLL_S
*);
36 rd_prompt_about_forged_remote_data(int reason
, REMDATA_S
*rd
, char *extra
)
39 char *unknown
= "<unknown>";
41 char *foldertype
, *foldername
, *special
;
43 foldertype
= (rd
&& rd
->t
.i
.special_hdr
&& !strucmp(rd
->t
.i
.special_hdr
, REMOTE_ABOOK_SUBTYPE
)) ? "address book" : (rd
&& rd
->t
.i
.special_hdr
&& !strucmp(rd
->t
.i
.special_hdr
, REMOTE_PINERC_SUBTYPE
)) ? "configuration" : "data";
44 foldername
= (rd
&& rd
->rn
) ? rd
->rn
: unknown
;
45 special
= (rd
&& rd
->t
.i
.special_hdr
) ? rd
->t
.i
.special_hdr
: unknown
;
49 dprint((1, "rd_check_out_forged_remote_data:\n"));
50 dprint((1, " reason=%d\n", reason
));
51 dprint((1, " folder_type=%s\n", foldertype
? foldertype
: "?"));
52 dprint((1, " remotename=%s\n\n", foldername
? foldername
: "?"));
54 if(rd
&& rd
->flags
& USER_SAID_NO
)
58 dprint((1, "The special header \"%s\" is missing from the last message in the folder.\nThis indicates that something is wrong.\nYou should probably answer \"No\"\nso that you don't use the corrupt data.\nThen you should investigate further.\n", special
? special
: "?"));
60 else if(reason
== -1){
61 dprint((1, "The last message in the folder contains \"Received\" headers.\nThis usually indicates that the message was put there by the mail\ndelivery system. Alpine does not add those Received headers.\nYou should probably answer \"No\" so that you don't use the corrupt data.\nThen you should investigate further.\n"));
64 dprint((1, "The special header \"%s\" in the last message\nin the folder has an unexpected value (%s)\nafter it. This could indicate that something is wrong.\nThis value should not normally be put there by Alpine.\nHowever, since there are no Received lines in the message we choose to\nbelieve that everything is ok and we will proceed.\n",
65 special
? special
: "?", (extra
&& *extra
) ? extra
: "?"));
68 dprint((1, "The special header \"%s\" in the last message\nin the folder has an unexpected value (1)\nafter it. It appears that it may have been put there by an Pine\nwith a version number less than 4.50.\nSince there are no Received lines in the message we choose to believe that\nthe header was added by an old Pine and we will proceed.\n",
69 special
? special
: "?"));
72 dprint((1, "The special header \"%s\" in the last message\nin the folder has an unexpected value (%s)\nafter it. This is the right sort of value that Alpine would normally put there,\nbut it doesn't match the value from the first message in the folder.\nThis may indicate that something is wrong.\nHowever, since there are no Received lines in the message we choose to\nbelieve that everything is ok and we will proceed.\n",
73 special
? special
: "?", (extra
&& *extra
) ? extra
: "?"));
78 * This check should not really be here. We have a cookie that
79 * has the wrong value so something is possibly wrong.
80 * But we are worried that old pines will put the bad value in
81 * there (which they will) and then the questions will bother
82 * users and mystify them. So we're just going to pretend the user
83 * said Yes in this case, and we'll try to fix the cookie.
84 * We still catch Received lines and use that or the complete absence
85 * of a special header as indicators of trouble.
87 rd
->flags
|= USER_SAID_YES
;
93 STORE_S
*in_store
, *out_store
;
95 HANDLE_S
*handles
= NULL
;
98 if(!(in_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)) ||
99 !(out_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
)))
102 /* TRANSLATORS: the first %s is the folder type, it may be address book or
103 configuration. The second %s is the folder name. Of course, the HTML
104 tags should be left as is. */
105 snprintf(tmp
, sizeof(tmp
), _("<HTML><P>The data in the remote %s folder<P><CENTER>%s</CENTER><P>looks suspicious. The reason for the suspicion is<P><CENTER>"),
106 foldertype
, foldername
);
107 tmp
[sizeof(tmp
)-1] = '\0';
108 so_puts(in_store
, tmp
);
111 snprintf(tmp
, sizeof(tmp
), _("header \"%s\" is missing</CENTER><P>The special header \"%s\" is missing from the last message in the folder. This indicates that something is wrong. You should probably answer \"No\" so that you don't use the corrupt data. Then you should investigate further."),
113 tmp
[sizeof(tmp
)-1] = '\0';
114 so_puts(in_store
, tmp
);
116 else if(reason
== -1){
117 so_puts(in_store
, _("\"Received\" headers detected</CENTER><P>The last message in the folder contains \"Received\" headers. This usually indicates that the message was put there by the mail delivery system. Alpine does not add those Received headers. You should probably answer \"No\" so that you don't use the corrupt data. Then you should investigate further."));
119 else if(reason
== 0){
120 snprintf(tmp
, sizeof(tmp
), _("Unexpected value for header \"%s\"</CENTER><P>The special header \"%s\" in the last message in the folder has an unexpected value (%s) after it. This probably indicates that something is wrong. This value would not normally be put there by Alpine. You should probably answer \"No\" so that you don't use the corrupt data. Then you should investigate further."),
121 special
, special
, (extra
&& *extra
) ? extra
: "?");
122 tmp
[sizeof(tmp
)-1] = '\0';
123 so_puts(in_store
, tmp
);
125 else if(reason
== 1){
126 snprintf(tmp
, sizeof(tmp
), _("Unexpected value for header \"%s\"</CENTER><P>The special header \"%s\" in the last message in the folder has an unexpected value (1) after it. It appears that it may have been put there by a Pine with a version number less than 4.50. If you believe that you have changed this data with an older Pine more recently than you've changed it with this version of Alpine, then you can probably safely answer \"Yes\". If you do not understand why this has happened, you should probably answer \"No\" so that you don't use the corrupt data. Then you should investigate further."),
128 tmp
[sizeof(tmp
)-1] = '\0';
129 so_puts(in_store
, tmp
);
132 snprintf(tmp
, sizeof(tmp
), _("Unexpected value for header \"%s\"</CENTER><P>The special header \"%s\" in the last message in the folder has an unexpected value (%s) after it. This is the right sort of value that Alpine would normally put there, but it doesn't match the value from the first message in the folder. This may indicate that something is wrong. Unless you understand why this has happened, you should probably answer \"No\" so that you don't use the corrupt data. Then you should investigate further."),
133 special
, special
, (extra
&& *extra
) ? extra
: "?");
134 tmp
[sizeof(tmp
)-1] = '\0';
135 so_puts(in_store
, tmp
);
138 so_seek(in_store
, 0L, 0);
139 init_handles(&handles
);
141 gf_link_filter(gf_html2plain
,
142 gf_html2plain_opt(NULL
,
143 ps_global
->ttyo
->screen_cols
, non_messageview_margin(),
144 &handles
, NULL
, GFHP_LOCAL_HANDLES
));
145 gf_set_so_readc(&gc
, in_store
);
146 gf_set_so_writec(&pc
, out_store
);
148 gf_clear_so_writec(out_store
);
149 gf_clear_so_readc(in_store
);
151 memset(&sargs
, 0, sizeof(SCROLL_S
));
152 sargs
.text
.handles
= handles
;
153 sargs
.text
.text
= so_text(out_store
);
154 sargs
.text
.src
= CharStar
;
155 sargs
.bar
.title
= _("REMOTE DATA FORGERY WARNING");
156 sargs
.proc
.tool
= rd_answer_forge_warning
;
157 sargs
.proc
.data
.p
= (void *)&the_answer
;
158 sargs
.keys
.menu
= &forge_keymenu
;
159 setbitmap(sargs
.keys
.bitmap
);
163 if(the_answer
== 'y'){
165 rd
->flags
|= USER_SAID_YES
;
168 rd
->flags
|= USER_SAID_NO
;
170 ps_global
->mangled_screen
= 1;
171 ps_global
->painted_body_on_startup
= 0;
172 ps_global
->painted_footer_on_startup
= 0;
175 free_handles(&handles
);
178 snprintf(p
, sizeof(tmp
), _("\nThe data in the remote %s folder\n\n %s\n\nlooks suspicious. The reason for the suspicion is\n\n "),
179 foldertype
, foldername
);
180 tmp
[sizeof(tmp
)-1] = '\0';
184 snprintf(p
, sizeof(tmp
)-(p
-tmp
), _("header \"%s\" is missing\n\nThe special header \"%s\" is missing from the last message\nin the folder. This indicates that something is wrong.\nYou should probably answer \"No\" so that you don't use the corrupt data.\nThen you should investigate further.\n\n"),
186 tmp
[sizeof(tmp
)-1] = '\0';
188 else if(reason
== -1){
189 snprintf(p
, sizeof(tmp
)-(p
-tmp
), _("\"Received\" headers detected\n\nThe last message in the folder contains \"Received\" headers.\nThis usually indicates that the message was put there by the\nmail delivery system. Alpine does not add those Received headers.\nYou should probably answer \"No\" so that you don't use the corrupt data.\nThen you should investigate further.\n\n"));
190 tmp
[sizeof(tmp
)-1] = '\0';
192 else if(reason
== 0){
193 snprintf(p
, sizeof(tmp
)-(p
-tmp
), _("Unexpected value for header \"%s\"\n\nThe special header \"%s\" in the last message in the folder\nhas an unexpected value (%s) after it. This probably\nindicates that something is wrong. This value would not normally be put\nthere by Alpine. You should probably answer \"No\" so that you don't use\nthe corrupt data. Then you should investigate further.\n\n"),
194 special
, special
, (extra
&& *extra
) ? extra
: "?");
195 tmp
[sizeof(tmp
)-1] = '\0';
197 else if(reason
== 1){
198 snprintf(p
, sizeof(tmp
)-(p
-tmp
), _("Unexpected value for header \"%s\"\n\nThe special header \"%s\" in the last message in the folder\nhas an unexpected value (1) after it. It appears that it may have been\nput there by a Pine with a version number less than 4.50.\nIf you believe that you have changed this data with an older Pine more\nrecently than you've changed it with this version of Alpine, then you can\nprobably safely answer \"Yes\". If you do not understand why this has\nhappened, you should probably answer \"No\" so that you don't use the\ncorrupt data. Then you should investigate further.\n\n"),
200 tmp
[sizeof(tmp
)-1] = '\0';
203 snprintf(p
, sizeof(tmp
)-(p
-tmp
), _("Unexpected value for header \"%s\"\n\nThe special header \"%s\" in the last message in the folder\nhas an unexpected\nvalue (%s) after it. This is\nthe right sort of value that Alpine would normally put there, but it\ndoesn't match the value from the first message in the folder. This may\nindicate that something is wrong. Unless you understand why this has happened,\nyou should probably answer \"No\" so that you don't use the\ncorrupt data. Then you should investigate further.\n\n"),
204 special
, special
, (extra
&& *extra
) ? extra
: "?");
205 tmp
[sizeof(tmp
)-1] = '\0';
210 snprintf(p
, sizeof(tmp
)-(p
-tmp
), _("Suspicious data in \"%s\": Continue anyway "),
211 (rd
&& rd
->t
.i
.special_hdr
) ? rd
->t
.i
.special_hdr
213 tmp
[sizeof(tmp
)-1] = '\0';
214 if(want_to(tmp
, 'n', 'x', NO_HELP
, WT_NORM
) == 'y'){
216 rd
->flags
|= USER_SAID_YES
;
219 rd
->flags
|= USER_SAID_NO
;
223 q_status_message1(SM_ORDER
, 1, 3, _("Can't open remote %s"),
224 (rd
&& rd
->rn
) ? rd
->rn
: "<noname>");
231 rd_answer_forge_warning(int cmd
, MSGNO_S
*msgmap
, SCROLL_S
*sparms
)
235 ps_global
->next_screen
= SCREEN_FUN_NULL
;
239 *(int *)(sparms
->proc
.data
.p
) = 'y';
243 *(int *)(sparms
->proc
.data
.p
) = 'n';
247 alpine_panic("Unexpected command in rd_answer_forge_warning");
257 rd_metadata_name(void)
259 char *p
, *q
, *metafile
;
260 char path
[MAXPATH
], pinerc_dir
[MAXPATH
];
261 struct variable
*vars
= ps_global
->vars
;
263 dprint((9, "rd_metadata_name\n"));
265 pinerc_dir
[0] = '\0';
266 if(ps_global
->pinerc
){
267 char *prcn
= ps_global
->pinerc
;
270 if((lc
= last_cmpnt(prcn
)) != NULL
){
273 to_copy
= (lc
- prcn
> 1) ? (lc
- prcn
- 1) : 1;
274 strncpy(pinerc_dir
, prcn
, MIN(to_copy
, sizeof(pinerc_dir
)-1));
275 pinerc_dir
[MIN(to_copy
, sizeof(pinerc_dir
)-1)] = '\0';
279 pinerc_dir
[1] = '\0';
284 * If there is no metadata file specified in the pinerc, create a filename.
286 if(!(VAR_REMOTE_ABOOK_METADATA
&& VAR_REMOTE_ABOOK_METADATA
[0])){
287 if(pinerc_dir
[0] && (p
= tempfile_in_same_dir(ps_global
->pinerc
,
288 meta_prefix
, NULL
))){
289 /* fill in the pinerc variable */
290 q
= p
+ strlen(pinerc_dir
) + 1;
291 set_variable(V_REMOTE_ABOOK_METADATA
, q
, 1, 0, Main
);
292 dprint((2, "creating name for metadata file: %s\n",
295 /* something's broken, return NULL rab */
296 if(!VAR_REMOTE_ABOOK_METADATA
|| !VAR_REMOTE_ABOOK_METADATA
[0]){
298 fs_give((void **)&p
);
302 fs_give((void **)&p
);
305 q_status_message(SM_ORDER
, 3, 5,
306 "can't create metadata file in pinerc directory, continuing");
311 build_path(path
, pinerc_dir
? pinerc_dir
: NULL
,
312 VAR_REMOTE_ABOOK_METADATA
, sizeof(path
));
316 * If the metadata file doesn't exist, create it.
318 if(can_access(metafile
, ACCESS_EXISTS
) != 0){
321 if((fd
= our_open(metafile
, O_CREAT
|O_EXCL
|O_WRONLY
|O_BINARY
, 0600)) < 0){
323 set_variable(V_REMOTE_ABOOK_METADATA
, NULL
, 1, 0, Main
);
325 q_status_message2(SM_ORDER
, 3, 5,
326 "can't create cache file %.200s, continuing (%.200s)",
327 metafile
, error_description(errno
));
329 dprint((2, "can't create metafile %s: %s\n",
330 metafile
? metafile
: "?", error_description(errno
)));
335 dprint((2, "created metadata file: %s\n",
336 metafile
? metafile
: "?"));
341 return(cpystr(metafile
));;