home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / SCCS / S5.C < prev    next >
Encoding:
Text File  |  1995-07-04  |  6.9 KB  |  302 lines

  1. h08711
  2. s 00289/00000/00000
  3. d D 1.1 95/07/04 20:12:48 tim 1 0
  4. c 
  5. e
  6. u
  7. U
  8. f e 0
  9. t
  10. T
  11. I 1
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "project.h"
  15. /* start of meta file operations code */
  16. /* the meta file consists of line terminated data in the following format */
  17. /* the full path component, E.g. LOC::M\MAIL\ */
  18. /* mu current email adress, e.g. tim.graves@uk.sun.com the following repeated */
  19. /* datafile name, E.g. in1.msg or out1.msg */
  20. /* to, a list of recieved addresses, e.g. tim.graves@uk.sun.com MUST contain at least one address */
  21. /* from, the origionator of the email */
  22. /* subject, obvious */
  23. /* cc, the cc list */
  24. /* bcc, the bcc list (empty on reciept )*/
  25. /* read, N if the email is unread, R if read */
  26. /*at the end of the repeats */
  27. /* END */
  28. /* No other items */
  29. /* */
  30. /* read in the data descriptions */
  31. int readmeta(fname, itemlist)
  32. char * fname ;
  33. struct ll * itemlist;
  34. {
  35.     FILE * fd ;
  36.     int ret ;
  37.     if (mtadbg == TRUE)
  38.         printf("CALL: readmeta (fname = %s, itemlist = OMITTED)", fname) ;
  39.     if ((fd = fopen(fname, "r")) == NULL)
  40.     {
  41.         printf("FILE ERROR:  readmeta, error in opening %s", fname) ;
  42.         return (FILEERR) ;
  43.     }
  44.     /* load the one off data */
  45.     ret = getf(fd, itemlist->mydata->mypath) ;
  46.     if ( ret == FALSE)
  47.     {
  48.         printf("FILE ERROR: readmeta, error in reading my path from %s", fname) ;
  49.         return(FILEERR) ;
  50.     }
  51.     ret = getf(fd, itemlist->mydata->myaddr) ;
  52.     if (ret == FALSE)
  53.     {
  54.         printf("FILE ERROR: readmeta, error in reading my address from %s", fname) ;
  55.         return(FILEERR) ;
  56.     }
  57.     while((ret = readhdr(fd, itemlist))== TRUE)
  58.         ;
  59.     fclose(fd) ;
  60.     if (ret == FILEERR)
  61.     {
  62.         printf("FILE ERROR: readmeta, error in reading meta record from %s", fname) ;
  63.         return(FILEERR) ;
  64.     }
  65.     return(TRUE) ;
  66. }
  67.  
  68. /* write the data descriptions out */
  69. wrtmeta(fname, itemlist)
  70. char * fname;
  71. struct ll * itemlist ;
  72. {
  73.     FILE * fd ;
  74.     int ret ;
  75.         
  76.     if (mtadbg == TRUE)
  77.         printf("CALL: wrtmeta (fname = %s, itemlist = OMITTED)", fname) ;
  78.     ret = unlink(fname) ; /* delete the origional file */
  79.     if (ret < 0)
  80.     {
  81.         printf("FILE ERROR: wrtmeta, error in deleting %s prior to output", fname) ;
  82.         return(FILEERR) ;
  83.     }
  84.     if ((fd = fopen(fname, "w")) == NULL)
  85.     {
  86.         printf("FILE ERROR: wrtmeta, error in opening %s for output", fname) ;
  87.         return(FILEERR) ;
  88.     }
  89.     /* write the one off data */
  90.     ret = putf(fd, itemlist->mydata->mypath) ;
  91.     if (ret == FILEERR)
  92.     {
  93.         printf("FILE ERROR: wrtmeta, error in writting my path to %s", fname) ;
  94.         fclose(fd) ;
  95.         return(FILEERR) ;
  96.     }
  97.     ret = putf(fd, itemlist->mydata->myaddr) ;
  98.     if (ret == FILEERR)
  99.     {
  100.         printf("FILE ERROR: wrtmeta, error in writting my address to %s", fname) ;
  101.         fclose(fd) ;
  102.         return(FILEERR) ;
  103.     }
  104.     while(itemlist != NULL)
  105.     {
  106.         ret = wrthdr(fd, itemlist) ;
  107.         if (ret == FILEERR)
  108.             break ;
  109.         itemlist = itemlist->next ;
  110.     }
  111.     if (ret == FILEERR)
  112.     {
  113.         printf("FILE ERROR: wrtmeta, error in writting record to %s", fname) ;
  114.         fclose(fd) ;
  115.         return(FILEERR) ;
  116.     }
  117.     ret = putf(fd, "END") ;
  118.     if (ret == FILEERR)
  119.     {
  120.         printf("FILE ERROR: wrtmeta, error in writting terminator (END) to %s", fname) ;
  121.         fclose(fd) ;
  122.         return(FILEERR) ;
  123.     }
  124.     fclose(fd) ;
  125.     return(TRUE) ;
  126. }
  127.  
  128. /* read the from, subject and return path etc from the data file */
  129. readhdr(fd, itemlist)
  130. FILE * fd;
  131. struct ll * itemlist;
  132. {
  133.     struct ll * newll ;
  134.     char datafile[20] ;
  135.     char to[100] ;
  136.     char from[100] ;
  137.     char subject[100];
  138.     char cc[100];
  139.     char bcc[100];
  140.     char cread[100] ;
  141.     int read, ret ;
  142.     if (mtadbg == TRUE)
  143.         printf("CALL: readhdr(fd = OMITTED, itemlist = OMITTED)");
  144.     /* read in an entry */
  145.     ret = getf(fd, datafile) ;
  146.     if (ret == FILEERR)
  147.     {
  148.         printf("FILE ERROR: readhdr, error in reading datafile") ;
  149.         return(FILEERR) ;
  150.     }
  151.     if (strcmp(datafile, "END") == 0)
  152.         return(FALSE) ;
  153.     ret = getf(fd, to) ;
  154.     if (ret == FILEERR)
  155.     {
  156.         printf("FILE ERROR: readhdr, error in reading to") ;
  157.         return(FILEERR) ;
  158.     }
  159.     ret = getf(fd, from) ;
  160.     if (ret == FILEERR)
  161.     {
  162.         printf("FILE ERROR: readhdr, error in reading from") ;
  163.         return(FILEERR) ;
  164.     }
  165.     ret = getf(fd, subject) ;
  166.     if (ret == FILEERR)
  167.     {
  168.         printf("FILE ERROR: readhdr, error in reading subject") ;
  169.         return(FILEERR) ;
  170.     }
  171.     ret = getf(fd, cc) ;
  172.     if (ret == FILEERR)
  173.     {
  174.         printf("FILE ERROR: readhdr, error in reading cc") ;
  175.         return(FILEERR) ;
  176.     }
  177.     ret = getf(fd, bcc) ;
  178.     if (ret == FILEERR)
  179.     {
  180.         printf("FILE ERROR: readhdr, error in reading bcc") ;
  181.         return(FILEERR) ;
  182.     }
  183.     ret = getf(fd, cread) ;
  184.     if (ret == FILEERR)
  185.     {
  186.         printf("FILE ERROR: readhdr, error in reading read") ;
  187.         return(FILEERR) ;
  188.     }    
  189.     if (cread[0] == 'R')
  190.         read = RD ;
  191.     else
  192.         read = NEW ;
  193.     
  194.     /* get a new ll structure */
  195.     newll = llnew ();
  196.     /* fill in the structure */
  197.     llfill(newll, datafile, to, from, subject, cc, bcc, ACTIVE, read, itemlist->count + 1) ;
  198.     /* add the new item into the list */
  199.     lladd(newll, itemlist) ;
  200.     return(TRUE) ;
  201. }
  202. /* write a subject and destination etc to the data file */
  203. wrthdr(fd,item)
  204. FILE * fd;
  205. struct ll * item;
  206. {
  207.     int ret ;
  208.     if (mtadbg == TRUE)
  209.         printf("CALL: wrthdr(fd = OMITTED, item = OMITTED)");
  210.     /* only outut the record if its active */
  211.     if (item->status != ACTIVE)
  212.         return(TRUE) ;
  213.     ret = putf(fd, item->datafile);
  214.     if ( ret == FILEERR)
  215.     {
  216.         printf("FILE ERROR: wrthdr, error in writting datafile (%s)", item->datafile) ;
  217.         return(FILEERR) ;
  218.     }
  219.     ret = putf(fd, item->to) ;
  220.     if ( ret == FILEERR)
  221.     {
  222.         printf("FILE ERROR: wrthdr, error in writting to (%s)", item->to) ;
  223.         return(FILEERR) ;
  224.     }
  225.     ret = putf(fd, item->from) ;
  226.     if ( ret == FILEERR)
  227.     {
  228.         printf("FILE ERROR: wrthdr, error in writting from (%s)", item->from) ;
  229.         return(FILEERR) ;
  230.     }
  231.     ret = putf(fd, item->subject) ;
  232.     if ( ret == FILEERR)
  233.     {
  234.         printf("FILE ERROR: wrthdr, error in writting subject (%s)", item->subject) ;
  235.         return(FILEERR) ;
  236.     }
  237.     ret = putf(fd, item->cc) ;
  238.     if ( ret == FILEERR)
  239.     {
  240.         printf("FILE ERROR: wrthdr, error in writting cc (%s)", item->cc) ;
  241.         return(FILEERR) ;
  242.     }
  243.     ret = putf(fd, item->bcc) ;
  244.     if ( ret == FILEERR)
  245.     {
  246.         printf("FILE ERROR: wrthdr, error in writting bcc (%s)", item->bcc) ;
  247.         return(FILEERR) ;
  248.     }
  249.     if (item->read == RD)
  250.         ret = putf(fd, "R") ;
  251.     else
  252.         ret = putf(fd, "N") ;
  253.     if ( ret == FILEERR)
  254.     {
  255.         printf("FILE ERROR: wrthdr, error in writting read (%s)", item->read == RD ? "R" : "N") ;
  256.         return(FILEERR) ;
  257.     }
  258.     return(TRUE) ;
  259. }
  260. /* end of meta file operations code */
  261.  
  262. /* start of ancillary file and keyboard IO code */
  263. /* read a line of text from file handle */
  264. getf(fd, line)
  265. FILE * fd;
  266. char * line;
  267. {
  268.     char *ret ;
  269.     if (ancdbg == TRUE)
  270.         printf("CALL: getf(fd = OMITTED, line = OMITTED)");
  271.     if (fgets(line, 1024, fd) == NULL)
  272.         return(FILEERR) ;
  273.     /* remove the newline */
  274.     if ((int) strlen(line) > 0)
  275.         if (line[strlen(line)-1] == '\n')
  276.             line[strlen(line) -1] = '\0' ;
  277.     if (ancdbg == TRUE)
  278.     {
  279.         printf("line is :%s:", line) ;
  280.     }
  281.  
  282.     return(TRUE) ;
  283. }
  284. /* write a line of text to file handle */
  285. putf(fd, line)
  286. FILE * fd;
  287. char * line;
  288. {
  289.     int ret ;
  290.     if (ancdbg == TRUE)
  291.         printf("CALL: putf (fd = OMITTED, line = %s)", line) ;
  292.     ret = fprintf(fd, "%s\n", line) ;
  293.     if (ret < 0)
  294.         return(FILEERR) ;
  295.     if (ancdbg == TRUE)
  296.     {
  297.         printf("ret is %d, line is :%s:", ret, line) ;
  298.     }
  299.     return(TRUE) ;
  300. }
  301. E 1
  302.