home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / c-client / dummy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-29  |  7.9 KB  |  366 lines

  1. /*
  2.  * Program:    Dummy routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    9 May 1991
  13.  * Last Edited:    4 February 1992
  14.  *
  15.  * Copyright 1992 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #include <stdio.h>
  38. #include <ctype.h>
  39. #include <errno.h>
  40. extern int errno;        /* just in case */
  41. #include <pwd.h>
  42. #include <sys/types.h>
  43. #include <sys/file.h>
  44. #include <sys/uio.h>
  45. #include "osdep.h"
  46. #include "mail.h"
  47. #include "dummy.h"
  48. #include "misc.h"
  49.  
  50. /* Dummy routines */
  51.  
  52.  
  53. /* Driver dispatch used by MAIL */
  54.  
  55. DRIVER dummydriver = {
  56.   (DRIVER *) NIL,        /* next driver */
  57.   dummy_valid,            /* mailbox is valid for us */
  58.   dummy_find,            /* find mailboxes */
  59.   dummy_find_bboards,        /* find bboards */
  60.   dummy_open,            /* open mailbox */
  61.   dummy_close,            /* close mailbox */
  62.   dummy_fetchfast,        /* fetch message "fast" attributes */
  63.   dummy_fetchflags,        /* fetch message flags */
  64.   dummy_fetchenvelope,        /* fetch message envelopes */
  65.   dummy_fetchheader,        /* fetch message header only */
  66.   dummy_fetchtext,        /* fetch message body only */
  67.   dummy_fetchbody,        /* fetch message body section */
  68.   dummy_setflag,        /* set message flag */
  69.   dummy_clearflag,        /* clear message flag */
  70.   dummy_search,            /* search for message based on criteria */
  71.   dummy_ping,            /* ping mailbox to see if still alive */
  72.   dummy_check,            /* check for new messages */
  73.   dummy_expunge,        /* expunge deleted messages */
  74.   dummy_copy,            /* copy messages to another mailbox */
  75.   dummy_move            /* move messages to another mailbox */
  76. };
  77.  
  78. /* Dummy validate mailbox
  79.  * Accepts: mailbox name
  80.  * Returns: our driver if name is valid, otherwise calls valid in next driver
  81.  */
  82.  
  83. DRIVER *dummy_valid (name)
  84.     char *name;
  85. {
  86.   int fd;
  87.   char s[MAILTMPLEN];
  88.   strcpy (s,name);        /* in case absolute */
  89.   switch (*name) {        /* what is it? */
  90.   case '{':            /* IMAP file name */
  91.     break;            /* never accept such */
  92.   case '*':            /* BBoard file name */
  93.   case '\0':            /* missing name? */
  94.     return &dummydriver;
  95.   default:            /* relative file name */
  96.     sprintf (s,"%s/%s",(getpwuid (geteuid ()))->pw_dir,name);
  97.   case '/':            /* absolute file name, can we open the file? */
  98.     if ((fd = open (s,O_RDONLY,NIL)) < 0) return &dummydriver;
  99.     close (fd);            /* must be bogus format file */
  100.     break;
  101.   }
  102.                 /* let next driver have at it */
  103.   return dummydriver.next ? (*dummydriver.next->valid) (name) : NIL;
  104. }
  105.  
  106. /* Dummy find list of mailboxes
  107.  * Accepts: mail stream
  108.  *        pattern to search
  109.  */
  110.  
  111. void dummy_find (stream,pat)
  112.     MAILSTREAM *stream;
  113.     char *pat;
  114. {
  115.   /* Exit quietly */
  116. }
  117.  
  118.  
  119. /* Dummy find list of bboards
  120.  * Accepts: mail stream
  121.  *        pattern to search
  122.  */
  123.  
  124. void dummy_find_bboards (stream,pat)
  125.     MAILSTREAM *stream;
  126.     char *pat;
  127. {
  128.   /* Exit quietly */
  129. }
  130.  
  131.  
  132. /* Dummy open
  133.  * Accepts: stream to open
  134.  * Returns: stream on success, NIL on failure
  135.  */
  136.  
  137. MAILSTREAM *dummy_open (stream)
  138.     MAILSTREAM *stream;
  139. {
  140.   char c = *stream->mailbox;
  141.   char tmp[MAILTMPLEN];
  142.   if (!stream->silent) {    /* silence please! */
  143.     if (c) {            /* name specified */
  144.       if (c != '*') sprintf (tmp,"Can't open mailbox: %s",strerror (errno));
  145.       else sprintf (tmp,"Newsgroup %s does not exist",stream->mailbox + 1);
  146.       mm_log (tmp,ERROR);
  147.     }
  148.     else mm_log ("Mailbox name not specified",ERROR);
  149.   }
  150.   return NIL;            /* always fails */
  151. }
  152.  
  153.  
  154. /* Dummy close
  155.  * Accepts: MAIL stream
  156.  */
  157.  
  158. void dummy_close (stream)
  159.     MAILSTREAM *stream;
  160. {
  161.   /* Exit quietly */
  162. }
  163.  
  164. /* Dummy fetch fast information
  165.  * Accepts: MAIL stream
  166.  *        sequence
  167.  */
  168.  
  169. void dummy_fetchfast (stream,sequence)
  170.     MAILSTREAM *stream;
  171.     char *sequence;
  172. {
  173.   fatal ("Impossible dummy_fetchfast");
  174. }
  175.  
  176.  
  177. /* Dummy fetch flags
  178.  * Accepts: MAIL stream
  179.  *        sequence
  180.  */
  181.  
  182. void dummy_fetchflags (stream,sequence)
  183.     MAILSTREAM *stream;
  184.     char *sequence;
  185. {
  186.   fatal ("Impossible dummy_fetchflags");
  187. }
  188.  
  189.  
  190. /* Dummy fetch envelope
  191.  * Accepts: MAIL stream
  192.  *        message # to fetch
  193.  * Returns: envelope of this message
  194.  */
  195.  
  196. ENVELOPE *dummy_fetchenvelope (stream,msgno)
  197.     MAILSTREAM *stream;
  198.     long msgno;
  199. {
  200.   fatal ("Impossible dummy_fetchenvelope");
  201.   return NIL;
  202. }
  203.  
  204.  
  205. /* Dummy fetch message header
  206.  * Accepts: MAIL stream
  207.  *        message # to fetch
  208.  * Returns: message header in RFC822 format
  209.  */
  210.  
  211. char *dummy_fetchheader (stream,msgno)
  212.     MAILSTREAM *stream;
  213.     long msgno;
  214. {
  215.   fatal ("Impossible dummy_fetchheader");
  216.   return NIL;
  217. }
  218.  
  219. /* Dummy fetch message text (only)
  220.     body only;
  221.  * Accepts: MAIL stream
  222.  *        message # to fetch
  223.  * Returns: message text in RFC822 format
  224.  */
  225.  
  226. char *dummy_fetchtext (stream,msgno)
  227.     MAILSTREAM *stream;
  228.     long msgno;
  229. {
  230.   fatal ("Impossible dummy_fetchtext");
  231.   return NIL;
  232. }
  233.  
  234.  
  235. /* Berkeley fetch message body as a structure
  236.  * Accepts: Mail stream
  237.  *        message # to fetch
  238.  *        section specifier
  239.  * Returns: pointer to section of message body
  240.  */
  241.  
  242. char *dummy_fetchbody (stream,m,sec,len)
  243.     MAILSTREAM *stream;
  244.     long m;
  245.     char *sec;
  246.     unsigned long *len;
  247. {
  248.   fatal ("Impossible dummy_fetchbody");
  249.   return NIL;
  250. }
  251.  
  252.  
  253. /* Dummy set flag
  254.  * Accepts: MAIL stream
  255.  *        sequence
  256.  *        flag(s)
  257.  */
  258.  
  259. void dummy_setflag (stream,sequence,flag)
  260.     MAILSTREAM *stream;
  261.     char *sequence;
  262.     char *flag;
  263. {
  264.   fatal ("Impossible dummy_setflag");
  265. }
  266.  
  267.  
  268. /* Dummy clear flag
  269.  * Accepts: MAIL stream
  270.  *        sequence
  271.  *        flag(s)
  272.  */
  273.  
  274. void dummy_clearflag (stream,sequence,flag)
  275.     MAILSTREAM *stream;
  276.     char *sequence;
  277.     char *flag;
  278. {
  279.   fatal ("Impossible dummy_clearflag");
  280. }
  281.  
  282.  
  283. /* Dummy search for messages
  284.  * Accepts: MAIL stream
  285.  *        search criteria
  286.  */
  287.  
  288. void dummy_search (stream,criteria)
  289.     MAILSTREAM *stream;
  290.     char *criteria;
  291. {
  292.   fatal ("Impossible dummy_search");
  293. }
  294.  
  295. /* Dummy ping mailbox
  296.  * Accepts: MAIL stream
  297.  * Returns: T if stream alive, else NIL
  298.  * No-op for readonly files, since read/writer can expunge it from under us!
  299.  */
  300.  
  301. long dummy_ping (stream)
  302.     MAILSTREAM *stream;
  303. {
  304.   fatal ("Impossible dummy_ping");
  305.   return NIL;
  306. }
  307.  
  308.  
  309. /* Dummy check mailbox
  310.  * Accepts: MAIL stream
  311.  * No-op for readonly files, since read/writer can expunge it from under us!
  312.  */
  313.  
  314. void dummy_check (stream)
  315.     MAILSTREAM *stream;
  316. {
  317.   fatal ("Impossible dummy_check");
  318. }
  319.  
  320.  
  321. /* Dummy expunge mailbox
  322.  * Accepts: MAIL stream
  323.  */
  324.  
  325. void dummy_expunge (stream)
  326.     MAILSTREAM *stream;
  327. {
  328.   fatal ("Impossible dummy_expunge");
  329. }
  330.  
  331.  
  332. /* Dummy copy message(s)
  333.     s;
  334.  * Accepts: MAIL stream
  335.  *        sequence
  336.  *        destination mailbox
  337.  * Returns: T if copy successful, else NIL
  338.  */
  339.  
  340. long dummy_copy (stream,sequence,mailbox)
  341.     MAILSTREAM *stream;
  342.     char *sequence;
  343.     char *mailbox;
  344. {
  345.   fatal ("Impossible dummy_copy");
  346.   return NIL;
  347. }
  348.  
  349.  
  350. /* Dummy move message(s)
  351.     s;
  352.  * Accepts: MAIL stream
  353.  *        sequence
  354.  *        destination mailbox
  355.  * Returns: T if move successful, else NIL
  356.  */
  357.  
  358. long dummy_move (stream,sequence,mailbox)
  359.     MAILSTREAM *stream;
  360.     char *sequence;
  361.     char *mailbox;
  362. {
  363.   fatal ("Impossible dummy_move");
  364.   return NIL;
  365. }
  366.