uucheck.c

来自「UUDeview是一个编码解码器」· C语言 代码 · 共 1,469 行 · 第 1/3 页

C
1,469
字号
  /*   * look for the string "part" followed by a number   */  if (length == 0) {    if ((iter = _FP_stristr (subject, "part")) != NULL) {      iter += 4;      while (isspace (*iter) || *iter == '.' || *iter == '-')	iter++;      while (isdigit (iter[length]))        length++;      if (length == 0) {	if (_FP_strnicmp (iter, "one", 3) == 0)        length = 1;	else if (_FP_strnicmp (iter, "two", 3) == 0)   length = 2;	else if (_FP_strnicmp (iter, "three", 5) == 0) length = 3;	else if (_FP_strnicmp (iter, "four",  4) == 0) length = 4;	else if (_FP_strnicmp (iter, "five",  4) == 0) length = 5;	else if (_FP_strnicmp (iter, "six",   3) == 0) length = 6;	else if (_FP_strnicmp (iter, "seven", 5) == 0) length = 7;	else if (_FP_strnicmp (iter, "eight", 5) == 0) length = 8;	else if (_FP_strnicmp (iter, "nine",  4) == 0) length = 9;	else if (_FP_strnicmp (iter, "ten",   3) == 0) length = 10;	if (length && (*whend = strchr (iter, ' '))) {	  *where = iter;	  return length;	}	else	  length = 0;      }      else {	*where = iter;	delim  = "of";      }    }  }  /*   * look for [0-9]* "of" [0-9]*   */  if (length == 0) {    if ((iter = _FP_strirstr (subject, "of")) != NULL) {      while (iter>subject && isspace (*(iter-1)))	iter--;      if (isdigit(*(iter-1))) {	while (iter>subject && isdigit (*(iter-1)))	  iter--;	if (!isdigit (*iter) && !isalpha (*iter) && *iter != '.')	  iter++;	ptr = iter;	while (isdigit (*ptr)) {	  ptr++; length++;	}	*where = iter;	delim  = "of";      }    }  }  /*   * look for whitespace-separated (or '/'-separated) digits   */  if (length == 0) {    ptr = subject;    while (*ptr && length==0) {      while (*ptr && !isdigit (*ptr))	ptr++;      if (isdigit (*ptr) && (ptr==subject || *ptr==' ' || *ptr=='/')) {	while (isdigit (ptr[length]))	  length++;	if (ptr[length]!='\0' && ptr[length]!=' ' && ptr[length]!='/') {	  ptr   += length;	  length = 0;	}	else {	  iter    = ptr;	  bdel[0] = ptr[length];	  delim   = bdel;	}      }      else {	while (isdigit (*ptr))	  ptr++;      }    }  }  /*   * look for _any_ digits -- currently disabled, because it also fell   * for "part numbers" in file names   */#if 0  if (length == 0) {    count = strlen(subject) - 1;    ptr   = subject;     while (count > 0) {      if (!isdigit(ptr[count])||isalpha(ptr[count+1])||ptr[count+1] == '.') {	count--;	continue;      }      length = 0;      while (count >= 0 && isdigit (ptr[count])) {	count--; length++;      }      if (count>=0 && ((isalpha (ptr[count]) && 			(ptr[count] != 's' || ptr[count+1] != 't') &&			(ptr[count] != 'n' || ptr[count+1] != 'd')) || 		       ptr[count] == '/' || ptr[count] == '.' || 		       ptr[count] == '-' || ptr[count] == '_')) {        length = 0;        continue;      }      count++;      iter = ptr + count;      if (length > 4) {	length = 0;	continue;      }      *where = iter;      delim  = "of";      break;    }  }#endif  /*   * look for part numbering as string   */  if (length == 0) {    /*     * some people use the strangest things, including spelling mistakes :-)     */    if ((iter = _FP_stristr (subject, "first")) != NULL)        length = 1;    else if ((iter = _FP_stristr (subject, "second")) != NULL)  length = 2;    else if ((iter = _FP_stristr (subject, "third")) != NULL)   length = 3;    else if ((iter = _FP_stristr (subject, "forth")) != NULL)   length = 4;    else if ((iter = _FP_stristr (subject, "fourth")) != NULL)  length = 4;    else if ((iter = _FP_stristr (subject, "fifth")) != NULL)   length = 5;    else if ((iter = _FP_stristr (subject, "sixth")) != NULL)   length = 6;    else if ((iter = _FP_stristr (subject, "seventh")) != NULL) length = 7;    else if ((iter = _FP_stristr (subject, "eigth")) != NULL)   length = 8;    else if ((iter = _FP_stristr (subject, "nineth")) != NULL)  length = 9;    else if ((iter = _FP_stristr (subject, "ninth")) != NULL)   length = 9;    else if ((iter = _FP_stristr (subject, "tenth")) != NULL)   length = 10;    else iter = NULL;    if (length && iter && (*whend = strchr (iter, ' '))) {      *where = iter;      return length;    }    else      length = 0;  }  if (iter == NULL || length == 0)	/* should be equivalent */    return -1;  *where = iter;  if (delim && delim[0]) {    if ((*whend=_FP_stristr (iter, delim)) != NULL && (*whend - *where) < 12) {      ptr = (*whend += strlen (delim));      while (*ptr == ' ')	ptr++;      if (isdigit (*ptr)) {	*whend = ptr;	while (isdigit (**whend))	  *whend += 1;      }    }    else {      *whend = iter + length;    }  }  else {    *whend = iter + length;  }  return atoi (iter);}/* * Obtain and process some information about the data. **/uufile *UUPreProcessPart (fileread *data, int *ret){  char *where, *whend, temp[80], *ptr, *p2;  uufile *result;  if ((result = (uufile *) malloc (sizeof (uufile))) == NULL) {    UUMessage (uucheck_id, __LINE__, UUMSG_ERROR,	       uustring (S_OUT_OF_MEMORY), sizeof (uufile));    *ret = UURET_NOMEM;    return NULL;  }  memset (result, 0, sizeof (uufile));  if (data->partno) {    where = whend  = NULL;    result->partno = data->partno;  }  else if (uu_dumbness) {    result->partno = -1;    where = whend  = NULL;  }  else if ((result->partno=UUGetPartNo(data->subject,&where,&whend)) == -2) {    *ret = UURET_NODATA;    UUkillfile (result);    return NULL;  }  if (data->filename != NULL) {    if ((result->filename = _FP_strdup (data->filename)) == NULL) {      UUMessage (uucheck_id, __LINE__, UUMSG_ERROR,		 uustring (S_OUT_OF_MEMORY),		 strlen (data->filename)+1);      *ret = UURET_NOMEM;      UUkillfile (result);      return NULL;    }  }  else    result->filename = NULL;  if (uu_dumbness <= 1)    result->subfname = UUGetFileName (data->subject, where, whend);  else    result->subfname = NULL;  result->mimeid   = _FP_strdup (data->mimeid);  result->mimetype = _FP_strdup (data->mimetype);  if (result->partno == -1 &&       (data->uudet == PT_ENCODED || data->uudet == QP_ENCODED))    result->partno = 1;  if (data->flags & FL_SINGLE) {    /*     * Don't touch this part. But it should really have a filename     */    if (result->filename == NULL) {      sprintf (temp, "%s.%03d", nofname, ++nofnum);      result->filename = _FP_strdup (temp);    }    if (result->subfname == NULL)      result->subfname = _FP_strdup (result->filename);    if (result->filename == NULL || 	result->subfname == NULL) {      UUMessage (uucheck_id, __LINE__, UUMSG_ERROR,		 uustring (S_OUT_OF_MEMORY),		 (result->filename==NULL)?		 (strlen(temp)+1):(strlen(result->filename)+1));      *ret = UURET_NOMEM;      UUkillfile(result);      return NULL;    }    if (result->partno == -1)      result->partno = 1;  }  else if (result->subfname == NULL && data->uudet &&      (data->begin || result->partno == 1 ||        (!uu_dumbness && result->partno == -1 && 	(data->subject != NULL || result->filename != NULL)))) {    /*     * If it's the first part of something and has some valid data, but     * no subject or anything, initialize lastvalid     */    /*     * in this case, it really _should_ have a filename somewhere     */    if (result->filename != NULL && *result->filename)      result->subfname = _FP_strdup (result->filename);    else { /* if not, escape to UNKNOWN. We need to fill subfname */      sprintf (temp, "%s.%03d", nofname, ++nofnum);      result->subfname = _FP_strdup (temp);    }    /*     * in case the strdup failed     */    if (result->subfname == NULL) {      UUMessage (uucheck_id, __LINE__, UUMSG_ERROR,		 uustring (S_OUT_OF_MEMORY),		 (result->filename)?		 (strlen(result->filename)+1):(strlen(temp)+1));      *ret = UURET_NOMEM;      UUkillfile (result);      return NULL;    }    /*     * if it's also got an 'end', or is the last part in a MIME-Mail,     * then don't set lastvalid     */    if (!data->end && (!data->partno || data->partno != data->maxpno)) {      /*       * initialize lastvalid       */      lastvalid = 1;      lastenc   = data->uudet;      lastpart  = result->partno = 1;      _FP_strncpy (uucheck_lastname, result->subfname, 256);    }    else      result->partno = 1;  }  else if (result->subfname == NULL && data->uudet && data->mimeid) {    /*     * if it's got a file name, use it. Else use the mime-id for identifying     * this part, and hope there's no other files encoded in the same message     * under the same id.     */    if (result->filename)      result->subfname = _FP_strdup (result->filename);    else      result->subfname = _FP_strdup (result->mimeid);  }  else if (result->subfname == NULL && data->uudet) {    /*     * ff we have lastvalid, use it. Make an exception for     * Base64-encoded files.     */    if (data->uudet == B64ENCODED) {      /*       * Assume it's the first part. I wonder why it's got no part number?       */      if (result->filename != NULL && *result->filename)        result->subfname = _FP_strdup (result->filename);      else { /* if not, escape to UNKNOWN. We need to fill subfname */        sprintf (temp, "%s.%03d", nofname, ++nofnum);        result->subfname = _FP_strdup (temp);      }      if (result->subfname == NULL) {	UUMessage (uucheck_id, __LINE__, UUMSG_ERROR,		   uustring (S_OUT_OF_MEMORY),		   (result->filename)?		   (strlen(result->filename)+1):(strlen(temp)+1));	*ret = UURET_NOMEM;	UUkillfile (result);        return NULL;      }      lastvalid = 0;    }    else if (lastvalid && data->uudet == lastenc && result->partno == -1) {      result->subfname = _FP_strdup (uucheck_lastname);      result->partno   = ++lastpart;      /*       * if it's the last part, invalidate lastvalid       */      if (data->end || (data->partno && data->partno == data->maxpno))	lastvalid = 0;    }    else if (data->partno != -1 && result->filename) {      result->subfname = _FP_strdup (result->filename);    }    else {       /*        * it's got no info, it's got no begin, and we don't know anything       * about this part. Let's forget all about it.       */      *ret = UURET_NODATA;      UUkillfile (result);      return NULL;    }  }  else if (result->subfname == NULL && result->partno == -1) {    /*     * This, too, is a part without any useful information that we     * should forget about.     */    *ret = UURET_NODATA;    UUkillfile (result);    return NULL;  }  else if (result->subfname == NULL) {    /*     * This is a part without useful subject name, a valid part number     * but no encoded data. It *could* be the zeroeth part of something,     * but we don't care here. Just forget it.     */    *ret = UURET_NODATA;    UUkillfile (result);    return NULL;  }  /*   * now, handle some cases where we have a useful subject but no   * useful part number   */  if (result->partno == -1 && data->begin) {    /*     * hmm, this is reason enough to initialize lastvalid, at least      * if we have no end     */    if (!data->end) {      _FP_strncpy (uucheck_lastname, result->subfname, 256);      result->partno = lastpart = 1;      lastenc = data->uudet;      lastvalid = 1;    }    else      result->partno = 1;  }  else if (result->partno == -1 && data->uudet) {    if (lastvalid && _FP_stricmp (uucheck_lastname, result->subfname) == 0) {      /*       * if the subject filename is the same as last time, use part no       * of lastvalid. If at end, invalidate lastvalid       */      result->partno = ++lastpart;      if (data->end)	lastvalid = 0;    }    else {      /*       * data but no part no. It's something UUInsertPartToList() should       * handle       */      goto skipcheck;    }  }  else if (result->partno == -1) {    /*     * it's got no data, so why should we need this one anyway?     */    *ret = UURET_NODATA;    UUkillfile (result);    return NULL;  }  /*   * at this point, the part should have a valid subfname and a valid   * part number. If it doesn't, then fail.   */  if (result->subfname == NULL || result->partno == -1) {    *ret = UURET_NODATA;    UUkillfile (result);    return NULL;  } skipcheck:  if (result->filename) {    if (*(ptr = _FP_cutdir (result->filename))) {      p2 = _FP_strdup (ptr);      _FP_free (result->filename);      result->filename = p2;    }  }  result->data = data;  result->NEXT = NULL;  *ret = UURET_OK;  return result;}/* * Insert one part of a file into the global list **/intUUInsertPartToList (uufile *data){  uulist *iter = UUGlobalFileList, *unew;  uufile *fiter, *last;  /*   * Part belongs together, if   * (1) The MIME-IDs match, or   * (2) The file name received from the subject lines match, and

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?