/***********************************************************************
* *
* This software is part of the BSD package *
*Copyright (c) 1978-2010 The Regents of the University of California an*
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* *
* 1. Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* materials provided with the distribution. *
* *
* 3. Neither the name of The Regents of the University of California*
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS *
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* 1. Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in *
* distribution. *
* 3. Neither the name of the University nor the names of its *
* contributors may be used to endorse or promote products derived *
* from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" *
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
* *
* Kurt Shoens (UCB) *
* gsf *
* *
***********************************************************************/
#pragma prototyped
/*
* Mail -- a mail program
*
* Startup -- interface with user.
*/
#include "mailx.h"
#if _PACKAGE_ast
#include "stamp.h"
static const char usage[] =
"[+NAME?mailx - send and receive mail]"
"[+DESCRIPTION?\bmailx\b is a mail processing command. The options place"
" \bmailx\b in either \asend\a or \areceive\a mode. Send mode composes"
" and sends messages from text on the standard input. Receive mode"
" provides both an interactive command language and non-interactive"
" command line actions. Receive mode, on startup, reads commands and"
" variable settings from the file \b$HOME/.mailrc\b, if it exists.]"
"[+?\bmailx\b provides commands for saving, deleting and responding to"
" messages. Message composition supports editing, reviewing and"
" other modifications as the message is entered.]"
"[+?Incoming mail is stored in one or more unspecified locations for each"
" user, collectively called the system mailbox for that user. When"
" \bmailx\b is invoked in \areceive\a mode, the system mailbox is"
" searched by default.]"
"[+?For additional help run \bmailx\b with no options or operands,"
" and then enter the \bhelp\b command at the interactive prompt.]"
"[A:articles?Treat mail folders as netnews article.]"
"[F:followup?Automatically include the previous message (followup) text"
" when composing a reply.]"
"[H:headers?List all headers and exit.]"
"[I:interactive?Force interactive receive mode.]"
"[N!:list-headers?List a screen of headers on receive mode startup.]"
"[P:pipe?Coprocess receive mode from a pipe.]"
"[Q:query?List the status character and sender address for the \acount\a"
" most recent messages, one line per message, and exit. See \b--status\b"
" for message status characters details.]:[count]"
"[S:status?List the status character and sender address for all messages,"
" one line per message, and exit. The message status characters are:]{"
" [M?To be saved in \bmbox\b and marked for delete on exit.]"
" [N?New message.]"
" [P?Preserved and will not be deleted.]"
" [R?Already read.]"
" [U?Unread message from previous session.]"
" [X?Possible spam.]"
" [\b*\b?Saved to a folder and marked for delete on exit.]"
"}"
"[b:bcc?Prompt for the blind carbon copy recipient list when composing"
" messages.]"
"[c:cc?Prompt for the carbon copy recipient list when composing messages.]"
"[d:debug?Enable implementation specific debug output.]"
"[e:check?Silently exit 0 if there is mail, 1 otherwise.]"
"[f:folder?Mail is read from \afolder\a instead of the default"
"[i:ignore-interrupts?Ignore interrupts.]"
"[o:set?Set \aname\a=\avalue\a options. The interactive mail command"
" \bhelp set all\b lists details for each option.]:[name=value]"
"[r:address?Set the reply to header address to \aaddress\a.]:[address]"
"[s:subject?The non-interactive send mode subject text.]:[text]"
"[t:sendheaders?Check for headers in send mode message text.]"
"[u:user?Pretend to be this \buser\b in send mode. For debugging.]:[user]"
"[v:verbose?Enable implementation specific send mode verbose trace.]"
"\n"
"\n[ address ... ]\n"
"\n"
;
#else
#endif
/*
* Interrupt printing of the headers.
*/
static void
{
note(0, "\nInterrupt");
}
/*
* Set command line options and append to
* op list for resetopt() after the rc's.
*/
static struct list*
{
int n;
n = strlen(s) + 1;
if (v)
n += strlen(v) + 1;
if (v) {
*s++ = '=';
strcpy(s, v);
}
}
sreset();
return op;
}
/*
* Reset the setopt() options after the rc's.
*/
static void
{
}
sreset();
}
}
int
{
register int i;
int sig;
char* ef;
int flags = 0;
#if _PACKAGE_ast
int fatal = 0;
#endif
#if _PACKAGE_ast
#endif
/*
* Set up a reasonable environment.
* Figure out whether we are being run interactively,
* and so forth.
*/
if (!(state.path.buf = sfstropen()) || !(state.path.move = sfstropen()) || !(state.path.part = sfstropen()) || !(state.path.temp = sfstropen()))
varinit();
/*
* Now, determine how we are being used.
* We successively pick off - flags.
* If there is anything left, it is the base of the list
* of users to mail to. Argp will be set to point to the
* first of these users.
*/
ef = 0;
opterr = 0;
for (;;) {
case 0:
case EOF:
break;
case 'A':
continue;
case 'F':
continue;
case 'H':
/*
* List all headers and exit.
*/
continue;
case 'I':
/*
* We're interactive
*/
continue;
case 'N':
/*
* Avoid initial header printing.
*/
continue;
case 'P':
/*
* Coprocess on pipe.
*/
continue;
case 'Q':
/*
* List all n most recent status and senders and exit.
*/
continue;
case 'S':
/*
* List all status and senders and exit.
*/
continue;
case 'T':
/*
* Next argument is temp file to write which
*/
continue;
case 'b':
/*
* Get Blind Carbon Copy Recipient list
*/
continue;
case 'c':
/*
* Get Carbon Copy Recipient list
*/
continue;
case 'd':
/*
* Debug output.
*/
continue;
case 'e':
/*
* Silently exit 0 if mail, 1, otherwise.
*/
continue;
case 'f':
#if _PACKAGE_ast
ef = "&";
#else
/*
* User is specifying file to "edit" with Mail,
* as opposed to reading system mailbox.
* If no argument is given after -f, we read his
* mbox file.
*
* getopt() can't handle optional arguments, so here
* is an ugly hack to get around it.
*/
else
ef = "&";
#endif
continue;
case 'i':
/*
* User wants to ignore interrupts.
* Set the variable "ignore"
*/
continue;
case 'n':
/*
* User doesn't want to source state.var.master
*/
continue;
case 'o':
/*
* Set option(s) by name.
*/
continue;
case 'r':
/*
* Set replyto.
*/
{
char* s;
int n;
static const char h[] = "fixedheaders=Reply-To:\" \"";
if (!(s = newof(0, char, n + sizeof(h) + 1, 0)))
memcpy(s, h, sizeof(h) - 1);
}
continue;
case 's':
/*
* Give a subject field for sending from
* non terminal
*/
continue;
case 't':
/*
* Check for headers in message text.
*/
continue;
case 'u':
/*
* Next argument is person to pretend to be.
*/
continue;
case 'v':
/*
* Send mailer verbose flag
*/
continue;
#if _PACKAGE_ast
case '?':
break;
case ':':
fatal = 1;
break;
#else
case '?':
Usage: mail [-o [no]name[=value]] [-s subject] [-c cc] [-b bcc] to ...\n\
mail [-o [no]name[=value]] [-f [folder]]");
break;
#endif
}
break;
}
#if _PACKAGE_ast
if (fatal)
#endif
if (argv[i])
/*
* Check for inconsistent arguments.
*/
}
exit(1);
tempinit();
/*
* Up to this point salloc()==malloc() by default.
* From now on salloc() space cleared by sreset().
*/
/*
* Expand returns a savestr, but load only uses the file name
* for fopen, so it's safe to do this.
*/
/*
* Reset command line options so they take precedence over the rc's.
*/
/*
* why wait?
*/
}
/*
* Ok, we are reading mail.
* Decide whether we are editing a mailbox or reading
* the system mailbox, and open up the right stuff.
*/
if (!ef)
ef = "%";
exit(1);
else {
announce();
}
commands();
quit();
}
exit(0);
}