home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / _ / 7plus / !Send7+ / c / send7+ < prev   
Text File  |  1995-06-23  |  12KB  |  518 lines

  1. /* ------------------------------------------------------------    */
  2. /* Send7+.c    Major re-write of the utility that was lost    */
  3. /*        during a hard disk backup in Aug 93        */
  4. /* ------------------------------------------------------------    */
  5. /* Purpose    Make 7+ files mail-files transmittable by !TCPIP*/
  6. /* Author    Rainer Schubert, DL6HBO                */
  7. /* Copyright    © 1993 by DL6HBO, free for non-commercial copy-    */
  8. /*        ing and use as long as this message is retained.*/
  9. /* Date        05-Sep-1993 07:23:43                */
  10. /* Last edited    13-Sep-1993 16:01:09                           */
  11. /* New version    26-Dec-1993 11:48:46 adapt to DB0HHT & WAMPES    */
  12. /* New version  29-Jan-1995 10:50:20 adapt for systems without  */
  13. /*             !BM and ALIAS files.                               */
  14. /* New version    18-Jun-1995 11:45:23 corrected Date&Time bug    */
  15. /*             on RiscPC with RO 3.5                        */
  16. /* Last edited    23-Jun-1995 09:33:44 CET            */
  17. /* ------------------------------------------------------------    */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <time.h>
  22. #include <ctype.h>
  23. #include "os.h"
  24.  
  25. /* #define DEBUG    1 */
  26. /* #define WAMPES    0*/    /* Use WAMPES's mailing convention for mail     */
  27.             /* addressed to 'boards' like 'archim@eu'    */
  28. #define NO_BM    1    /* Adapt for systems NOT using !BM & ALIAS    */
  29.  
  30. char path[FILENAME_MAX], textpath[FILENAME_MAX], workpath[FILENAME_MAX];
  31. char lockpath[FILENAME_MAX], sevenplus[FILENAME_MAX];
  32. #ifndef NO_BM
  33. char bmpath[FILENAME_MAX], aliaspath[FILENAME_MAX];
  34. #endif
  35. char hostname[FILENAME_MAX], callsign[10];
  36. char receiver[80], receiverpath[256];
  37. char infile[FILENAME_MAX];
  38.  
  39. int parts, partscnt, quit;
  40.  
  41. long seq;
  42.  
  43. struct tm *tp;
  44. time_t *ttp;
  45. int tttp[2];
  46.  
  47. #ifndef WAMPES
  48. const char version[] ="Send7Plus 0.5";
  49. #else
  50. const char version[] ="Send7Plus 0.6 WAMPES";
  51. #endif
  52. const char copyr[] ="© 1993-95 by DL6HBO";
  53.  
  54. /* replace terminating end of line marker(s) with null */
  55. void rip(register char *s)
  56. {
  57.   for (; *s; s++)
  58.     if (*s == '\r' || *s == '\n') {
  59.       *s = '\0';
  60.       break;
  61.     }
  62. }
  63.  
  64. char *readvar(char *s)
  65. {
  66.     char *c;
  67.     if ((c = getenv(s)) == NULL)
  68.        printf("System variable %s not found\n",s);
  69.  
  70.     return c;
  71. }
  72.  
  73. char *fn_tolower(char *any)
  74. {
  75.     char *p;
  76.  
  77.     p = any;
  78.     while ( *p++ != '\0')
  79.        tolower(*p);
  80.  
  81.     return any;
  82. }
  83.  
  84. int process(FILE *infil,int witch,char *search,long sequence)
  85. {
  86.     FILE *msgfile, *wrkfile;
  87.     char msgfilename[FILENAME_MAX], wrkfilename[FILENAME_MAX];
  88.     char from[80], to[80], mesid[80], date[90], mstime[81], sender[80];
  89.     char reply_to[80], subject[80], x_mail[80], ln[132];
  90.     char *p;
  91.  
  92.     sprintf(from,"%s","From: ");
  93.     rip(receiverpath);
  94.     sprintf(to,"To: %s",receiverpath);
  95.  
  96. #ifdef DEBUG
  97.     puts(to);
  98.     putchar('\n');
  99. #endif
  100.     sprintf(date,"%s","Date: ");
  101.     tttp[0] = 3;
  102.         os_word(14,tttp);
  103.     printf("%d\n",time((time_t *)tttp));
  104.     printf("%s",asctime(gmtime((time_t *)tttp)));
  105.     printf("%s",ctime((time_t *)tttp));
  106.            strftime(mstime, 80, "%a, %d %b %H:%M:%S %Y %Z",gmtime((time_t *)tttp));
  107.     strcat(date,mstime);
  108. #ifdef DEBUG
  109.     puts(date);
  110.     putchar('\n');
  111. #endif
  112.     sprintf(mesid,"Message-Id: <%ld@%s>",sequence,hostname);
  113.     sprintf(reply_to,"Reply-To: %s@%s",fn_tolower(callsign),hostname);
  114. #ifdef DEBUG
  115.     puts(mesid);
  116.     putchar('\n');
  117.     puts(reply_to);
  118.     putchar('\n');
  119. #endif
  120.     if (parts == 1) {
  121. #ifndef WAMPES
  122.        sprintf(subject,"Subject: %s.%s",infile,"7pl");
  123. #else
  124.        sprintf(subject,"Subject: [%s] %s.%s",receiverpath,infile,"7pl");
  125. #endif
  126.     }
  127.     else {
  128. #ifndef WAMPES
  129.        sprintf(subject,"Subject: %s.p%02X of %02X",infile,partscnt,parts);
  130. #else
  131.        sprintf(subject,"Subject: [%s] %s.p%02X of %02X",receiverpath,infile,partscnt,parts);
  132. #endif
  133.     }
  134. #ifdef DEBUG
  135.     puts(subject);
  136.     putchar('\n');
  137. #endif
  138.     sprintf(x_mail,"%s%s %s","X-Mailer: ",version,copyr);
  139. #ifdef DEBUG
  140.     puts(x_mail);
  141.     putchar('\n');
  142. #endif
  143.     printf("Processing file %s part %02X\n",infile,partscnt);
  144.  
  145.     sprintf(msgfilename,"%s%d",textpath,(int)sequence);
  146. #ifdef DEBUG
  147.     puts(msgfilename);
  148.     putchar('\n');
  149. #endif
  150.     if ((msgfile = fopen(msgfilename,"w")) == NULL) {
  151.        printf("Unable to write to %s\n",msgfilename);
  152.        return -1;
  153.     }
  154.     sprintf(wrkfilename,"%s%d",workpath,(int)sequence);
  155. #ifdef DEBUG
  156.     puts(wrkfilename);
  157.     putchar('\n');
  158. #endif
  159.     if ((wrkfile = fopen(wrkfilename,"w")) == NULL) {
  160.        printf("Unable to write to %s\n",wrkfilename);
  161.        return -1;
  162.     }
  163.     rip(from);
  164.     rip(date);
  165.     rip(mesid);
  166.     rip(callsign);
  167.     rip(hostname);
  168.     fprintf(msgfile,"%s\n",date);
  169.     fprintf(msgfile,"%s\n",mesid);
  170.     fprintf(msgfile,"%s%s%s%s\n",from,fn_tolower(callsign),"@",hostname);
  171.  
  172.     if (strlen(from) > 6) {
  173.        p = strchr(from,' ');
  174.        if (*p) strcpy(sender, ++p);
  175.     }
  176.  
  177.     rip(reply_to);
  178.     rip(sender);
  179.     rip(to);
  180.     rip(subject);
  181.     rip(x_mail);
  182.     strcpy(sender,fn_tolower(sender));
  183.     fprintf(msgfile,"%s\n",reply_to);
  184.     fprintf(msgfile,"%s\n",to);
  185.     fprintf(msgfile,"%s\n",subject);
  186.     fprintf(msgfile,"%s\n\n",x_mail);
  187.  
  188.     if ((p = strchr(receiverpath,'@')) != NULL) {
  189.                fprintf(wrkfile,"%s\n",++p);
  190.            } else {
  191.                fprintf(wrkfile,"%s\n",receiverpath);
  192.            }
  193.  
  194.     fprintf(wrkfile,"%s@%s\n",fn_tolower(callsign),hostname);
  195. #ifndef WAMPES
  196.     fprintf(wrkfile,"%s\n",receiverpath);
  197. #else
  198.     fprintf(wrkfile,"%s\n","bbs@db0hht"); /* edit this NODE's callsign */
  199. #endif
  200.     fclose(wrkfile);
  201.  
  202.     rewind(infil);
  203.  
  204.     fgets(ln,132,infil);
  205.     while (!feof(infil)) {
  206.       fprintf(msgfile,"%s",ln);
  207.       fgets(ln,132,infil);
  208.     }
  209.     fclose(msgfile);
  210.     return 0;
  211. }
  212.  
  213. long get_sequence(void)
  214. {
  215.     FILE *sequf;
  216.     char sequen[20], filenam[FILENAME_MAX];
  217.  
  218.     sprintf(filenam,"%s%s",path,"sequence");
  219.     if ((sequf = fopen(filenam,"r")) != NULL) {
  220.        fgets(sequen,19,sequf);
  221.        fclose(sequf);
  222.        printf("Sequence no. %s\n",sequen);
  223.        return atol(sequen);
  224.     }
  225.     return 0;
  226. }
  227.  
  228. int exists(char *any)
  229. {
  230.     FILE *file;
  231. #ifdef DEBUG
  232.     printf("Does file %s exist ?",any);
  233. #endif
  234.     if ((file = fopen(any,"r")) !=(FILE *) NULL) {
  235. #ifdef DEBUG
  236.        puts(" Yes !\n");
  237. #endif
  238.        fclose(file);
  239.        return 1;
  240.     }
  241. #ifdef DEBUG
  242.        puts(" No !\n");
  243. #endif
  244.     return 0;
  245. }
  246.  
  247. int key(void)
  248. {
  249.     int c;
  250.  
  251.     printf("Press any key to continue......\n");
  252.     c = getchar();
  253.     return c;
  254. }
  255.  
  256. char *filename(char *fi,int pts)
  257. {
  258.     char fo[FILENAME_MAX], fa[FILENAME_MAX];
  259.     char pa[6];
  260.  
  261.     if (pts == 1) {
  262.        sprintf(fo,"%s.%s.%s",fi,"7pl","7pl");
  263.        if (! exists(fo)) {
  264.           strcpy(fa,fi);
  265.           strcat(fa,".p");
  266.           sprintf(pa,"%02X",pts);
  267.           pa[1] = '\0';
  268.           strcat(fa,pa);
  269.           pa[0] = '\0';
  270.           sprintf(pa,"_.p%02X",pts);
  271.           strcat(fa,pa);
  272.           return(fa);
  273.        }
  274.        return fo;
  275.     }
  276.     else {
  277.        strcpy(fa,fi);
  278.        strcat(fa,".p");
  279.        sprintf(pa,"%02X",pts);
  280.        pa[1] = '\0';
  281.        strcat(fa,pa);
  282.        pa[0] = '\0';
  283.        sprintf(pa,"_.p%02X",pts);
  284.        strcat(fa,pa);
  285.        return fa;
  286.     }
  287. }
  288.  
  289. int get_parts(char *file, int parts)
  290. {
  291.     char localfname[FILENAME_MAX];
  292.     char localpart[6];
  293.  
  294.     sprintf(localfname,"%s.%s",file,"7pl.7pl");
  295.     if (exists(localfname)) {
  296.        return 1;
  297.     }
  298.     else {
  299.        do {
  300.           sprintf(localfname,"%s.p",file);
  301.           sprintf(localpart,"%02X",parts);
  302.           localpart[1] = '\0';
  303.           strcat(localfname,localpart);
  304.           localpart[0] = '\0';
  305.           sprintf(localpart,"_.p%02X",parts);
  306.           strcat(localfname,localpart);
  307.           parts++;
  308.           }
  309.        while (exists(localfname));
  310.        --parts;
  311.     }
  312.     return (--parts);
  313. }
  314.  
  315. #ifndef NO_BM
  316. char *scan_alias(char *name, char *look_up)
  317. {
  318.     FILE *file;
  319.     char *pos, line[80], mypath[80];
  320.  
  321.     if (strchr(look_up,'@') == NULL) {
  322.         line[0] = '\0';
  323.         mypath[0] = '\0';
  324.         pos = (char *)0;
  325.  
  326.         if ((file = fopen(name,"r")) == NULL) {
  327.              printf("Unable to open file %s\n",name);
  328.              return pos;
  329.         }
  330.         do {
  331.            fgets(line,79,file);
  332.            if (line[0] != '#')
  333.                pos = strstr(line,look_up);
  334.         } while ((pos == NULL) && (! feof(file)));
  335.         fclose(file);
  336.         if (pos != NULL) {
  337.             pos += strlen(look_up);
  338.             pos++;
  339.             while (isspace(*pos))
  340.                 pos++;
  341.             strcpy(mypath,pos);
  342.         }
  343.         return mypath;
  344.     }
  345.     return look_up;
  346. }
  347. #endif
  348.  
  349. int main()
  350. {
  351.     char *p;
  352.     char search1[10];
  353.     char line[132];
  354.  
  355.     int found;
  356.  
  357.     FILE *inf, *seqf;
  358.  
  359.     strcpy(path,readvar("Mail$Dir"));
  360.     strcat(path,".spool.mqueue.");
  361.     strcpy(textpath,path);
  362.     strcat(textpath,"text.");
  363.     strcpy(workpath,path);
  364.     strcat(workpath,"work.");
  365.     strcpy(lockpath,path);
  366.     strcat(lockpath,"lock.");
  367.     strc