public static string ParseMIMEHeader(string header) { StringBuilder result = StringBuilderPool.Alloc(); try { int len = header.Length; for (int i = 0; i < len; ++i) { char c = header[i]; if (c == '=' && i < len - 1 && header[i + 1] == '?') { int mimeStrEnd = i + 1; for (int j = 0; mimeStrEnd > 0 && j < 3; ++j) { mimeStrEnd = header.IndexOf('?', mimeStrEnd + 1); } if (mimeStrEnd > 0 && mimeStrEnd < len - 1 && header[mimeStrEnd + 1] == '=') { result.Append( MIMEParser.DecodeMIMEString(header.Substring(i, mimeStrEnd - i + 2))); i = mimeStrEnd + 1; } else { result.Append(MIMEParser.DecodeMIMEString(header.Substring(i))); i = len; } } else { result.Append(c); } } return(result.ToString()); } catch { } finally { StringBuilderPool.Dispose(result); } return(header); }
/** * returns true if a contact is myself */ internal static bool ParseFrom(IResource article, string fromValue, out IContact contact) { if (MIMEParser.ContainsMIMEStrings(fromValue)) { fromValue = ParseTools.ParseMIMEHeader(fromValue); } fromValue = fromValue.Replace("<", null).Replace(">", null).Replace("\\", null).Replace("//", null); string[] parts = fromValue.Split(' '); string eMail = string.Empty; foreach (string part in parts) { if (part.IndexOf('@') >= 0) { eMail = part; break; } } string displayName = fromValue; if (eMail.Length > 0) { displayName = displayName.Replace(eMail, null).Trim(); } if (eMail.Length > 0 || displayName.Length > 0) { IContactManager cm = Core.ContactManager; IResource oldFrom = article.GetLinkProp(cm.Props.LinkFrom); contact = cm.FindOrCreateContact(eMail, displayName); cm.LinkContactToResource(cm.Props.LinkFrom, contact.Resource, article, eMail, displayName); if (oldFrom != null && contact.Resource != oldFrom) { cm.DeleteUnusedContacts(oldFrom.ToResourceList()); } return(contact.IsMyself); } contact = null; return(false); }
internal static string TranslateHeader(string charset, string header) { header = MIMEParser.ContainsMIMEStrings(header) ? ParseTools.ParseMIMEHeader(header) : MIMEParser.TranslateRawStringInCharset(charset, header); return(header); }