static char rcsid[] = "@(#)$Id: args.c,v 1.82 2007/08/19 14:02:45 hurtta Exp $";
/******************************************************************************
* The Elm (ME+) Mail System - $Revision: 1.82 $ $State: Exp $
*
* Modified by: Kari Hurtta <hurtta+elm@posti.FMI.FI>
* (was hurtta+elm@ozone.FMI.FI)
******************************************************************************
* The Elm Mail System
*
* Copyright (c) 1988-1992 USENET Community Trust
* Copyright (c) 1986,1987 Dave Taylor
*****************************************************************************/
/** starting argument parsing routines for ELM system...
**/
#include "def_elm.h"
#include "patchlevel.h"
#include "s_elm.h"
#if 0
DEBUG_VAR(Debug,__FILE__,"ELM");
#endif
struct Attachments attach_files = { NULL, 0 };
CONST struct Attachments NULL_Attachments = { NULL, 0 };
void add_Attachments(A,x)
struct Attachments *A;
mime_t *x;
{
if (x->magic != MIME_magic)
mime_panic(__FILE__,__LINE__,"add_Attachments",
"Bad magic number");
A->attach_files = safe_realloc(A->attach_files,
(A->attachment_count+1) *
sizeof (A->attach_files[0]));
A->attach_files[A->attachment_count++] = *x;
mime_t_zero(x); /* Quarantee no double pointters */
}
void free_Attachments(A)
struct Attachments *A;
{
if (A->attach_files) {
int i;
for (i = 0; i < A->attachment_count; i++) {
mime_t_clear(& (A->attach_files[i]) );
}
free(A->attach_files);
A->attach_files = NULL;
A->attachment_count = 0;
}
}
extern char *optarg; /* optional argument as we go */
extern int optind; /* argnum + 1 when we leave */
static void args_version P_((int i));
static void args_help P_((void));
char * wanted_charset = NULL;
int wanted_switchmode = -1;
char * wanted_title_string = NULL;
char * wanted_icon_string = NULL;
char * with_title = NULL;
char * wanted_mailbox_title = NULL;
int confirm_url = 0;
/* Retuns array of files requested */
char ** parse_arguments(argc, argv, to_whom, chk_mode, url_mode)
int argc;
char *argv[];
char ***to_whom;
enum check_mode * chk_mode;
char **url_mode;
{
/** Set flags according to what was given to program. If we are
fed a name or series of names, put them into the 'to_whom' buffer
and if the check_only flag wasn't presented, set mail_only to ON,
and if stdin is not a tty, set batch_only to ON;
Return req_mfile, which points to a named mail file or is empty.
**/
int c = 0;
int v = 0;
char ** req_vector = NULL;
int req_len = 0;
*to_whom = NULL;
batch_subject[0] = '\0';
included_file[0] = '\0';
while ((c = getopt(argc, argv, "?aA:cd:D:f:hi:kKmO:s:tVvwX:yz-:")) != EOF) {
switch (c) {
case 'a' : arrow_cursor++; break;
case 'A' :
if(!Attach_it(optarg)) exit(1);
break;
case 'c' : check_only++; use_tite = 0; break;
case 'd' :
#if DEBUG
set_debugging(optarg);
#else
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsIngoringDebug,
"Warning: system created without debugging enabled - request ignored\n"));
error_sleep(1);
#endif
break;
case 'D' :
if (0 == strcmp("NOSWITCH",optarg))
wanted_switchmode = 0;
else if ('=' == optarg[0]) {
wanted_charset = safe_strdup(optarg+1);
wanted_switchmode = 0;
} else {
wanted_charset = safe_strdup(optarg);
wanted_switchmode = 1;
}
break;
case 'f' :
req_vector = safe_realloc(req_vector,
(req_len+2) * sizeof(req_vector[0]));
req_vector[req_len] = safe_strdup(optarg); /* Not really required? */
req_vector[req_len+1] = NULL;
req_len++;
break;
case '?' :
case 'h' : args_help();
case 'i' : strfcpy(included_file, optarg, sizeof included_file);
break;
/* case 'k' : hp_terminal++; break;
case 'K' : hp_terminal++; hp_softkeys++; break;
*/
case 'm' : mini_menu = 0; break;
case 'O' : /* Open url */
if (*url_mode) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsSeveralUrlOptions,
"Several -O 'url' options is not possible."));
exit(1);
}
*url_mode = safe_strdup(optarg); /* Not really required? */
break;
case 's' :
if (batch_subject[0]) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsSeveralSubjectOptions,
"Several -s 'subject' options is not possible."));
exit(1);
}
strfcpy(batch_subject, optarg, sizeof batch_subject);
break;
case 't' : use_tite = 0; break;
case 'V' : sendmail_verbose++; break;
case 'v' : v++; break;
case 'w' : write_elmrc++; break;
case 'X' :
if (!set_transaction_file(optarg))
exit(1);
break;
case 'y' :
if (*chk_mode != chk_none) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsBadYoption,
"Option -y incompatible with given other options."));
exit(1);
}
*chk_mode = chk_unread;
break;
case 'z' :
if (*chk_mode != chk_none) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsBadZoption,
"Option -z incompatible with given other options."));
exit(1);
}
*chk_mode = chk_size;
break;
case '-':
if (0 == strncmp(optarg, "title-name=",11))
wanted_title_string = optarg+11;
else if (0 == strncmp(optarg,"icon-name=",10))
wanted_icon_string = optarg+10;
else if (0 == strncmp(optarg,"with-title=",11))
with_title = optarg+11;
else if (0 == strcmp(optarg,"with-title"))
with_title = "";
else if (0 == strncmp(optarg,"mailbox-title=",14))
wanted_mailbox_title = optarg+14;
else if (0 == strcmp(optarg,"confirm-url"))
confirm_url = 1;
else {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsBadLongOption,
"Bad Long option: %s\n"),
optarg);
exit(1);
}
}
}
if (v)
args_version(v);
#if !defined(DEBUG) && 0
if (debug)
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsIngoringDebug,
"Warning: system created without debugging enabled - request ignored\n"));
debug = 0;
#endif
if (optind < argc) {
*to_whom = argv + optind;
if(!check_only)
mail_only++;
*chk_mode = chk_none; /* NEVER do this if we're mailing!! */
}
if (mail_only || check_only || req_len > 0) {
if (*url_mode) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsBadOoption,
"Option -O incompatible with given other options or arguments"));
exit(1);
}
}
if (strlen(batch_subject) > 0 && ! mail_only && ! *url_mode) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsSubjectNotSend,
"\n\rDon't understand specifying a subject and no-one to send to!\n\r"));
exit(1);
}
if (!isatty(fileno(stdin)) && !check_only) {
batch_only = ON;
if(*batch_subject == '\0')
strfcpy(batch_subject, DEFAULT_BATCH_SUBJECT,
sizeof batch_subject);
}
if (attach_files.attachment_count > 0) {
if (! mail_only && !*url_mode) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsAttachFileNotSend,
"Can't specify an attached files with no-one to send to!"));
exit(1);
}
}
if (strlen(included_file) > 0
) {
if (! mail_only && !*url_mode) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsInclFileNotSend,
"Can't specify an included file with no-one to send to!"));
exit(1);
}
if (batch_only) {
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsInclFileBatch,
"Can't specify an included file in batch mode!"));
exit(1);
}
}
if (wanted_mailbox_title && req_len < 2) {
lib_error(CATGETS(elm_msg_cat, ElmSet,
ElmArgsSeveralFoldersForTitle,
"--mailbox-title requires that several folders is given with -f arguments"));
exit(1);
}
if (confirm_url && !*url_mode) {
lib_error(CATGETS(elm_msg_cat, ElmSet,
ElmArgsConfirmUrlNeedsO,
"--confirm-url requires that url is given with -O argument"));
exit(1);
}
return(req_vector);
}
static void args_help()
{
/** print out possible starting arguments... **/
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsHelp1,
"\nPossible Starting Arguments for ELM program:\n\n\r\
\targ\t\t\tMeaning\n\r\
\t -a \t\tArrow - use the arrow pointer regardless\n\r\
\t -A \t\tAttach file (requires .elm/mime.types)\n\r\
\t -c \t\tCheckalias - check the given aliases only\n\r\
\t -dclass=debugfile:n\t\tDebug - set debug level to 'n' for 'class'\n\r\
\t -fx\t\tFolder - read folder 'x' rather than incoming mailbox\n\r\
\t -h \t\tHelp - give this list of options\n\r\
\t -ix\t\tInclude prepared file 'x' in edit buffer for send\n\r"));
lib_error(CATGETS(elm_msg_cat, ElmSet, ElmArgsHelp2,
"\t -m \t\tMenu - Turn off menu, using more of the screen\n\r\
\t -Ox\t\tOpen url 'x'\n\r\
\t -sx\t\tSubject 'x' - for batch mailing\n\r\
\t -t \t\tTiTe - don't use termcap/terminfo ti/te entries.\n\r\
\t -V \t\tEnable sendmail voyeur mode.\n\r\
\t -v \t\tPrint out ELM version information.\n\r\
\t -w \t\tWrite .elm/elmrc and .elm/mime.charsets\n\r\
\t -y \t\tdon't enter ELM if no unread mail is pending\n\r\
\t -z \t\tZero - don't enter ELM if no mail is pending\n\r\
\n\n"));
/*
\t -k \t\tKeypad - enable HP 2622 terminal keyboard\n\r
\t -K \t\tKeypad&softkeys - enable use of softkeys + \"-k\"\n\r\
*/
exit(1);
}
static void args_version(i)
int i;
{
time_t curr_time = time(NULL);
char * value = NULL;
/** print out version information **/
printf("\nElm Version and Identification Information:\n\n");
if (i == 1)
printf("\tElm Millennium Edition \n\n");
printf("\tElm %s PL%s, of %s\n",VERSION,PATCHLEVEL,VERS_DATE);
#ifdef BINARY_PACKAGE
if (i != 2) {
printf("\tCompiled for binary distribution.\n");
printf("\tSend bug reports to packager of binary distribution.\n");
}
#else
if (curr_time < LAST_REPORT_TIME && i != 2) {
printf("\tSend bug reports to %s\n",BUG_REPORT_ADDR);
printf("\n\tWARNING: Elm is not intended to be distributed in\n");
printf( "\t binary form. If that is done, then it is very\n");
printf( "\t likely that compile time configuration does not\n");
printf( "\t match to your system. This is NOT bug of ELM ME+\n");
printf( "\t and bug reports for that reason will be rejected.\n\n");
}
#endif
if (i == 1)
printf("\n\tBased on Elm 2.4 PL24 - PL25\n\n");
if (i < 3) {
printf("\t(C) Copyright 1996-2007 Kari Hurtta\n");
printf("\tBased on Elm 2.4, (C) Copyright 1988-1992 USENET Community Trust\n");
printf("\tBased on Elm 2.0, (C) Copyright 1986,1987 Dave Taylor\n");
}
if ( i < 2 ) {
printf ("\n\tTo print configuration, use option: -vv\n");
exit(1);
}
if (i < 3) {
printf("\t----------------------------------\n");
printf("\tConfigured %s\n", CONFIGURE_DATE);
printf("\t----------------------------------\n");
#ifdef MMDF
printf("\tUse MMDF Mail Transport Agent/Mailbox Delimiters: MMDF\n");
#else /* MMDF */
printf("\tUse UNIX Mailbox Delimiters and Mail Transport Agent: not MMDF\n");
#endif /* MMDF */
#ifdef MYDOMAIN
printf("\tCompiled in default host's domain name is %s\n",
MYDOMAIN);
#endif
#if defined(GETHOSTNAME) || defined(DOUNAME)
printf("\tHostname is available on runtime:");
#ifdef GETHOSTNAME
printf(" GETHOSTNAME");
#endif
#ifdef DOUNAME
printf(" DOUNAME");
#endif
printf("\n");
#else
printf("\tHostname is not available on runtime: no GETHOSTNAME nor DOUNAME\n");
#endif
printf("\tFollowing mail spool locking protocols will be used:");
#ifdef USE_DOTLOCK_LOCKING
printf(" USE_DOTLOCK_LOCKING (.lock)");
#endif
#ifdef USE_FLOCK_LOCKING
printf(" USE_FLOCK_LOCKING");
#endif
#ifdef USE_FCNTL_LOCKING
printf(" USE_FCNTL_LOCKING");
#endif
printf("\n");
#ifdef SYSCALL_LOCKING
printf("\tFolder locking is available: SYSCALL_LOCKING\n");
#else
printf("\tFolder locking is not possible: not SYSCALL_LOCKING\n");
#endif
#if 0
#ifdef DEBUG
printf("\tDebug options are available: DEBUG\n");
#else /* DEBUG */
printf("\tNo debug options are available: not DEBUG\n");
#endif /* DEBUG */
#endif
#ifdef CRYPT
printf("\tCrypt function enabled: CRYPT\n");
#else /* CRYPT */
printf("\tCrypt function disabled: not CRYPT\n");
#endif /* CRYPT */
#ifdef ALLOW_MAILBOX_EDITING
printf("\tMailbox editing included: ALLOW_MAILBOX_EDITING\n");
#else /* ALLOW_MAILBOX_EDITING */
printf("\tMailbox editing not included: not ALLOW_MAILBOX_EDITING\n");
#endif /* ALLOW_MAILBOX_EDITING */
#ifdef ALLOW_SUBSHELL
printf("\tSubshell menu items included: ALLOW_SUBSHELL\n");
#else /* ALLOW_SUBSHELL */
printf("\tSubshell menu items not included: not ALLOW_SUBSHELL\n");
#endif /* ALLOW_SUBSHELL */
#ifdef ISPELL
printf("\tSpell checking feature enabled: ISPELL\n");
printf("\t\t(Default spelling checker is %s options '%s')\n", ISPELL_PATH, ISPELL_OPTIONS);
#else /* ISPELL */
printf("\tSpell checking feature disabled: not ISPELL\n");
#endif /* ISPELL */
#ifdef ENABLE_CALENDAR
printf("\tCalendar file feature enabled: ENABLE_CALENDAR\n");
printf("\t\t(Default calendar file is %s)\n",dflt_calendar_file);
#else /* ENABLE_CALENDAR */
printf("\tCalendar file feature disabled: not ENABLE_CALENDAR\n");
#endif /* ENABLE_CALENDAR */
#ifdef USE_PGP
printf("\tPGP support enabled: USE_PGP\n");
#else
printf("\tPGP support disabled: not USE_PGP\n");
#endif
#ifdef ASCII_CTYPE
printf("\t\"ctype\" functions are ASCII -only: ASCII_CTYPE\n");
#else
printf("\t\"ctype\" functions are 8-bit clean: not ASCII_CTYPE\n");
#endif
#ifdef BROKE_CTYPE
printf("\tUsing replacement toupper() and tolower() routines: BROKE_CTYPE\n");
#else
printf("\tUsing standard \"ctype\" toupper() and tolower() routines: not BROKE_CTYPE\n");
#endif
#ifdef I_LOCALE
printf("\tSystem support multiple character sets or languages: I_LOCALE\n");
#else
printf("\tMultiple display character sets are not supported: not I_LOCALE\n");
#endif
#ifdef HAVE_CODESET
printf("\tSystem supports nl_langinfo(CODESET) query: HAVE_CODESET\n");
if (ASCII_CODESET) {
char * S = ASCII_CODESET;
printf("\t Codeset for C locale (US-ASCII) is %s\n", S);
}
#else
printf("\tSystem does not support nl_langinfo(CODESET) query: not HAVE_CODESET\n");
#endif
#ifdef WCHAR
printf("\tSystem have native wide character support: WCHAR\n");
#ifdef __STDC_ISO_10646__
printf("\t wchar_t is Unicode (the Universal Character Set): __STDC_ISO_10646__\n");
#endif
#ifdef WCWIDTH
printf("\t wcwidth() function is available: WCWIDTH\n");
#else
printf("\t Character width function is not available: not WCWIDTH\n");
#endif
#else
printf("\tSystem do not support wide characters: not WCHAR\n");
#endif
#ifdef MSGCAT
printf("\tUses system's msgcat() implementation: MSGCAT\n");
#else
printf("\tUses own message catalog routines: not MSGCAT\n");
#endif
#ifdef REMOTE_MBX
printf("\tSupports remote mailboxes (username@host): REMOTE_MBX\n");
#else
printf("\tDoes not support remote mailboxes (username@host): not REMOTE_MBX\n");
#endif
#ifdef DIROPS
printf("\tSupports browsing of local directories: DIROPS %s%s\n",
DIROPS == USE_DIRENT ? "(USE_DIRENT)" : "",
DIROPS == USE_SYSDIR ? "(USE_SYSDIR)" : "");
#else
printf("\tDoes not support browsing of local directories: not DIROPS\n");
#endif
#ifdef MMAP
printf("\tUnicode data is mapped to memory: MMAP\n");
#else
printf("\tUnicode data is read to memory: not MMAP\n");
#endif
#ifdef USE_DLOPEN
printf("\tDynamically loaded libraries are supported: USE_DLOPEN\n");
#else
printf("\tAdditional libraries are not supported: not USE_DLOPEN\n");
#endif
printf("\n\n");
printf("\tTo read global initialization file %s, use 'elm -vvv'\n",
system_rc_file);
exit(1);
}
switch (i) {
case 3:
printf("\t------------------------------------------\n");
printf("\tSystem RC file: %s\n",system_rc_file);
printf("\t------------------------------------------\n\n");
user_init();
init_mailerlib();
init_mboxlib();
init_misclib();
init_defaults();
post_init_check(0);
printf("\tHave Posix saved IDs: %3s (egid %d)\n",
have_saved_ids ? "Yes" : "No",
mailgroupid);
putchar('\n');
printf("\tHostname: %s\n",hostname);
printf("\tHost's domain: %s\n",hostdomain);
printf("\tQualified hostname: %s\n",hostfullname);
{
char * default_val = give_dt_estr_as_str(&defaultfile_e,"incoming-mailbox");
printf("\tMailbox: %s\n",
default_val ? default_val : "<no value>");
}
if(mailerfunc(&value,0,0,NULL))
printf("\tMailer: %s\n",value);
printf("\tSystem character-set: %s\n",
system_charset->MIME_name ?
system_charset->MIME_name :
"<no MIME name>");
printf("\tLocal FS character-set: %-18s",
local_fs_charset->MIME_name ?
local_fs_charset->MIME_name :
"<no MIME name>");
if (!local_fs_charset->MIME_name ||
0 != istrcmp(local_fs_charset->MIME_name,raw_local_fs_charset))
printf("(%s)",raw_local_fs_charset);
putchar('\n');
printf("\tWanted display character-set: %-18s",
wanted_display_charset->MIME_name ?
wanted_display_charset->MIME_name :
"<no MIME name>");
if (!wanted_display_charset->MIME_name ||
0 != istrcmp(wanted_display_charset->MIME_name,
raw_display_charset))
printf("(%s)",raw_display_charset);
putchar('\n');
printf("\tSending character-set: %-18s",
text_charset->MIME_name ?
text_charset->MIME_name :
"<no MIME name>");
if (!text_charset->MIME_name ||
0 != istrcmp(text_charset->MIME_name,raw_text_charset))
printf("(%s)",raw_text_charset);
putchar('\n');
printf("\tDef. non-MIME character-set: %-18s",
default_nomime_charset->MIME_name ?
default_nomime_charset->MIME_name :
"<no MIME name>");
if (!default_nomime_charset->MIME_name ||
0 != istrcmp(default_nomime_charset->MIME_name,
raw_default_nomime_charset))
printf("(%s)",raw_default_nomime_charset);
putchar('\n');
printf("\tDef. MIME text character-set: %-18s",
default_mimetext_charset->MIME_name ?
default_mimetext_charset->MIME_name :
"<no MIME name>");
if (!default_mimetext_charset->MIME_name ||
0 != istrcmp(default_mimetext_charset->MIME_name,
raw_default_mimetext_charset))
printf("(%s)",raw_default_mimetext_charset);
putchar('\n');
printf("\n\tTo list configuration files, use 'elm -vvvv'\n");
break;
case 4:
printf("\t------------------------------------------\n");
printf("\tElm ME+ configuration files: \n");
printf("\t------------------------------------------\n\n");
user_init();
printf("System configuration files:\n");
printf("\tRC file: %s\n",system_rc_file);
printf("\tAliases database: %s\n",system_data_file);
printf("\tAliases file: %s\n",system_text_file);
printf("\tMapping to content-type: %s\n",system_mime_types);
printf("\tMapping to charset: %s\n",system_mime_charsets);
printf("\tMapping of ISO 2022: %s\n",system_iso2022_sets);
printf("\tAdditional terminal info: %s\n",system_terminal_info);
printf("\tMail services info: %s\n",system_mail_services);
printf("\tDomain-name file: %s\n",hostdomfile);
printf("User configuration files:\n");
printf("\tRC file: %s\n",user_rc_file);
printf("\tAliases database: %s\n",user_data_file);
printf("\tAliases file: %s\n",user_text_file);
printf("\tMapping to content-type: %s\n",user_mime_types);
printf("\tMapping to charset: %s\n",user_mime_charsets);
printf("\tMapping of ISO 2022: %s\n",user_iso2022_sets);
printf("\tAdditional terminal info: %s\n",user_terminal_info);
printf("\tMail services info: %s\n",user_mail_services);
printf("\tAdditional mail-headers: %s\n",user_mailheaders);
printf("\n\tTo read user configuration, use 'elm -vvvvv'\n");
break;
case 5:
user_init();
init_mailerlib();
init_mboxlib();
init_misclib();
init_defaults();
printf("\t------------------------------------------\n");
printf("\tUser RC file: %s\n",user_rc_file);
printf("\t------------------------------------------\n\n");
read_rc_file(0);
if (display_codeset[0]) {
printf("\tLocale (LC_CTYPE): %s (codeset %s)\n",
display_locale,display_codeset);
} else
printf("\tLocale (LC_CTYPE): %s\n",display_locale);
printf("\tSystem character-set: %s\n",
system_charset->MIME_name ?
system_charset->MIME_name :
"<no MIME name>");
printf("\tWanted display character-set: %-18s",
wanted_display_charset->MIME_name ?
wanted_display_charset->MIME_name :
"<no MIME name>");
if (!wanted_display_charset->MIME_name ||
0 != istrcmp(wanted_display_charset->MIME_name,
raw_display_charset))
printf("(%s)",raw_display_charset);
putchar('\n');
printf("\tLocal FS character-set: %-18s",
local_fs_charset->MIME_name ?
local_fs_charset->MIME_name :
"<no MIME name>");
if (!local_fs_charset->MIME_name ||
0 != istrcmp(local_fs_charset->MIME_name,raw_local_fs_charset))
printf("(%s)",raw_local_fs_charset);
putchar('\n');
printf("\tSending character-set: %-18s",
text_charset->MIME_name ?
text_charset->MIME_name :
"<no MIME name>");
if (!text_charset->MIME_name ||
0 != istrcmp(text_charset->MIME_name,raw_text_charset))
printf("(%s)",raw_text_charset);
putchar('\n');
printf("\tDef. non-MIME character-set: %-18s",
default_nomime_charset->MIME_name ?
default_nomime_charset->MIME_name :
"<no MIME name>");
if (!default_nomime_charset->MIME_name ||
0 != istrcmp(default_nomime_charset->MIME_name,
raw_default_nomime_charset))
printf("(%s)",raw_default_nomime_charset);
putchar('\n');
{
char * default_val = give_dt_estr_as_str(&defaultfile_e,"incoming-mailbox");
printf("\tMailbox: %s\n",
default_val ? default_val : "<no value>");
}
}
exit(1);
}
/*
* Local Variables:
* mode:c
* c-basic-offset:4
* buffer-file-coding-system: iso-8859-1
* End:
*/
syntax highlighted by Code2HTML, v. 0.9.1