home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / comm / bbs / eazybbs / source / mail2eazy.c < prev    next >
C/C++ Source or Header  |  1994-09-08  |  2KB  |  125 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8.  
  9.  
  10.  
  11. #define VERSION "1.2"
  12. static char *version = "\0$VER: mail2eazy " VERSION " (" __AMIGADATE__ ")";
  13.  
  14.  
  15.  
  16. void space2under(char *s)
  17. {
  18.     while (s && *s) {
  19.         if (*s == ' ')
  20.             *s = '_';
  21.         s++;
  22.     }
  23. }
  24.  
  25.  
  26.  
  27. void kill_quotes(char *s)
  28. {
  29.     while (s && *s) {
  30.         if (*s == '\"')
  31.             *s = '\'';
  32.         s++;
  33.     }
  34. }
  35.  
  36.  
  37.  
  38. int main(int argc, char *argv[])
  39. {
  40.     if (argc == 2) {
  41.         char tmp[80];
  42.         FILE *fp;
  43.  
  44.         sprintf(tmp, "%s%ld", "MB_TMP:Mail2Eazy.tmp", (long) FindTask(NULL));
  45.  
  46.         if (fp = fopen(tmp, "w")) {
  47.             register int c = 0;
  48.             char username[256];
  49.             char uucpadr[256];
  50.             char *to_user = argv[1];
  51.             char subject[256];
  52.             char exec[256];
  53.             char str[1024];
  54.             BOOL ende = FALSE;
  55.  
  56.             strcpy(username, "unknown");
  57.             strcpy(subject, "none");
  58.             strcpy(uucpadr, "");
  59.  
  60.             while (!ende && fgets(str, 1023, stdin)) {
  61.                 if (strlen(str) == 0 || strcmp(str, "\n") == 0)
  62.                     ende = TRUE;
  63.                 else if ((strnicmp(str, "From: ", 6) == 0 && strlen(uucpadr) == 0) || strnicmp(str, "Reply-To: ", 10) == 0) {
  64.                     char *p;
  65.                     char *str2;
  66.                     str2 = strstr(str, ": ") + 2;
  67.  
  68.                     strcpy(uucpadr, str2);
  69.                     kill_quotes(uucpadr);
  70.                     if (strchr(uucpadr, '\n'))
  71.                         *strchr(uucpadr, '\n') = 0;
  72.  
  73. #if 0
  74.                     strcpy(username, str2);
  75.                     p = username;
  76.                     while (*p && *p != '@') {
  77.                         p++;
  78.                     }
  79.                     if (*p == '@')
  80.                         *p = 0;
  81. #endif
  82.                     if (p = strchr(str2, '@')) {
  83.                         int pos;
  84.                         for (pos = 0, p--; p >= str2 && *p != ' ' && *p != '\t' && *p != '<'; p--)
  85.                             username[pos++] = *p;
  86.                         username[pos] = 0;
  87.                         strrev(username);
  88.                     }
  89.  
  90.                     if (strchr(username, '\n'))
  91.                         *strchr(username, '\n') = 0;
  92.                     username[15] = 0;
  93.                     kill_quotes(username);
  94.                 }
  95.                 else if (strncmp(str, "Subject: ", 9) == 0) {
  96.                     strcpy(subject, str + 9);
  97.                     kill_quotes(subject);
  98.                     if (strchr(subject, '\n'))
  99.                         *strchr(subject, '\n') = 0;
  100.                     subject[40] = 0;
  101.                 }
  102.             }
  103.  
  104.             while ((c = fgetc(stdin)) != EOF) {
  105.                 if (c == '\\')
  106.                     fputc('\\', fp);
  107.                 fputc(c, fp);
  108.             }
  109.             fprintf(fp, "\n");
  110.  
  111.             fclose(fp);
  112.  
  113.             sprintf(exec, "MB:C/ImportMail \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", username, to_user, uucpadr, subject, tmp);
  114.             System(exec, NULL);
  115.             DeleteFile(tmp);
  116.         }
  117.     }
  118.     else {
  119.         fprintf(stderr, "\033[1;33mEazyBBS\033[0m © 1988-1994 Andreas M. Kirchwitz\n"
  120.             "Usage: mail2eazy \033[3m<to> \033[0m <text\n");
  121.     }
  122.  
  123.     exit(0);
  124. }
  125.