PR_ASSERT(msg_headers);
MimeCMSHeadersAndCertsMatch(MimeObject *obj,							  nsICMSMessage *content_info,							  char **sender_email_addr_return){  MimeHeaders *msg_headers = 0;  char *from_addr = 0;  char *from_name = 0;  char *sender_addr = 0;  char *sender_name = 0;  char *cert_name = 0;  char *cert_addr = 0;  PRBool match = PR_TRUE;  /* Find the name and address in the cert.   */  PR_ASSERT(content_info);  if (content_info)	{	  content_info->GetSignerCommonName (&cert_name);	  content_info->GetSignerEmailAddress (&cert_addr);	}  if (!cert_name && !cert_addr) 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;	  }  }  PR_ASSERT(msg_headers);  if (!msg_headers) 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)	  {		int n = ParseRFC822Addresses(s, &from_name, &from_addr);		PR_ASSERT(n <= 1);		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)	  {		int n = ParseRFC822Addresses(s, &sender_name, &sender_addr);		PR_ASSERT(n <= 1);		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; and if the name in the cert	 matches either the name in the From or Sender field.	 Consider it a match if the cert does not contain a name (address.)	 But do not consider it a match if the cert contains a name (address)	 but the message headers do not.   */  PR_ASSERT(match == PR_TRUE);  match = PR_TRUE;  /* ======================================================================	 First check the addresses.   */  /* If there is no addr in the cert, then consider it a match. */  if (!cert_addr)	match = PR_TRUE;  /* If there is both a from and sender address, and if neither of	 them match, then error. */  else if (from_addr && *from_addr &&		   sender_addr && *sender_addr)	{    if (!!nsCRT::strcasecmp(cert_addr, from_addr) &&      !!nsCRT::strcasecmp(cert_addr, sender_addr))		match = PR_FALSE;	}  /* If there is a from but no sender, and it doesn't match, then error. */  else if (from_addr && *from_addr)	{    if (!!nsCRT::strcasecmp(cert_addr, from_addr))		match = PR_FALSE;	}  /* If there is a sender but no from, and it doesn't match, then error. */  else if (sender_addr && *sender_addr)	{    if (!!nsCRT::strcasecmp(cert_addr, sender_addr))		match = PR_FALSE;	}  /* Else there are no addresses at all -- error. */  else	{	  match = PR_FALSE;	}  if (sender_email_addr_return)	{	  if (match && cert_addr)      *sender_email_addr_return = nsCRT::strdup(cert_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;	}  /* ======================================================================     Next, check the names.   */#if 0  /* No, don't check the names, that's a nightmare that just won't end. */  if (match == PR_FALSE)	;  /* nevermind */  /* If there is no name in the cert, then consider it a match. */  else if (!cert_name)	match = PR_TRUE;  /* If there is both a from and sender name, and if neither of	 them match, then error. */  else if (from_name && *from_name &&		   sender_name && *sender_name)	{	  if (!!strcasecomp(cert_name, from_name) &&		  !!strcasecomp(cert_name, sender_name))		match = PR_FALSE;	}  /* If there is a from but no sender, and it doesn't match, then error. */  else if (from_name && *from_name)	{	  if (!!strcasecomp(cert_name, from_name))		match = PR_FALSE;	}  /* If there is a sender but no from, and it doesn't match, then error. */  else if (sender_name && *sender_name)	{    if (!!strcasecomp(cert_name, sender_name))    match = PR_FALSE;  }  /* Else there are no names at all -- consider that a match. */#endif /* 0 */ DONE:  PR_FREEIF(from_addr);  PR_FREEIF(from_name);  PR_FREEIF(sender_addr);  PR_FREEIF(sender_name);  PR_FREEIF(cert_addr);  PR_FREEIF(cert_name);  return match;}