* For mailing lists, Alpine adds a description of the type of link
[alpine.git] / pith / state.c
blob0c687d6abec588edb566808dc936ff194a67b4f3
1 /*
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 /*======================================================================
16 state.c
17 Implements the Pine state management routines
18 ====*/
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! */
40 #ifdef DEBUG
42 * Debug level and output file defined here, referenced globally.
43 * The debug file is opened and initialized below...
45 int debug = DEFAULT_DEBUG;
46 #endif
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
58 and many many more...
60 ----*/
61 char tmp_20k_buf[SIZEOF_20KBUF];
65 * new_pine_struct - allocate and fill in with default values a new pine struct
67 struct pine *
68 new_pine_struct(void)
70 struct pine *p;
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;
86 #ifdef SMIME
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();
92 #endif /* SMIME */
93 p->atmts = (ATTACH_S *) fs_get(sizeof(ATTACH_S));
94 p->atmts_allocated = 1;
95 p->atmts->description = NULL;
96 p->low_speed = 1;
97 p->init_context = -1;
98 /* msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
99 init_init_vars(p);
101 return(p);
107 * free_pine_struct -- free up allocated data in pine struct and then the
108 * struct itself
110 void
111 free_pine_struct(struct pine **pps)
113 if(!(pps && (*pps)))
114 return;
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);
146 if((*pps)->ui.login)
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);
167 if((*pps)->pinerc)
168 fs_give((void **)&(*pps)->pinerc);
170 #if defined(DOS) || defined(OS2)
171 if((*pps)->pine_dir)
172 fs_give((void **)&(*pps)->pine_dir);
174 if((*pps)->aux_files_dir)
175 fs_give((void **)&(*pps)->aux_files_dir);
176 #endif
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);
187 #ifdef SMIME
188 if((*pps)->pwdcertdir)
189 fs_give((void **)&(*pps)->pwdcertdir);
191 if((*pps)->pwdcert){
192 PERSONAL_CERT *pc;
194 pc = (PERSONAL_CERT *) (*pps)->pwdcert;
195 free_personal_certs(&pc);
196 (*pps)->pwdcert = NULL;
199 if((*pps)->pwdcertlist){
200 CertList *cert;
202 cert = (CertList *) (*pps)->pwdcertlist;
203 free_certlist(&cert);
204 (*pps)->pwdcertlist = NULL;
207 if((*pps)->backuppassword){
208 CertList *cert;
210 cert = (CertList *) (*pps)->backuppassword;
211 free_certlist(&cert);
212 (*pps)->backuppassword = NULL;
214 #endif /* SMIME */
217 #ifdef PASSFILE
218 if((*pps)->passfile)
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);
228 if((*pps)->keywords)
229 free_keyword_list(&(*pps)->keywords);
231 if((*pps)->kw_colors)
232 free_spec_colors(&(*pps)->kw_colors);
234 if((*pps)->atmts){
235 int i;
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);
245 if((*pps)->msgmap)
246 msgno_give(&(*pps)->msgmap);
248 if((*pps)->id)
249 free_id(&(*pps)->id);
251 free_vars(*pps);
253 fs_give((void **) pps);
257 void
258 free_pinerc_strings(struct pine **pps)
260 if((*pps)->prc){
261 if((*pps)->prc->outstanding_pinerc_changes)
262 write_pinerc((*pps), Main, WRP_NONE);
264 if((*pps)->prc->rd)
265 rd_close_remdata(&(*pps)->prc->rd);
267 free_pinerc_s(&(*pps)->prc);
270 if((*pps)->pconf)
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
287 * variables list
289 void
290 free_vars(struct pine *ps)
292 register int i;
294 for(i = 0; ps && i <= V_LAST_VAR; i++)
295 free_variable_values(&ps->vars[i]);
299 void
300 free_variable_values(struct variable *var)
302 if(var){
303 if(var->is_list){
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);
311 else{
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);
320 if(var->fixed_val.p)
321 fs_give((void **)&var->fixed_val.p);
322 if(var->cmdline_val.p)
323 fs_give((void **)&var->cmdline_val.p);
329 PINERC_S *
330 new_pinerc_s(char *name)
332 PINERC_S *prc = NULL;
334 if(name){
335 prc = (PINERC_S *)fs_get(sizeof(*prc));
336 memset((void *)prc, 0, sizeof(*prc));
337 prc->name = cpystr(name);
338 if(IS_REMOTE(name))
339 prc->type = RemImap;
340 else
341 prc->type = Loc;
344 return(prc);
348 void
349 free_pinerc_s(PINERC_S **prc)
351 if(prc && *prc){
352 if((*prc)->name)
353 fs_give((void **)&(*prc)->name);
355 if((*prc)->rd)
356 rd_free_remdata(&(*prc)->rd);
358 if((*prc)->pinerc_lines)
359 free_pinerc_lines(&(*prc)->pinerc_lines);
361 fs_give((void **)prc);
365 void
366 free_pith_module_globals(void)
368 free_filter_module_globals();
369 ical_free_all();
370 free_bldaddr_module_globals();
371 fname_to_locale(NULL);
372 fname_to_utf8(NULL);