uuenview.c
来自「UUDeview是一个编码解码器」· C语言 代码 · 共 1,348 行 · 第 1/3 页
C
1,348 行
else if (_FP_strnicmp (input, "To:", 3) == 0) { if (towhom && isemail && rcptlist) { fprintf (thepipe, "To: %s\n", rcptlist); } else { fprintf (thepipe, "%s", input); } hadto = 1; } else if (_FP_strnicmp (input, "From:", 5) == 0) { if (from) { fprintf (thepipe, "From: %s\n", from); } else { fprintf (thepipe, "%s", input); } hadfrom = 1; } else if (_FP_strnicmp (input, "Reply-To:", 9) == 0) { if (replyto) { fprintf (thepipe, "Reply-To: %s\n", replyto); } else { fprintf (thepipe, "%s", input); } hadreplyto = 1; } else if (_FP_strnicmp (input, "Mime-Version:", 13) == 0) { fprintf (thepipe, "%s", input); hadmime = 1; } else if (_FP_strnicmp (input, "Content-Type:", 13) == 0) { if (_FP_stristr (input, "multipart") != NULL) { /* it is already a multipart posting. grab the boundary */ if ((ptr = _FP_stristr (input, "boundary=")) != NULL) { fprintf(thepipe, input); strcpy (boundary, ParseValue (ptr)); hadmulti = 1; } } else { /* * save content-type for later, must be only one line! */ ctype = _FP_strdup (input); } } else if (_FP_strnicmp (input, "Content-Transfer-Encoding:", 26) == 0) { /* * save for later, must be only one line */ cte = _FP_strdup (input); } else { /* * just copy header line */ fprintf (thepipe, "%s", input); } } /* * okay, header is copied. add our own fields if necessary */ if (!hadmime && encoding != YENC_ENCODED) fprintf (thepipe, "Mime-Version: 1.0\n"); if (!hadmulti && encoding != YENC_ENCODED) { /* must invent a boundary */ sprintf (boundary, "==UUD_=_%ld", (long) time (NULL)); fprintf (thepipe, "Content-Type: multipart/mixed; boundary=\"%s\"\n", boundary); } /* * huh, there have been no headers. */ if (!hadfrom && from) { fprintf (thepipe, "From: %s\n", from); } if (!hadgroups && towhom && !isemail && rcptlist) { fprintf (thepipe, "Newsgroups: %s\n", rcptlist); } if (!hadto && towhom && isemail && rcptlist) { fprintf (thepipe, "To: %s\n", rcptlist); } if (!hadreplyto && replyto) { fprintf (thepipe, "Reply-To: %s\n", replyto); } if (!hadsubject && subject) { fprintf (thepipe, "Subject: %s\n", subject); } /* * end headers */ fprintf (thepipe, "\n"); /* * okay, copy text if available */ if (!feof (stdin) && index > 0) { ptr = _FP_fgets (input, 1024, stdin); } else { ptr = input; } if (!feof (stdin) && ptr) { if (!hadmulti && encoding != YENC_ENCODED) { /* * need our own header */ fprintf (thepipe, "--%s\n", boundary); if (ctype) { fprintf (thepipe, "%s", ctype); } else { fprintf (thepipe, "Content-Type: text/plain\n"); } if (cte) { fprintf (thepipe, "%s", cte); } else { fprintf (thepipe, "Content-Transfer-Encoding: 8bit\n"); } fprintf (thepipe, "\n"); /* * just copy stdin */ fprintf (thepipe, "%s", input); while (!feof (stdin)) { if (_FP_fgets (input, 256, stdin) == NULL) break; fprintf (thepipe, "%s", input); } /* * the last crlf is to be ignored, so add another one */ fprintf (thepipe, "\n"); } else { /* * this was already a multipart/mixed posting, copy everything up * to the final boundary */ while (!feof (stdin)) { if (_FP_fgets (input, 256, stdin) == NULL) break; if (input[0] == '-' && input[1] == '-' && strncmp (input+2, boundary, strlen (boundary)) == 0 && input[strlen(boundary)+2] == '-' && input[strlen(boundary)+3] == '-') break; fprintf (thepipe, "%s", input); } } } /* * okay, so let's finally make our attachments */ for (index=1; index<argc; index++) { if (*argv[index] == '-' && argv[index][1] != '\0') { switch (argv[index][1]) { case 'm': /* skip parameters of options */ case 'p': case 's': case 'i': case 'f': case 'r': if (index+1 < argc && argv[index+1][0] != '-') index++; break; case 'o': /* may or may have not a parameter */ if (argv[index][2]=='d' && index+1<argc && argv[index+1][0]!='-') index++; break; case 'b': encoding = B64ENCODED; break; case 'u': encoding = UU_ENCODED; break; case 'x': encoding = XX_ENCODED; break; case 't': encoding = PT_ENCODED; break; case 'q': encoding = QP_ENCODED; break; case 'y': encoding = YENC_ENCODED; break; default: /* parameter without option */ break; } } else /* this is a filename */ { /* * new boundary */ if (encoding != YENC_ENCODED) { fprintf (thepipe, "--%s\n", boundary); } if ((res = UUEncodeMulti (thepipe, NULL, argv[index], encoding, NULL, NULL, 0)) != UURET_OK) { fprintf (stderr, "error while attaching %s: %s %s\n", argv[index], UUstrerror (res), (res==UURET_IOERR)? strerror (UUGetOption (UUOPT_ERRNO, NULL, NULL, 0)) : ""); } fprintf (thepipe, "\n"); } } /* * done. */ if (encoding != YENC_ENCODED) { fprintf (thepipe, "--%s--\n\n", boundary); } if (towhom) {#ifdef HAVE_POPEN pclose (thepipe); _FP_free (rcptlist); _FP_free (command);#endif } _FP_free (ctype); _FP_free (cte); /* phew */ return UURET_OK;}/* * Mail or Post a file. Remember to keep in sync with uutcl.c */static intSendAFile (FILE *infile, char *infname, int encoding, int linperfile, char *outfname, char *towhom, char *subject, char *from, char *replyto, int isemail){ char *command, *rcptlist; FILE *thepipe, *theifile; int res, part; if (towhom==NULL || (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { fprintf (stderr, "oops: Parameter check failed in SendAFile()\n"); return UURET_ILLVAL; }#ifndef HAVE_POPEN fprintf (stderr, "error: Your system does not support %s of files\n", (isemail)?"mailing":"posting"); return UURET_ILLVAL;#else if ((command = SendMkCommand (&rcptlist, towhom, subject, isemail)) == NULL) { return UURET_ILLVAL; } /* * Get going ... */ if (infile == NULL) { if ((theifile = fopen (infname, "rb")) == NULL) { fprintf (stderr, "error: Could not open input file %s: %s\n", infname, strerror (errno)); _FP_free (rcptlist); _FP_free (command); return UURET_IOERR; } } else { theifile = infile; } for (part=1; !feof (theifile); part++) { if ((thepipe = popen (command, "w")) == NULL) { fprintf (stderr, "error: could not open pipe %s\n", command); if (infile==NULL) fclose (theifile); _FP_free (rcptlist); _FP_free (command); return UURET_IOERR; }#if 0 if (UUGetOption(UUOPT_VERBOSE, NULL, NULL, 0)) { fprintf (stderr, "%s part %03d of %s to %s ... ", (isemail)?"mailing":"posting", part, (infname)?infname:outfname, rcptlist); fflush (stderr); }#endif res = UUE_PrepPartialExt (thepipe, theifile, infname, encoding, outfname, 0, part, linperfile, 0, rcptlist, from, subject, replyto, isemail);#if 0 if (UUGetOption (UUOPT_VERBOSE, NULL, NULL, 0)) { if (res == UURET_OK) fprintf (stderr, "ok.\n"); else fprintf (stderr, "%s\n", UUstrerror (res)); }#endif pclose (thepipe); if (res != UURET_OK) { if (infile == NULL) fclose (theifile); _FP_free (rcptlist); _FP_free (command); return res; } } if (infile == NULL) fclose (theifile); _FP_free (rcptlist); _FP_free (command); return UURET_OK;#endif}/* * main function from uuenview */intmain (int argc, char *argv[]){ int outflags[5], tostdout, linperfile, uuencode, encoding; int index, subject, count, fileflag, stdinused; int from, replyto; char filename[512], usename[512], outdir[512]; int iskipflag, attach, files; char *p1, *myargv[256]; int myargc, quote; FILE *testit; /* * set defaults */ outflags[UUE_TOFILE] = -1; outflags[UUE_MAILTO] = -1; outflags[UUE_POSTTO] = -1; subject = -1; tostdout = 1; linperfile = 0; uuencode = 0; encoding = -1; count = 0; stdinused = 0; attach = 0; files = 0; from = -1; replyto = -1; if (UUInitialize () != UURET_OK) { fprintf (stderr, "oops: could not initialize decoding library\n"); return 2; } UUSetOption (UUOPT_VERBOSE, 0, NULL);#if defined(SYSTEM_DOS) || defined(SYSTEM_QUICKWIN) UUSetFNameFilter (NULL, UUFNameFilterDOS);#else UUSetFNameFilter (NULL, UUFNameFilterUnix);#endif /* * Setup Callback */ UUSetMsgCallback (NULL, MessageCallback); UUSetBusyCallback (NULL, BusyCallback, 100); /* * OK to overwrite target files */ UUSetOption (UUOPT_OVERWRITE, 1, NULL); if (argc < 2) { usage (argv[0]); return 1; } /* * In DOS, the default is to create files, not to send it to stdout */#ifdef SYSTEM_DOS outflags[UUE_TOFILE] = -42; /* MAGIC */ tostdout = 0;#endif /* * Check for environment variable called INEWS and override * compile-time option if present */ if (getenv ("INEWS") && *(char *)getenv ("INEWS")) { uue_inewsprog = getenv ("INEWS"); } /* * Check for environment variable called UUENVIEW and read it */ myargc = 1; myargv[0] = argv[0]; if ((p1 = (char *) getenv ("UUENVIEW"))) { myargv[myargc++] = p1; quote = 0; while (*p1 && myargc < 255) { switch (*p1) { case ' ': case '\t': if (!quote) { if ((*myargv[myargc-1] == '"' || *myargv[myargc-1] == '\'') && p1-1 != myargv[myargc-1] && *(p1-1) == *myargv[myargc-1]) { *(p1-1) = '\0'; myargv[myargc-1] += 1; } *p1++ = '\0'; while (*p1 == ' ' || *p1 == '\t')
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?