StrAllocCopy(&work_buf, header);   StrAllocCopy(&retbuff, header);
mime_SACopy(&work_buf, header);   mime_SACopy(&retbuff, header);
char *intl_decode_mime_part2_str(const char *header, char* charset){  char *work_buf = NULL;  char *output_p = NULL;  char *retbuff = NULL;  char *p, *q, *decoded_text;  char *begin; /* tracking pointer for where we are in the work buffer */  int  ret = 0;  // initialize charset name to an empty string  if (charset)    charset[0] = '\0';  StrAllocCopy(&work_buf, header);  /* temporary buffer */  StrAllocCopy(&retbuff, header);  if (work_buf == NULL || retbuff == NULL)    return NULL;  output_p = retbuff;  begin = work_buf;  while (*begin != '\0')  {    char * output_text;    /*              GetCharset();           */    p = strstr(begin, "=?");    if (p == NULL)      break;                          /* exit the loop because the rest are not encoded */    *p = '\0';    /* skip strings don't need conversion */    strncpy(output_p, begin, p - begin);    output_p += p - begin;    p += 2;    begin = p;    q = strchr(p, '?');  /* Get charset info */    if (q == NULL)            break;                          /* exit the loop because there are no charset info */    *q++ = '\0';    if (charset)      PL_strcpy(charset, PL_strcasecmp(p, "us-ascii") ? p : "iso-8859-1");    if (*(q+1) == '?' &&        (*q == 'Q' || *q == 'q' || *q == 'B' || *q == 'b'))    {      p = strstr(q+2, "?=");      if(p != NULL)        *p = '\0';      if(*q == 'Q' || *q == 'q')        decoded_text = intlmime_decode_qp(q+2);      else        decoded_text = intlmime_decode_base64_buf(q+2);    }    else      break;                          /* exit the loop because we don't know the encoding method */    begin = (p != NULL) ? p + 2 : (q + PL_strlen(q));    if (decoded_text == NULL)      break;                          /* exit the loop because we have problem to decode */    ret = 1;    output_text = (char *)decoded_text;    PR_ASSERT(output_text != NULL);    PL_strcpy(output_p, (char *)output_text);    output_p += PL_strlen(output_text);    if (output_text != decoded_text)      PR_Free(output_text);    PR_Free(decoded_text);  }  PL_strcpy(output_p, (char *)begin);     /* put the tail back  */  if (work_buf)    PR_Free(work_buf);  if (ret)  {    return retbuff;  }  else  {    PR_Free(retbuff);    PL_strcpy(charset, "us-ascii");       /* charset was not encoded, put us-ascii */    return PL_strdup(header);             /* nothing to decode */  }}