/* * For Epsilon version 5.0: * E-Mail commands. * * Copyright (C) 1991, K. Shane Hartman * * This file is free software; you can redistribute it and/or modify * it under so long as this notice is preserved and no fee is charged * (other than reasonable media fees) for distribution. You are forbidden * to deny these rights to any user of Epsilon. Lugaru Software Ltd. may * incorporate any and all of this code into Epsilon and have all rights to * the code, since it is only useful for Epsilon. * * This file is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Revision History: * Send bug fixes, comments or suggestions to shane@ai.mit.edu. * * Version 1.0: 07/29/91 shane@ai.mit.edu * Version 1.1: 08/02/91 shane@ai.mit.edu Comment and change copyright wording. * Version 1.2: 08/05/91 shane@ai.mit.edu Change regex to simpler form. * * * This file implements an interface to public domain email program * PMAIL for Novell Netware. To use it, PMAIL must be in your path. * You can obtain PMAIL via anonymous FTP from the following: * * RODAN.ACS.SYR.EDU * SPLICER.CBA.HAWAII.EDU * * Its not bad for free and installs in seconds. * * This program works by using the command line interface to PMAIL: * * PMAIL "user-list" file-to-send "subject". * * It could be made to work for any mail program which has a decent * command line interface. * * The command implemented are: * * M-x mail - Compose a message. * C-c C-s - Send the message. * * I have also included M-x show-mail, commented, because it is specific * to our site. It could be made a lot nicer, but I have to earn a living * between Epsilon hacks. The variable user_name controls it. If that is * an empty string, it looks in the environment for USER. If that fails, * it asks. */ #include "eel.h" #ifndef SPR #include "vardefs.h" #else /* * This is the default user name, you should set it to your NETWARE id. */ char user_name[16] = ""; #endif #undef NULL #define NULL ((char *) 0) keytable mail_tab; /* key table for mail mode */ keytable mail_cc_tab; /* for C-c */ /* * M-x mail Compose a message. */ command mail() { zap ("*Mail*"); to_buffer ("*Mail*"); mode_keys = mail_tab; /* use these keys */ mail_tab[CTRL('C')] = find_index ("mail-cc-tab"); major_mode = "Mail"; fill_mode = 1; try_calling ("mail-hook"); make_mode (); bprintf ("To: \nSubject: \n--Text follows this line--\n"); point = 4; } /* * C-c C-s: send composed message. */ command send_mail() on mail_cc_tab[CTRL('S')], mail_cc_tab[CTRL('C')] { char subject[81]; char to[81]; int save = point; if (strfcmp (bufname, "*Mail*")) goto bad_format; point = 0; if (re_search (1, "To:[ \t]+")) { if (!parse_string (1, ".+$", to)) get_string (to, "To: "); if (!*to) { point = save; error ("Must specify recipient"); } } else goto bad_format; if (re_search (1, "Subject:[ \t]+")) { if (!parse_string (1, ".+$", subject)) get_string (subject, "Subject: "); } else goto bad_format; if (search (1, "--Text follows this line--\n")) { /* Put the message in a temporary file */ if (!write_part ("$draft$", 1, point, size ())) { char cmdline[128]; sprintf (cmdline, "PMAIL $draft$ \"%s\" \"%s\"", to, subject); if (!shell ("", cmdline, "")) { say ("Message sent to %s", to); to_buffer (previous_buffer); } else { point = save; say ("PMAIL lost!"); } delete_file ("$draft$"); } } else goto bad_format; point = save; return; bad_format: point = save; error ("Badly formatted message"); } #ifdef SPR /* * This works by looking in the mail directory for a user. You have to * set up the mapping for the user <-> netware mail dir. This example * shows the mapping we use at SPR. If you have a lot of users, you * probably want a table driven thing. PMAIL writes mail to this directory: * old mail are files with extension .cnr, new mail with extension .cnm; * This could be made a lot nicer (read the files for subject and sender * and display a list of those instead of raw filenames. This works for * me. If you do make a nice one, please let me have it. */ /* With arg, shows new mail, otherwise shows all mail */ command show_mail() on mail_cc_tab[CTRL('R')] { char *user = user_name; char *maildir = NULL; if (!user[0]) { user = getenv ("USER"); if (!user) { get_string (user_name, "User Name: "); if (!user_name[0]) quick_abort (); else user = user_name; } } if (user) { /* * Change these so that they map user names to subdirs of mail directory * on your server. */ if (!strfcmp (user, "Shane")) maildir = "B0045"; else if (!strfcmp (user, "Mly")) maildir = "120061"; else if (!strfcmp (user, "David")) maildir = "170089"; else maildir = NULL; } if (!maildir) error ("I don't know you"); { char pat[FNAMELEN]; jmp_buf *old_level = top_level; jmp_buf this_level; char *bname = bufname; int ret; top_level = &this_level; if (ret = setjmp (top_level)) { char *dired = bufname; if (dired != bname) { bufname = bname; delete_buffer (dired); } top_level = old_level; longjmp (top_level, ret); } /* Change this to your server drive and mail directory */ sprintf (pat, "l:\\mail\\%s\\*.cn%c", maildir, has_arg ? 'm' : '?'); dired_one (pat); top_level = old_level; } } #endif