nsresult rv; nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
msg_pick_real_name (nsMsgAttachmentHandler *attachment, const PRUnichar *proposedName, const char *charset){  nsresult rv;  nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));   const char *s, *s2;  char *s3;  if ( (attachment->m_real_name) && (*attachment->m_real_name))    return;  if (proposedName && *proposedName)  {    attachment->m_real_name = ToNewUTF8String(nsAutoString(proposedName));  }  else //Let's extract the name from the URL  {    nsXPIDLCString url;  attachment->mURL->GetSpec(url);  s = url;  s2 = PL_strchr (s, ':');  if (s2) s = s2 + 1;  /* If we know the URL doesn't have a sensible file name in it,   don't bother emitting a content-disposition. */  if (!PL_strncasecmp (url, "news:", 5) ||    !PL_strncasecmp (url, "snews:", 6) ||    !PL_strncasecmp (url, "IMAP:", 5) ||    !PL_strncasecmp (url, "mailbox:", 8))    return;  /* Take the part of the file name after the last / or \ */  s2 = PL_strrchr (s, '/');  if (s2) s = s2+1;  s2 = PL_strrchr (s, '\\');    if (s2) s = s2+1;  /* Copy it into the attachment struct. */  PR_FREEIF(attachment->m_real_name);  attachment->m_real_name = PL_strdup (s);  /* Now trim off any named anchors or search data. */  s3 = PL_strchr (attachment->m_real_name, '?');  if (s3) *s3 = 0;  s3 = PL_strchr (attachment->m_real_name, '#');  if (s3) *s3 = 0;  /* Now lose the %XX crap. */  nsUnescape (attachment->m_real_name);  }  PRInt32 parmFolding = 0;  if (NS_SUCCEEDED(rv) && prefs)     prefs->GetIntPref("mail.strictly_mime.parm_folding", &parmFolding);  if (parmFolding == 0 || parmFolding == 1)    if (!proposedName || !(*proposedName))  {    /* Convert to unicode */    nsAutoString uStr;    rv = nsMsgI18NCopyNativeToUTF16(attachment->m_real_name, uStr);    if (NS_FAILED(rv))       CopyASCIItoUTF16(attachment->m_real_name, uStr);  }    /* Now a special case for attaching uuencoded files...   If we attach a file "foo.txt.uu", we will send it out with   Content-Type: text/plain; Content-Transfer-Encoding: x-uuencode.   When saving such a file, a mail reader will generally decode it first   (thus removing the uuencoding.)  So, let's make life a little easier by   removing the indication of uuencoding from the file name itself.  (This   will presumably make the file name in the Content-Disposition header be   the same as the file name in the "begin" line of the uuencoded data.)   However, since there are mailers out there (including earlier versions of   Mozilla) that will use "foo.txt.uu" as the file name, we still need to   cope with that; the code which copes with that is in the MIME parser, in   libmime/mimei.c.   */  if (attachment->m_already_encoded_p &&    attachment->m_encoding)  {    char *result = attachment->m_real_name;    PRInt32 L = PL_strlen(result);    const char **exts = 0;    /* #### TOTAL KLUDGE.     I'd like to ask the mime.types file, "what extensions correspond     to obj->encoding (which happens to be "x-uuencode") but doing that     in a non-sphagetti way would require brain surgery.  So, since     currently uuencode is the only content-transfer-encoding which we     understand which traditionally has an extension, we just special-     case it here!       Note that it's special-cased in a similar way in libmime/mimei.c.     */    if (!PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE) ||      !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE2) ||      !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE3) ||      !PL_strcasecmp(attachment->m_encoding, ENCODING_UUENCODE4))    {      static const char *uue_exts[] = { "uu", "uue", 0 };      exts = uue_exts;    }    while (exts && *exts)    {      const char *ext = *exts;      PRInt32 L2 = PL_strlen(ext);      if (L > L2 + 1 &&             /* long enough */        result[L - L2 - 1] == '.' &&      /* '.' in right place*/        !PL_strcasecmp(ext, result + (L - L2))) /* ext matches */      {        result[L - L2 - 1] = 0;   /* truncate at '.' and stop. */        break;      }      exts++;    }  }}