annotate lib-src/fakemail.c @ 4981:4aebb0131297

Cleanups/renaming of EXTERNAL_TO_C_STRING and friends -------------------- ChangeLog entries follow: -------------------- modules/ChangeLog addition: 2010-02-05 Ben Wing <ben@xemacs.org> * postgresql/postgresql.c: * postgresql/postgresql.c (CHECK_LIVE_CONNECTION): * postgresql/postgresql.c (Fpq_connectdb): * postgresql/postgresql.c (Fpq_connect_start): * postgresql/postgresql.c (Fpq_lo_import): * postgresql/postgresql.c (Fpq_lo_export): * ldap/eldap.c (Fldap_open): * ldap/eldap.c (Fldap_search_basic): * ldap/eldap.c (Fldap_add): * ldap/eldap.c (Fldap_modify): * ldap/eldap.c (Fldap_delete): * canna/canna_api.c (Fcanna_initialize): * canna/canna_api.c (Fcanna_store_yomi): * canna/canna_api.c (Fcanna_parse): * canna/canna_api.c (Fcanna_henkan_begin): EXTERNAL_TO_C_STRING returns its argument instead of storing it in a parameter, and is renamed to EXTERNAL_TO_ITEXT. Similar things happen to related macros. See entry in src/ChangeLog. More Mule-izing of postgresql.c. Extract out common code between `pq-connectdb' and `pq-connect-start'. Fix places that signal an error string using a formatted string to instead follow the standard and have a fixed reason followed by the particular error message stored as one of the frobs. src/ChangeLog addition: 2010-02-05 Ben Wing <ben@xemacs.org> * console-msw.c (write_string_to_mswindows_debugging_output): * console-msw.c (Fmswindows_message_box): * console-x.c (x_perhaps_init_unseen_key_defaults): * console.c: * database.c (dbm_get): * database.c (dbm_put): * database.c (dbm_remove): * database.c (berkdb_get): * database.c (berkdb_put): * database.c (berkdb_remove): * database.c (Fopen_database): * device-gtk.c (gtk_init_device): * device-msw.c (msprinter_init_device_internal): * device-msw.c (msprinter_default_printer): * device-msw.c (msprinter_init_device): * device-msw.c (sync_printer_with_devmode): * device-msw.c (Fmsprinter_select_settings): * device-x.c (sanity_check_geometry_resource): * device-x.c (Dynarr_add_validified_lisp_string): * device-x.c (x_init_device): * device-x.c (Fx_put_resource): * device-x.c (Fx_valid_keysym_name_p): * device-x.c (Fx_set_font_path): * dialog-msw.c (push_lisp_string_as_unicode): * dialog-msw.c (handle_directory_dialog_box): * dialog-msw.c (handle_file_dialog_box): * dialog-x.c (dbox_descriptor_to_widget_value): * editfns.c (Fformat_time_string): * editfns.c (Fencode_time): * editfns.c (Fset_time_zone_rule): * emacs.c (make_argc_argv): * emacs.c (Fdump_emacs): * emodules.c (emodules_load): * eval.c: * eval.c (maybe_signal_error_1): * event-msw.c (Fdde_alloc_advise_item): * event-msw.c (mswindows_dde_callback): * event-msw.c (mswindows_wnd_proc): * fileio.c (report_error_with_errno): * fileio.c (Fsysnetunam): * fileio.c (Fdo_auto_save): * font-mgr.c (extract_fcapi_string): * font-mgr.c (Ffc_config_app_font_add_file): * font-mgr.c (Ffc_config_app_font_add_dir): * font-mgr.c (Ffc_config_filename): * frame-gtk.c (gtk_set_frame_text_value): * frame-gtk.c (gtk_create_widgets): * frame-msw.c (mswindows_init_frame_1): * frame-msw.c (mswindows_set_title_from_ibyte): * frame-msw.c (msprinter_init_frame_3): * frame-x.c (x_set_frame_text_value): * frame-x.c (x_set_frame_properties): * frame-x.c (start_drag_internal_1): * frame-x.c (x_cde_transfer_callback): * frame-x.c (x_create_widgets): * glyphs-eimage.c (my_jpeg_output_message): * glyphs-eimage.c (jpeg_instantiate): * glyphs-eimage.c (gif_instantiate): * glyphs-eimage.c (png_instantiate): * glyphs-eimage.c (tiff_instantiate): * glyphs-gtk.c (xbm_instantiate_1): * glyphs-gtk.c (gtk_xbm_instantiate): * glyphs-gtk.c (gtk_xpm_instantiate): * glyphs-gtk.c (gtk_xface_instantiate): * glyphs-gtk.c (cursor_font_instantiate): * glyphs-gtk.c (gtk_redisplay_widget): * glyphs-gtk.c (gtk_widget_instantiate_1): * glyphs-gtk.c (gtk_add_tab_item): * glyphs-msw.c (mswindows_xpm_instantiate): * glyphs-msw.c (bmp_instantiate): * glyphs-msw.c (mswindows_resource_instantiate): * glyphs-msw.c (xbm_instantiate_1): * glyphs-msw.c (mswindows_xbm_instantiate): * glyphs-msw.c (mswindows_xface_instantiate): * glyphs-msw.c (mswindows_redisplay_widget): * glyphs-msw.c (mswindows_widget_instantiate): * glyphs-msw.c (add_tree_item): * glyphs-msw.c (add_tab_item): * glyphs-msw.c (mswindows_combo_box_instantiate): * glyphs-msw.c (mswindows_widget_query_string_geometry): * glyphs-x.c (x_locate_pixmap_file): * glyphs-x.c (xbm_instantiate_1): * glyphs-x.c (x_xbm_instantiate): * glyphs-x.c (extract_xpm_color_names): * glyphs-x.c (x_xpm_instantiate): * glyphs-x.c (x_xface_instantiate): * glyphs-x.c (autodetect_instantiate): * glyphs-x.c (safe_XLoadFont): * glyphs-x.c (cursor_font_instantiate): * glyphs-x.c (x_redisplay_widget): * glyphs-x.c (Fchange_subwindow_property): * glyphs-x.c (x_widget_instantiate): * glyphs-x.c (x_tab_control_redisplay): * glyphs.c (pixmap_to_lisp_data): * gui-x.c (menu_separator_style_and_to_external): * gui-x.c (add_accel_and_to_external): * gui-x.c (button_item_to_widget_value): * hpplay.c (player_error_internal): * hpplay.c (play_sound_file): * hpplay.c (play_sound_data): * intl.c (Fset_current_locale): * lisp.h: * menubar-gtk.c (gtk_xemacs_set_accel_keys): * menubar-msw.c (populate_menu_add_item): * menubar-msw.c (populate_or_checksum_helper): * menubar-x.c (menu_item_descriptor_to_widget_value_1): * nt.c (init_user_info): * nt.c (get_long_basename): * nt.c (nt_get_resource): * nt.c (init_mswindows_environment): * nt.c (get_cached_volume_information): * nt.c (mswindows_readdir): * nt.c (read_unc_volume): * nt.c (mswindows_stat): * nt.c (mswindows_getdcwd): * nt.c (mswindows_executable_type): * nt.c (Fmswindows_short_file_name): * ntplay.c (nt_play_sound_file): * objects-gtk.c: * objects-gtk.c (gtk_valid_color_name_p): * objects-gtk.c (gtk_initialize_font_instance): * objects-gtk.c (gtk_font_list): * objects-msw.c (font_enum_callback_2): * objects-msw.c (parse_font_spec): * objects-x.c (x_parse_nearest_color): * objects-x.c (x_valid_color_name_p): * objects-x.c (x_initialize_font_instance): * objects-x.c (x_font_instance_truename): * objects-x.c (x_font_list): * objects-xlike-inc.c (XFUN): * objects-xlike-inc.c (xft_find_charset_font): * process-nt.c (mswindows_report_winsock_error): * process-nt.c (nt_create_process): * process-nt.c (get_internet_address): * process-nt.c (nt_open_network_stream): * process-unix.c: * process-unix.c (allocate_pty): * process-unix.c (get_internet_address): * process-unix.c (unix_canonicalize_host_name): * process-unix.c (unix_open_network_stream): * realpath.c: * select-common.h (lisp_data_to_selection_data): * select-gtk.c (symbol_to_gtk_atom): * select-gtk.c (atom_to_symbol): * select-msw.c (symbol_to_ms_cf): * select-msw.c (mswindows_register_selection_data_type): * select-x.c (symbol_to_x_atom): * select-x.c (x_atom_to_symbol): * select-x.c (hack_motif_clipboard_selection): * select-x.c (Fx_store_cutbuffer_internal): * sound.c (Fplay_sound_file): * sound.c (Fplay_sound): * sound.h (sound_perror): * sysdep.c: * sysdep.c (qxe_allocating_getcwd): * sysdep.c (qxe_execve): * sysdep.c (copy_in_passwd): * sysdep.c (qxe_getpwnam): * sysdep.c (qxe_ctime): * sysdll.c (dll_open): * sysdll.c (dll_function): * sysdll.c (dll_variable): * sysdll.c (search_linked_libs): * sysdll.c (dll_error): * sysfile.h: * sysfile.h (PATHNAME_CONVERT_OUT_TSTR): * sysfile.h (PATHNAME_CONVERT_OUT_UTF_8): * sysfile.h (PATHNAME_CONVERT_OUT): * sysfile.h (LISP_PATHNAME_CONVERT_OUT): * syswindows.h (ITEXT_TO_TSTR): * syswindows.h (LOCAL_FILE_FORMAT_TO_TSTR): * syswindows.h (TSTR_TO_LOCAL_FILE_FORMAT): * syswindows.h (LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN): * syswindows.h (LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR): * text.h: * text.h (eicpy_ext_len): * text.h (enum new_dfc_src_type): * text.h (EXTERNAL_TO_ITEXT): * text.h (GET_STRERROR): * tooltalk.c (check_status): * tooltalk.c (Fadd_tooltalk_message_arg): * tooltalk.c (Fadd_tooltalk_pattern_attribute): * tooltalk.c (Fadd_tooltalk_pattern_arg): * win32.c (tstr_to_local_file_format): * win32.c (mswindows_lisp_error_1): * win32.c (mswindows_report_process_error): * win32.c (Fmswindows_shell_execute): * win32.c (mswindows_read_link_1): Changes involving external/internal format conversion, mostly code cleanup and renaming. 1. Eliminate the previous macros like LISP_STRING_TO_EXTERNAL that stored its result in a parameter. The new version of LISP_STRING_TO_EXTERNAL returns its result through the return value, same as the previous NEW_LISP_STRING_TO_EXTERNAL. Use the new-style macros throughout the code. 2. Rename C_STRING_TO_EXTERNAL and friends to ITEXT_TO_EXTERNAL, in keeping with overall naming rationalization involving Itext and related types. Macros involved in previous two: EXTERNAL_TO_C_STRING -> EXTERNAL_TO_ITEXT EXTERNAL_TO_C_STRING_MALLOC -> EXTERNAL_TO_ITEXT_MALLOC SIZED_EXTERNAL_TO_C_STRING -> SIZED_EXTERNAL_TO_ITEXT SIZED_EXTERNAL_TO_C_STRING_MALLOC -> SIZED_EXTERNAL_TO_ITEXT_MALLOC C_STRING_TO_EXTERNAL -> ITEXT_TO_EXTERNAL C_STRING_TO_EXTERNAL_MALLOC -> ITEXT_TO_EXTERNAL_MALLOC LISP_STRING_TO_EXTERNAL LISP_STRING_TO_EXTERNAL_MALLOC LISP_STRING_TO_TSTR C_STRING_TO_TSTR -> ITEXT_TO_TSTR TSTR_TO_C_STRING -> TSTR_TO_ITEXT The following four still return their values through parameters, since they have more than one value to return: C_STRING_TO_SIZED_EXTERNAL -> ITEXT_TO_SIZED_EXTERNAL LISP_STRING_TO_SIZED_EXTERNAL C_STRING_TO_SIZED_EXTERNAL_MALLOC -> ITEXT_TO_SIZED_EXTERNAL_MALLOC LISP_STRING_TO_SIZED_EXTERNAL_MALLOC Sometimes additional casts had to be inserted, since the old macros played strange games and completely defeated the type system of the store params. 3. Rewrite many places where direct calls to TO_EXTERNAL_FORMAT occurred with calls to one of the convenience macros listed above, or to make_extstring(). 4. Eliminate SIZED_C_STRING macros (they were hardly used, anyway) and use a direct call to TO_EXTERNAL_FORMAT or TO_INTERNAL_FORMAT. 4. Use LISP_PATHNAME_CONVERT_OUT in many places instead of something like LISP_STRING_TO_EXTERNAL(..., Qfile_name). 5. Eliminate some temporary variables that are no longer necessary now that we return a value rather than storing it into a variable. 6. Some Mule-izing in database.c. 7. Error functions: -- A bit of code cleanup in maybe_signal_error_1. -- Eliminate report_file_type_error; it's just an alias for signal_error_2 with params in a different order. -- Fix some places in the hostname-handling code that directly inserted externally-retrieved error strings into the supposed ASCII "reason" param instead of doing the right thing and sticking text descriptive of what was going on in "reason" and putting the external message in a frob. 8. Use Ascbyte instead of CIbyte in process-unix.c and maybe one or two other places. 9. Some code cleanup in copy_in_passwd() in sysdep.c. 10. Fix a real bug due to accidental variable shadowing in tstr_to_local_file_format() in win32.c.
author Ben Wing <ben@xemacs.org>
date Fri, 05 Feb 2010 11:02:24 -0600
parents 8b63e21b0436
children cd167465bf69 061f4f90f874
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* sendmail-like interface to /bin/mail for system V,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
4 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
11 XEmacs is distributed in the hope that it will be useful,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.28. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #define NO_SHORTNAMES
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 434
diff changeset
24 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #if defined (BSD) && !defined (BSD4_1) && !defined (USE_FAKEMAIL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 /* This program is not used in BSD, so just avoid loader complaints. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #elif defined (LINUX)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 int
2509
6a9afa282c8e [xemacs-hg @ 2005-01-26 09:53:28 by ben]
ben
parents: 2286
diff changeset
37 main (int argc, char *argv[])
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 /* Linux /bin/mail, if it exists, is NOT the Unix v7 mail that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 fakemail depends on! This causes garbled mail. Better to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 output an error message. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 fprintf (stderr, "Sorry, fakemail does not work on Linux.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 fprintf (stderr, "Make sure you have the sendmail program, and\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 fprintf (stderr, "set the Lisp variable `sendmail-program' to point\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 fprintf (stderr, "to the path of the sendmail binary.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #else /* not BSD 4.2 (or newer) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 /* These are defined in config in some versions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #ifdef static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #undef static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #ifdef read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #undef read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #undef write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #undef open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #undef close
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #if __STDC__ || defined(STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #include <pwd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 /* Type definitions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #define boolean int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 #define true 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #define false 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 /* Various lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 struct line_record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 char *string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 struct line_record *continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 typedef struct line_record *line_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 struct header_record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 line_list text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 struct header_record *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 struct header_record *previous;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 typedef struct header_record *header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 struct stream_record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 FILE *handle;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 int (*action)(FILE *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 struct stream_record *rest_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 typedef struct stream_record *stream_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 /* A `struct linebuffer' is a structure which holds a line of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 * `readline' reads a line from a stream into a linebuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 * and works regardless of the length of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 struct linebuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
111 size_t size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 char *buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 struct linebuffer lb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #define new_list() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ((line_list) xmalloc (sizeof (struct line_record)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 #define new_header() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ((header) xmalloc (sizeof (struct header_record)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 #define new_stream() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ((stream_list) xmalloc (sizeof (struct stream_record)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #define alloc_string(nchars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ((char *) xmalloc ((nchars) + 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 /* Global declarations */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #define BUFLEN 1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 #define KEYWORD_SIZE 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 #define FROM_PREFIX "From"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #define MY_NAME "fakemail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #define NIL ((line_list) NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #define INITIAL_LINE_SIZE 200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #define MAIL_PROGRAM_NAME "/bin/mail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
136 static const char *my_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 static char *the_date;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 static char *the_user;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 static line_list file_preface;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 static stream_list the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 static boolean no_problems = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 #if !__STDC__ && !defined(STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 extern FILE *popen ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 extern int fclose (), pclose ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 extern char *malloc (), *realloc ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
2687
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
149 #if defined(__FreeBSD_version) && __FreeBSD_version >= 400000
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
150 #define CURRENT_USER
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
151 #endif
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
152
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 #ifdef CURRENT_USER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 extern struct passwd *getpwuid ();
2687
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
155 #if defined(__FreeBSD_version) && __FreeBSD_version >= 400000
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
156 extern uid_t geteuid ();
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
157 #else
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
158 extern unsigned short geteuid ();
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
159 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 static struct passwd *my_entry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 #define cuserid(s) \
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
162 (my_entry = getpwuid ((int) geteuid ()), \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 my_entry->pw_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 /* Utilities */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
171 error (const char *s1, const char *s2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 printf ("%s: ", my_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 printf (s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 no_problems = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 /* Print error message and exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
182 fatal (const char *s1, const char *s2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 error (s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
190 static void *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 xmalloc (size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
193 void *result = malloc (size);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
194 if (result == NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 fatal ("virtual memory exhausted", (char *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
199 static void *
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
200 xrealloc (void *ptr, size_t size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
202 void *result = realloc (ptr, size);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
203 if (result == NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 fatal ("virtual memory exhausted", (char *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 /* Initialize a linebuffer for use */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 init_linebuffer (struct linebuffer *linebuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 linebuffer->size = INITIAL_LINE_SIZE;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
214 linebuffer->buffer = (char *) xmalloc (INITIAL_LINE_SIZE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 /* Read a line of text from `stream' into `linebuffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 * Return the length of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 static long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 readline (struct linebuffer *linebuffer, FILE *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 char *buffer = linebuffer->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 char *p = linebuffer->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 char *end = p + linebuffer->size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 while (true)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 int c = getc (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 if (p == end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 linebuffer->size *= 2;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
234 buffer = (char *) xrealloc (buffer, linebuffer->size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 p = buffer + (p - linebuffer->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 end = buffer + linebuffer->size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 linebuffer->buffer = buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 if (c < 0 || c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 *p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 *p++ = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 return p - buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 get_keyword (register char *field, char **rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 static char keyword[KEYWORD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 register char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 register char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 ptr = &keyword[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 c = *field++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 if ((isspace ((int) (unsigned char) c)) || (c == ':'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 return (char *) NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 *ptr++ = ((islower ((int) (unsigned char) c)) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (toupper ((int) (unsigned char) c)) : c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 while (((c = *field++) != ':') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (!(isspace ((int) (unsigned char) c))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 *ptr++ = ((islower ((int) (unsigned char) c)) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (toupper ((int) (unsigned char) c)) : c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 *ptr++ = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 while (isspace ((int) (unsigned char) c)) c = *field++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 if (c != ':') return (char *) NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 *rest = field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 return &keyword[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 has_keyword (char *field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 char *ignored;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
278 return (get_keyword (field, &ignored) != (char *) NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 add_field (line_list the_list, register char *field, register char *where)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 register char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 while (true)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 *where++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 while ((c = *field++) != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 if (c == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 while (*field && *field != ')') ++field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 if (! (*field++)) break; /* no closer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 if (! (*field)) break; /* closerNULL */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 c = *field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 *where++ = ((c == ','||c=='>'||c=='<') ? ' ' : c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 if (the_list == NIL) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 field = the_list->string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 the_list = the_list->continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 return where;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 static line_list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 make_file_preface (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 char *the_string, *temp;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
310 time_t idiotic_interface;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 long prefix_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 long user_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 long date_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 line_list result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 prefix_length = strlen (FROM_PREFIX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 time (&idiotic_interface);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 the_date = ctime (&idiotic_interface);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 /* the_date has an unwanted newline at the end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 date_length = strlen (the_date) - 1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
321 if (the_date[date_length] == '\n')
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
322 the_date[date_length] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
323 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 temp = "(null)";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 temp = cuserid ((char *) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 user_length = strlen (temp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 the_user = alloc_string ((size_t) (user_length + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 strcpy (the_user, temp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 the_string = alloc_string ((size_t) (3 + prefix_length +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 user_length +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 date_length));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 temp = the_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 strcpy (temp, FROM_PREFIX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 temp = &temp[prefix_length];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 *temp++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 strcpy (temp, the_user);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 temp = &temp[user_length];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 *temp++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 strcpy (temp, the_date);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 result = new_list ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 result->string = the_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 result->continuation = ((line_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 write_line_list (register line_list the_list, FILE *the_stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 for ( ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 the_list != ((line_list) NULL) ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 the_list = the_list->continuation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 fputs (the_list->string, the_stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 putc ('\n', the_stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 close_the_streams (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 register stream_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 for (rem = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 rem != ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 rem = rem->rest_streams)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 no_problems = (no_problems &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 ((*rem->action) (rem->handle) == 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 the_streams = ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 return (no_problems ? 0 : 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 add_a_stream (FILE *the_stream, int (*closing_action)(FILE *))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 stream_list old = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 the_streams = new_stream ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 the_streams->handle = the_stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 the_streams->action = closing_action;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 the_streams->rest_streams = old;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 my_fclose (FILE *the_file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 putc ('\n', the_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 fflush (the_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 return fclose (the_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 open_a_file (char *name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 FILE *the_stream = fopen (name, "a");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 if (the_stream != ((FILE *) NULL))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 add_a_stream (the_stream, my_fclose);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
400 if (the_user == (char *) NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 file_preface = make_file_preface ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 write_line_list (file_preface, the_stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 put_string (char *s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 register stream_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 for (rem = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 rem != ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 rem = rem->rest_streams)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 fputs (s, rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
420 put_line (const char *string)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 register stream_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 for (rem = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 rem != ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 rem = rem->rest_streams)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
427 const char *s = string;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 int column = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 /* Divide STRING into lines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 while (*s != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
433 const char *breakpos;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 /* Find the last char that fits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 for (breakpos = s; *breakpos && column < 78; ++breakpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 if (*breakpos == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 column += 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 column++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 /* If we didn't reach end of line, break the line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 if (*breakpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 /* Back up to just after the last comma that fits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 while (breakpos != s && breakpos[-1] != ',') --breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 if (breakpos == s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 /* If no comma fits, move past the first address anyway. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 while (*breakpos != 0 && *breakpos != ',') ++breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 if (*breakpos != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 /* Include the comma after it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 ++breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 /* Output that much, then break the line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 fwrite (s, 1, breakpos - s, rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 column = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 /* Skip whitespace and prepare to print more addresses. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 s = breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 while (*s == ' ' || *s == '\t') ++s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 if (*s != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 fputs ("\n\t", rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 putc ('\n', rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 #define mail_error error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 setup_files (register line_list the_list, register char *field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 register char *start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 register char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 while (true)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 while (((c = *field) != '\0') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 ((c == ' ') ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (c == '\t') ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (c == ',')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 field += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 if (c != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 start = field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 while (((c = *field) != '\0') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (c != ' ') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (c != '\t') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (c != ','))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 field += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 *field = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 if (!open_a_file (start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 mail_error ("Could not open file %s", start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 *field = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 if (c != '\0') continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 if (the_list == ((line_list) NULL)) return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 field = the_list->string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 the_list = the_list->continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 args_size (header the_header)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 register line_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 register int size = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 {
4932
8b63e21b0436 fix compile issues with gcc 4
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
515 char *field = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 register char *keyword = get_keyword (the_header->text->string, &field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 if ((strcmp (keyword, "TO") == 0) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (strcmp (keyword, "CC") == 0) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (strcmp (keyword, "BCC") == 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 size += 1 + strlen (field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 for (rem = the_header->text->continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 rem != NIL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 rem = rem->continuation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 size += 1 + strlen (rem->string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 the_header = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 } while (the_header != old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 return size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 parse_header (header the_header, register char *where)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 {
4932
8b63e21b0436 fix compile issues with gcc 4
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
538 char *field = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 register char *keyword = get_keyword (the_header->text->string, &field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 if (strcmp (keyword, "TO") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 where = add_field (the_header->text->continuation, field, where);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 else if (strcmp (keyword, "CC") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 where = add_field (the_header->text->continuation, field, where);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 else if (strcmp (keyword, "BCC") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 where = add_field (the_header->text->continuation, field, where);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 the_header->previous->next = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 the_header->next->previous = the_header->previous;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 else if (strcmp (keyword, "FCC") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 setup_files (the_header->text->continuation, field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 the_header = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 } while (the_header != old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 *where = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 static header
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 read_header (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 register header the_header = ((header) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 register line_list *next_line = ((line_list *) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 init_linebuffer (&lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 long length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 register char *line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 readline (&lb, stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 line = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 length = strlen (line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 if (length == 0) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 if (has_keyword (line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 the_header = new_header ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 if (old == ((header) NULL))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 the_header->next = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 the_header->previous = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 the_header->previous = old;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 the_header->next = old->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 old->next = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 next_line = &(the_header->text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 if (next_line == ((line_list *) NULL))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 /* Not a valid header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 *next_line = new_list ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (*next_line)->string = alloc_string ((size_t) length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 strcpy (((*next_line)->string), line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 next_line = &((*next_line)->continuation);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 *next_line = NIL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 } while (true);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 return the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 write_header (header the_header)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 register line_list the_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 for (the_list = the_header->text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 the_list != NIL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 the_list = the_list->continuation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 put_line (the_list->string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 the_header = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 } while (the_header != old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 put_line ("");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 char *command_line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 header the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 long name_length;
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 2687
diff changeset
633 const char *mail_program_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 char buf[BUFLEN + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 register int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 FILE *the_pipe;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 mail_program_name = getenv ("FAKEMAILER");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 if (!(mail_program_name && *mail_program_name))
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 2687
diff changeset
640 mail_program_name = MAIL_PROGRAM_NAME;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 name_length = strlen (mail_program_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 my_name = MY_NAME;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 the_streams = ((stream_list) NULL);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
645 the_date = (char *) NULL;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
646 the_user = (char *) NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 the_header = read_header ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 command_line = alloc_string ((size_t) (name_length +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 args_size (the_header)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 strcpy (command_line, mail_program_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 parse_header (the_header, &command_line[name_length]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 the_pipe = popen (command_line, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 if (the_pipe == ((FILE *) NULL))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
656 fatal ("cannot open pipe to real mailer", (char *) NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 add_a_stream (the_pipe, pclose);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 write_header (the_header);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 /* Dump the message itself */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 while (!feof (stdin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 size = fread (buf, 1, BUFLEN, stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 buf[size] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 put_string (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 return close_the_streams ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 #endif /* not BSD 4.2 (or newer) */