home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume13
/
xmail
/
part03
/
mail.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-15
|
12KB
|
343 lines
/*
* xmail - X window system interface to the mail program
*
* Copyright 1989 The University of Texas at Austin
*
* Author: Po Cheung
* Date: March 10, 1989
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation. The University of Texas at Austin makes no
* representations about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* Copyright 1990 by National Semiconductor Corporation
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of National Semiconductor Corporation not
* be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* NATIONAL SEMICONDUCTOR CORPORATION MAKES NO REPRESENTATIONS ABOUT THE
* SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS"
* WITHOUT EXPRESS OR IMPLIED WARRANTY. NATIONAL SEMICONDUCTOR CORPORATION
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
* EVENT SHALL NATIONAL SEMICONDUCTOR CORPORATION BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* The following software modules were created and are Copyrighted by National
* Semiconductor Corporation:
*
* 1. editMail:
* 2. sendMail:
*
* Author: Michael C. Wagnitz - National Semiconductor Corporation
*
*/
#include "global.h"
#include <sys/wait.h>
#include <sys/stat.h>
#ifndef DEFAULT_VISUAL
#define DEFAULT_VISUAL "/usr/ucb/vi"
#endif
/*
** @(#)editMail() - edit a mail message using the preferred editor
**
** Support is now provided for declaring the editor command as an xmail
** resource, ala xrn. If the resource ``xmail.editorCommand'' is defined,
** it must contain an `sprintf'-able format string that provides for the
** inclusion of both a display name and the name of the file to be edited.
** If the resource declaration is not included, or does not contain the two
** required percent-s (%s) formatting strings, xmail will use the VISUAL
** resource. If VISUAL is used, try to accommodate those editors (emacs,
** xedit...) which start their own window in X11. We know for a fact that
** vi and ed variants do not invoke windows. We assume any other editor
** specification does.
*/
void
editMail()
{
Display *ad;
char *edit, *cp;
char *Argv[50];
char cmd[BUFSIZ];
int i, editMail_pid;
int status;
static XEvent event;
bzero(cmd, BUFSIZ);
ad = XtDisplay(XtNameToWidget(toplevel, "topBox.statusWindow"));
/*
** If editorCommand resource exists, use it (format validated during initialize)
*/
if (XMail.editorCommand)
sprintf(cmd, XMail.editorCommand, ad->display_name, tmpName);
else {
/*
** Otherwise, default to the VISUAL method of starting things
*/
if ((edit = GetMailEnv("VISUAL")) == NULL)
edit = XtNewString(DEFAULT_VISUAL);
if ((cp = strrchr(edit, '/')) == NULL) cp = edit;
else cp++;
if (strcmp(cp, "ed") == 0 ||
strcmp(cp,"red") == 0 ||
strcmp(cp, "ex") == 0 ||
strcmp(cp, "vi") == 0) {
sprintf(cmd,
"/usr/bin/X11/xterm -display %s -name XMail -title 'Message entry' -e %s %s",
ad->display_name, edit, tmpName);
} else sprintf(cmd, "%s -display %s %s", edit, ad->display_name, tmpName);
XtFree(edit);
}
editMail_pid = fork();
switch (editMail_pid) {
case -1: /* fork failed ... revert to a system call */
system(cmd);
break;
case 0: /* child starts the message entry session */
for (i = 0, cp = cmd; i < 49 && *cp; i++) {
Argv[i] = cp++; /* pull out each separate argument */
if (*Argv[i] == '"') { /* if this is a "quoted string"... */
Argv[i] = cp++;
while (*cp && *cp != '"') cp++;
*cp++ = '\0';
} else
if (*Argv[i] == "'"[0]) { /* or if it's a 'quoted string'... */
Argv[i] = cp++;
while (*cp && *cp != "'"[0]) cp++;
*cp++ = '\0';
}
else while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n') cp++;
if (*cp) /* truncate each argument as needed */
*cp++ = '\0';
}
Argv[i] = NULL;
SetCursor(0); /* restore cursor just before editing */
execvp(Argv[0], Argv);
perror("editMail: Failed to start the text editor");
_exit();
break;
default: /* wait for child to finish before continuing */
while (wait3(&status, WNOHANG, NULL) != editMail_pid)
if (XPending(XtDisplay(toplevel)) > 0) {
XNextEvent(XtDisplay(toplevel), &event);
XtDispatchEvent(&event);
}
break;
}
} /* editMail */
/*
** @(#)readMail() - callback invoked every time input is pending on mail fd
**
** Calls QueryMail() to read all available data from mail file descriptor,
** and passes output to parse() for analysis and appropriate action.
*/
XtInputCallbackProc
readMail(client_data, source, id)
caddr_t client_data;
int *source;
XtInputId *id;
{
parse(QueryMail(""));
} /* readMail */
/*
** @(#)sendMail() - send a mail message to the indicated recipient(s)
*/
/* ARGSUSED */
void
sendMail(parent)
Widget parent;
{
Arg args[11];
Widget Popup, Layout, Box;
Widget lab1, lab2, lab3, lab4;
Widget To, Subject, Cclist, Bcc, Last;
editMail();
Popup = XtNameToWidget(toplevel, "topBox.commandPanel.Send.popup");
if (! Popup) {
XtSetArg(args[0], XtNinput, True);
XtSetArg(args[1], XtNwidth, XMail.shellWidth - 2);
XtSetArg(args[2], XtNheight,
XMail.borderWidth*3 + XMail.buttonHeight*5 + 44);
Popup = XtCreatePopupShell("popup",transientShellWidgetClass,parent,args,3);
XtSetArg(args[0], XtNdefaultDistance, 2);
Layout = XtCreateManagedWidget("SubjCc", formWidgetClass, Popup, args, 1);
XtSetArg(args[0], XtNfromVert, NULL);
XtSetArg(args[1], XtNfromHoriz, NULL);
XtSetArg(args[2], XtNlabel, "To:");
XtSetArg(args[3], XtNborderWidth, 0);
XtSetArg(args[4], XtNfont, XMail.buttonFont);
XtSetArg(args[5], XtNheight, XMail.buttonHeight + XMail.borderWidth + 7);
XtSetArg(args[6], XtNwidth, XMail.buttonWidth);
XtSetArg(args[7], XtNjustify, XtJustifyLeft);
XtSetArg(args[8], XtNinternalHeight, 0);
XtSetArg(args[9], XtNinternalWidth, 1);
lab1 = XtCreateManagedWidget("SubjCc", labelWidgetClass, Layout, args, 10);
To = CreateInputWindow(Layout, "To", Recipient, BUFSIZ);
AddInfoHandler(To, SendMail_Info[0]);
XtSetArg(args[0], XtNfromVert, NULL);
XtSetArg(args[1], XtNfromHoriz, lab1);
XtSetValues(To, args, 2);
AddHelpText(To, To_Help);
XtSetArg(args[0], XtNfromVert, lab1);
XtSetArg(args[1], XtNfromHoriz, NULL);
XtSetArg(args[2], XtNlabel, "Subject:");
lab2 = XtCreateManagedWidget("SubjCc", labelWidgetClass, Layout, args, 10);
Subject = CreateInputWindow(Layout, "Subject", SubjBuf, BUFSIZ);
AddInfoHandler(Subject, SendMail_Info[1]);
XtSetArg(args[0], XtNfromVert, To);
XtSetArg(args[1], XtNfromHoriz, lab2);
XtSetValues(Subject, args, 2);
AddHelpText(Subject, Subject_Help);
XtSetArg(args[0], XtNfromVert, lab2);
XtSetArg(args[1], XtNfromHoriz, NULL);
XtSetArg(args[2], XtNlabel, "Cc:");
lab3 = XtCreateManagedWidget("SubjCc", labelWidgetClass, Layout, args, 10);
Cclist = CreateInputWindow(Layout, "Cc", CcBuf, BUFSIZ);
AddInfoHandler(Cclist, SendMail_Info[2]);
XtSetArg(args[0], XtNfromVert, Subject);
XtSetArg(args[1], XtNfromHoriz, lab3);
XtSetValues(Cclist, args, 2);
AddHelpText(Cclist, Cc_Help);
XtSetArg(args[0], XtNfromVert, lab3);
XtSetArg(args[1], XtNfromHoriz, NULL);
XtSetArg(args[2], XtNlabel, "Bcc:");
lab4 = XtCreateManagedWidget("SubjCc", labelWidgetClass, Layout, args, 10);
Bcc = CreateInputWindow(Layout, "Bcc", BccBuf, BUFSIZ);
AddInfoHandler(Bcc, SendMail_Info[3]);
XtSetArg(args[0], XtNfromVert, Cclist);
XtSetArg(args[1], XtNfromHoriz, lab4);
XtSetValues(Bcc, args, 2);
AddHelpText(Bcc, Bcc_Help);
XtSetArg(args[0], XtNfont, XMail.buttonFont);
XtSetArg(args[1], XtNheight, XMail.buttonHeight + XMail.borderWidth*2 + 4);
XtSetArg(args[2], XtNwidth, XMail.shellWidth - 2);
XtSetArg(args[3], XtNfromVert, lab4);
XtSetArg(args[4], XtNfromHoriz, NULL);
XtSetArg(args[5], XtNborderWidth, 0);
XtSetArg(args[6], XtNresize, False);
XtSetArg(args[7], XtNmin, args[1].value);
XtSetArg(args[8], XtNmax, args[1].value);
XtSetArg(args[9], XtNhSpace, 2);
XtSetArg(args[10],XtNvSpace, 2);
Box = XtCreateManagedWidget("Box", boxWidgetClass, Layout, args, 11);
XtSetArg(args[1], XtNheight, XMail.buttonHeight);
XtSetArg(args[2], XtNwidth,
(((XMail.shellWidth - 2) / 6) - XMail.borderWidth * 2) - 4);
lab1 = XtCreateManagedWidget("Autograph", commandWidgetClass, Box, args, 3);
XtAddCallback(lab1, XtNcallback, (XtCallbackProc) Autograph, (caddr_t) "A");
AddInfoHandler(lab1, Autograph_Info[0]);
AddHelpText(lab1, Sign_Help);
lab2 = XtCreateManagedWidget("autograph", commandWidgetClass, Box, args, 3);
XtAddCallback(lab2, XtNcallback, (XtCallbackProc) Autograph, (caddr_t) "a");
AddInfoHandler(lab2, Autograph_Info[1]);
AddHelpText(lab2, sign_Help);
lab1 = XtCreateManagedWidget("ReEdit", commandWidgetClass, Box, args, 3);
XtAddCallback(lab1,XtNcallback,(XtCallbackProc) ReEdit, (caddr_t)"ReEdit");
AddInfoHandler(lab1, Deliver_Info[1]);
AddHelpText(lab1, ReEdit_Help);
lab2 = XtCreateManagedWidget("Cancel", commandWidgetClass, Box, args, 3);
XtAddCallback(lab2, XtNcallback, (XtCallbackProc) Done, (caddr_t) "cancel");
AddInfoHandler(lab2, Deliver_Info[2]);
AddHelpText(lab2, Cancel_Help);
lab3 = XtCreateManagedWidget("Abort", commandWidgetClass, Box, args, 3);
XtAddCallback(lab3, XtNcallback, (XtCallbackProc) Done, (caddr_t) "Cancel");
AddInfoHandler(lab3, Deliver_Info[3]);
AddHelpText(lab3, Abort_Help);
Last = XtCreateManagedWidget("Deliver", commandWidgetClass, Box, args, 3);
XtAddCallback(Last, XtNcallback, (XtCallbackProc) Done, (caddr_t)"Deliver");
AddInfoHandler(Last, Deliver_Info[0]);
AddHelpText(Last, Deliver_Help);
}
To = XtNameToWidget(Popup, "*To");
writeText(To, Recipient, 0);
XawTextSetInsertionPoint(To, TextGetLastPos(To));
Subject = XtNameToWidget(Popup, "*Subject");
writeText(Subject, SubjBuf, 0);
XawTextSetInsertionPoint(Subject, TextGetLastPos(Subject));
Cclist = XtNameToWidget(Popup, "*Cc");
writeText(Cclist, CcBuf, 0);
XawTextSetInsertionPoint(Cclist, TextGetLastPos(Cclist));
Bcc = XtNameToWidget(Popup, "*Bcc");
writeText(Bcc, BccBuf, 0);
XawTextSetInsertionPoint(Bcc, TextGetLastPos(Bcc));
SetXY(Popup, XtNameToWidget(toplevel, "topBox.commandPanel"), 0, 0);
XtPopup(Popup, XtGrabNone);
XWarpPointer(XtDisplay(toplevel), None, XtWindow(To), 0, 0, 0, 0, 10, 5);
} /* sendMail */
/*
** @(#)writeMail() - Write s to mail, and flush the output.
*/
void
writeMail(s)
char *s;
{
write(mail_fd, s, strlen(s));
} /* writeMail */