public static Change ( string text, string charset ) : string | ||
text | string | |
charset | string | |
Результат | string |
public Attachment(string buffer) : base(buffer) { this.contentDisposition = this.GetValueFromHeader("Content-Disposition: "); this.fileName = GetValueEqualFromHeader("name="); this.contentID = GetValueFromHeader("Content-ID: "); if (contentDisposition.IndexOf("attachment") != -1) { this.fileName = GetValueEqualFromHeader("filename="); this.isRealAttachment = true; } if (contentType.IndexOf("multipart") != -1) { string boundary = "--" + GetValueEqualFromHeader("boundary="); hasAttachments = true; ParseMixedMessage(buffer, boundary); } else { hasAttachments = false; //data int start = buffer.IndexOf("\r\n\r\n"); if (start == -1) { throw new Exception("could not find beginning of MIME body"); } start += 4; if (this.contentTransferEncoding.ToLower().IndexOf("base64") != -1) { this.data = Convert.FromBase64String(buffer.Substring(start)); } else if (this.contentTransferEncoding.IndexOf("quoted-printable") != -1) { this.data = QuotedCoding.GetByteArray(buffer.Substring(start)); } else { //change charset if contentTransferEncoding is 8bit if (this.contentTransferEncoding.IndexOf("8bit") != -1) { this.data = StringOperations.GetByteArray(StringOperations.Change(buffer.Substring(start), charset)); } else { this.data = StringOperations.GetByteArray(buffer.Substring(start)); } } } }
internal string GetTextMessage(string buffer) { // find "\r\n\r\n" denoting end of header int start = buffer.IndexOf("\r\n\r\n") + 4; int end = buffer.LastIndexOf("\r\n.\r\n"); //change charset if contentTransferEncoding is 8bit if (this.contentTransferEncoding.IndexOf("8bit") != -1) { return(StringOperations.Change(buffer.Substring(start, end - start), charset)); } else if (this.contentTransferEncoding.IndexOf("base64") != -1) { return(StringOperations.Decode(buffer.Substring(start, end - start), charset)); } else { return(buffer.Substring(start, end - start)); } }