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 Implements the Pine state management routines
21 #include "../pith/headers.h"
22 #include "../pith/state.h"
23 #include "../pith/conf.h"
24 #include "../pith/init.h"
25 #include "../pith/sort.h"
26 #include "../pith/atttype.h"
27 #include "../pith/util.h"
28 #include "../pith/mailindx.h"
29 #include "../pith/remote.h"
30 #include "../pith/list.h"
31 #include "../pith/smime.h"
32 #include "../pith/ical.h"
33 #include "../pith/bldaddr.h"
36 * Globals referenced throughout pine...
38 struct pine
*ps_global
; /* THE global variable! */
42 * Debug level and output file defined here, referenced globally.
43 * The debug file is opened and initialized below...
45 int debug
= DEFAULT_DEBUG
;
49 /*----------------------------------------------------------------------
50 General use big buffer. It is used in the following places:
51 compose_mail: while parsing header of postponed message
52 append_message2: while writing header into folder
53 q_status_messageX: while doing printf formatting
54 addr_book: Used to return expanded address in. (Can only use here
55 because mm_log doesn't q_status on PARSE errors !)
56 alpine.c: When address specified on command line
57 init.c: When expanding variable values
61 char tmp_20k_buf
[SIZEOF_20KBUF
];
65 * new_pine_struct - allocate and fill in with default values a new pine struct
72 p
= (struct pine
*)fs_get(sizeof (struct pine
));
73 memset((void *) p
, 0, sizeof(struct pine
));
74 p
->def_sort
= SortArrival
;
75 p
->sort_types
[0] = SortSubject
;
76 p
->sort_types
[1] = SortArrival
;
77 p
->sort_types
[2] = SortFrom
;
78 p
->sort_types
[3] = SortTo
;
79 p
->sort_types
[4] = SortCc
;
80 p
->sort_types
[5] = SortDate
;
81 p
->sort_types
[6] = SortSize
;
82 p
->sort_types
[7] = SortSubject2
;
83 p
->sort_types
[8] = SortScore
;
84 p
->sort_types
[9] = SortThread
;
85 p
->sort_types
[10] = EndofList
;
88 * We need to have access to p->smime even before calling
89 * smime_init() so that we can set do_encrypt and do_sign.
91 p
->smime
= new_smime_struct();
93 p
->atmts
= (ATTACH_S
*) fs_get(sizeof(ATTACH_S
));
94 p
->atmts_allocated
= 1;
95 p
->atmts
->description
= NULL
;
98 /* msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
107 * free_pine_struct -- free up allocated data in pine struct and then the
111 free_pine_struct(struct pine
**pps
)
116 if((*pps
)->free_initial_cmds
!= NULL
)
117 fs_give((void **) &(*pps
)->free_initial_cmds
);
119 if((*pps
)->id
!= NULL
)
120 mail_free_idlist(&(*pps
)->id
);
122 if((*pps
)->hostname
!= NULL
)
123 fs_give((void **)&(*pps
)->hostname
);
125 if((*pps
)->localdomain
!= NULL
)
126 fs_give((void **)&(*pps
)->localdomain
);
128 if((*pps
)->ttyo
!= NULL
)
129 fs_give((void **)&(*pps
)->ttyo
);
131 if((*pps
)->home_dir
!= NULL
)
132 fs_give((void **)&(*pps
)->home_dir
);
134 if((*pps
)->folders_dir
!= NULL
)
135 fs_give((void **)&(*pps
)->folders_dir
);
137 if((*pps
)->html_dir
!= NULL
)
138 fs_give((void **)&(*pps
)->html_dir
);
140 if((*pps
)->html_dir_list
!= NULL
)
141 free_html_log(&(*pps
)->html_dir_list
);
143 if((*pps
)->ui
.homedir
)
144 fs_give((void **)&(*pps
)->ui
.homedir
);
147 fs_give((void **)&(*pps
)->ui
.login
);
149 if((*pps
)->ui
.fullname
)
150 fs_give((void **)&(*pps
)->ui
.fullname
);
152 free_index_format(&(*pps
)->index_disp_format
);
154 if((*pps
)->conv_table
){
155 if((*pps
)->conv_table
->table
)
156 fs_give((void **) &(*pps
)->conv_table
->table
);
158 if((*pps
)->conv_table
->from_charset
)
159 fs_give((void **) &(*pps
)->conv_table
->from_charset
);
161 if((*pps
)->conv_table
->to_charset
)
162 fs_give((void **) &(*pps
)->conv_table
->to_charset
);
164 fs_give((void **)&(*pps
)->conv_table
);
168 fs_give((void **)&(*pps
)->pinerc
);
170 #if defined(DOS) || defined(OS2)
172 fs_give((void **)&(*pps
)->pine_dir
);
174 if((*pps
)->aux_files_dir
)
175 fs_give((void **)&(*pps
)->aux_files_dir
);
178 if((*pps
)->display_charmap
)
179 fs_give((void **)&(*pps
)->display_charmap
);
181 if((*pps
)->keyboard_charmap
)
182 fs_give((void **)&(*pps
)->keyboard_charmap
);
184 if((*pps
)->posting_charmap
)
185 fs_give((void **)&(*pps
)->posting_charmap
);
188 if((*pps
)->pwdcertdir
)
189 fs_give((void **)&(*pps
)->pwdcertdir
);
194 pc
= (PERSONAL_CERT
*) (*pps
)->pwdcert
;
195 free_personal_certs(&pc
);
196 (*pps
)->pwdcert
= NULL
;
199 if((*pps
)->pwdcertlist
){
202 cert
= (CertList
*) (*pps
)->pwdcertlist
;
203 free_certlist(&cert
);
204 (*pps
)->pwdcertlist
= NULL
;
207 if((*pps
)->backuppassword
){
210 cert
= (CertList
*) (*pps
)->backuppassword
;
211 free_certlist(&cert
);
212 (*pps
)->backuppassword
= NULL
;
219 fs_give((void **)&(*pps
)->passfile
);
220 #endif /* PASSFILE */
222 if((*pps
)->hdr_colors
)
223 free_spec_colors(&(*pps
)->hdr_colors
);
225 if((*pps
)->index_token_colors
)
226 free_spec_colors(&(*pps
)->index_token_colors
);
229 free_keyword_list(&(*pps
)->keywords
);
231 if((*pps
)->kw_colors
)
232 free_spec_colors(&(*pps
)->kw_colors
);
237 for(i
= 0; (*pps
)->atmts
[i
].description
; i
++){
238 fs_give((void **) &(*pps
)->atmts
[i
].description
);
239 fs_give((void **) &(*pps
)->atmts
[i
].number
);
242 fs_give((void **) &(*pps
)->atmts
);
246 msgno_give(&(*pps
)->msgmap
);
249 free_id(&(*pps
)->id
);
253 fs_give((void **) pps
);
258 free_pinerc_strings(struct pine
**pps
)
261 if((*pps
)->prc
->outstanding_pinerc_changes
)
262 write_pinerc((*pps
), Main
, WRP_NONE
);
265 rd_close_remdata(&(*pps
)->prc
->rd
);
267 free_pinerc_s(&(*pps
)->prc
);
271 free_pinerc_s(&(*pps
)->pconf
);
273 if((*pps
)->post_prc
){
274 if((*pps
)->post_prc
->outstanding_pinerc_changes
)
275 write_pinerc((*pps
), Post
, WRP_NONE
);
277 if((*pps
)->post_prc
->rd
)
278 rd_close_remdata(&(*pps
)->post_prc
->rd
);
280 free_pinerc_s(&(*pps
)->post_prc
);
286 * free_vars -- give back resources acquired when we defined the
290 free_vars(struct pine
*ps
)
294 for(i
= 0; ps
&& i
<= V_LAST_VAR
; i
++)
295 free_variable_values(&ps
->vars
[i
]);
300 free_variable_values(struct variable
*var
)
304 free_list_array(&var
->current_val
.l
);
305 free_list_array(&var
->main_user_val
.l
);
306 free_list_array(&var
->post_user_val
.l
);
307 free_list_array(&var
->global_val
.l
);
308 free_list_array(&var
->fixed_val
.l
);
309 free_list_array(&var
->cmdline_val
.l
);
312 if(var
->current_val
.p
)
313 fs_give((void **)&var
->current_val
.p
);
314 if(var
->main_user_val
.p
)
315 fs_give((void **)&var
->main_user_val
.p
);
316 if(var
->post_user_val
.p
)
317 fs_give((void **)&var
->post_user_val
.p
);
318 if(var
->global_val
.p
)
319 fs_give((void **)&var
->global_val
.p
);
321 fs_give((void **)&var
->fixed_val
.p
);
322 if(var
->cmdline_val
.p
)
323 fs_give((void **)&var
->cmdline_val
.p
);
330 new_pinerc_s(char *name
)
332 PINERC_S
*prc
= NULL
;
335 prc
= (PINERC_S
*)fs_get(sizeof(*prc
));
336 memset((void *)prc
, 0, sizeof(*prc
));
337 prc
->name
= cpystr(name
);
349 free_pinerc_s(PINERC_S
**prc
)
353 fs_give((void **)&(*prc
)->name
);
356 rd_free_remdata(&(*prc
)->rd
);
358 if((*prc
)->pinerc_lines
)
359 free_pinerc_lines(&(*prc
)->pinerc_lines
);
361 fs_give((void **)prc
);
366 free_pith_module_globals(void)
368 free_filter_module_globals();
370 free_bldaddr_module_globals();
371 fname_to_locale(NULL
);