PRBool foundFrom = PR_FALSE; PRBool foundSender = PR_FALSE;
MimeCMSHeadersAndCertsMatch(MimeObject *obj,							  nsICMSMessage *content_info,							  PRBool *signing_cert_without_email_address,							  char **sender_email_addr_return){  MimeHeaders *msg_headers = 0;  nsXPIDLCString from_addr;  nsXPIDLCString from_name;  nsXPIDLCString sender_addr;  nsXPIDLCString sender_name;  nsXPIDLCString cert_addr;  PRBool match = PR_TRUE;  /* Find the name and address in the cert.   */  if (content_info)	{	  // Extract any address contained in the cert.	  // This will be used for testing, whether the cert contains no addresses at all.	  content_info->GetSignerEmailAddress (getter_Copies(cert_addr));	}  if (signing_cert_without_email_address)  {    *signing_cert_without_email_address = (!cert_addr);  }  if (!cert_addr) {    // no address, no match    match = PR_FALSE;    goto DONE;  }  /* Find the headers of the MimeMessage which is the parent (or grandparent)	 of this object (remember, crypto objects nest.) */  {	MimeObject *o2 = obj;	msg_headers = o2->headers;	while (o2 &&		   o2->parent &&		   !mime_typep(o2->parent, (MimeObjectClass *) &mimeMessageClass))	  {		o2 = o2->parent;		msg_headers = o2->headers;	  }  }  if (!msg_headers) {    // no headers, no match    match = PR_FALSE;    goto DONE;  }  /* Find the names and addresses in the From and/or Sender fields.   */  {	char *s;	/* Extract the name and address of the "From:" field. */	s = MimeHeaders_get(msg_headers, HEADER_FROM, PR_FALSE, PR_FALSE);	if (s)	  {		ParseRFC822Addresses(s, getter_Copies(from_name), getter_Copies(from_addr));		PR_FREEIF(s);	  }	/* Extract the name and address of the "Sender:" field. */	s = MimeHeaders_get(msg_headers, HEADER_SENDER, PR_FALSE, PR_FALSE);	if (s)	  {		ParseRFC822Addresses(s, getter_Copies(sender_name), getter_Copies(sender_addr));		PR_FREEIF(s);	  }  }  /* Now compare them --	 consider it a match if the address in the cert matches either the	 address in the From or Sender field   */  PRBool foundFrom = PR_FALSE;  PRBool foundSender = PR_FALSE;  /* If there is no addr in the cert at all, it can not match and we fail. */  if (!cert_addr)  {  	match = PR_FALSE;  }  else  {    nsCOMPtr<nsIX509Cert> signerCert;    content_info->GetSignerCert(getter_AddRefs(signerCert));    if (signerCert)    {      if (from_addr && *from_addr)      {        NS_ConvertASCIItoUCS2 ucs2From(from_addr);        if (NS_FAILED(signerCert->ContainsEmailAddress(ucs2From, &foundFrom)))        {          foundFrom = PR_FALSE;        }      }      if (sender_addr && *sender_addr)      {        NS_ConvertASCIItoUCS2 ucs2Sender(sender_addr);        if (NS_FAILED(signerCert->ContainsEmailAddress(ucs2Sender, &foundSender)))        {          foundSender = PR_FALSE;        }      }    }    if (!foundSender && !foundFrom)    {		  match = PR_FALSE;	  }  }  if (sender_email_addr_return) {    if (match && foundFrom)      *sender_email_addr_return = nsCRT::strdup(from_addr);    if (match && foundSender)      *sender_email_addr_return = nsCRT::strdup(sender_addr);    else if (from_addr && *from_addr)      *sender_email_addr_return = nsCRT::strdup(from_addr);    else if (sender_addr && *sender_addr)      *sender_email_addr_return = nsCRT::strdup(sender_addr);    else      *sender_email_addr_return = 0;  } DONE:  return match;}