/// <summary>Returns a <see cref="T:System.String" /> representation of this instance.</summary> /// <returns>A <see cref="T:System.String" /> that contains the property values for this instance.</returns> public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(DispositionType.ToLower()); if (Parameters != null && Parameters.Count > 0) { bool flag = false; foreach (DictionaryEntry parameter in Parameters) { if (parameter.Value != null && parameter.Value.ToString().Length > 0) { stringBuilder.Append("; "); stringBuilder.Append(parameter.Key); stringBuilder.Append("="); string text = parameter.Key.ToString(); string text2 = parameter.Value.ToString(); flag = (((text == "filename" && text2.IndexOf(' ') != -1) || text.EndsWith("date")) ? true : false); if (flag) { stringBuilder.Append("\""); } stringBuilder.Append(text2); if (flag) { stringBuilder.Append("\""); } } } } return(stringBuilder.ToString()); }
public override string ToString() { // the content-disposition header as in RFC 2183 // ex. attachment; filename=genome.jpeg; modification-date="Wed, 12 Feb 1997 16:29:51 -0500"; // the dates must be quoted and in RFC 822 format // // According to RFC 2183, the filename field value follows the definition // given in RFC 1521, which is // // value := token / quoted-string // StringBuilder sb = new StringBuilder(); sb.Append(DispositionType.ToLower()); if (Parameters != null && Parameters.Count > 0) { bool quote = false; string key, value; foreach (var pair in Parameters) { if (pair.Value != null && pair.Value.ToString().Length > 0) { sb.Append("; "); sb.Append(pair.Key); sb.Append("="); key = pair.Key.ToString(); value = pair.Value.ToString(); if ((key == "filename" && value.IndexOf(' ') != -1) || key.EndsWith("date")) { quote = true; } else { quote = false; } if (quote) { sb.Append("\""); } sb.Append(value); if (quote) { sb.Append("\""); } } } } return(sb.ToString()); }
public override String ToString() { StringBuilder lSb = new StringBuilder(); lSb.Append(DispositionType.ToLower()); foreach (var lItem in fParameters.GetSequence()) { if (lItem.Value.Length > 0) { lSb.Append("; " + lItem.Key + "="); if ((lItem.Key == "filename" && lItem.Value.IndexOf(' ') >= 0) || lItem.Key.EndsWith("date")) { lSb.Append("\"" + lItem.Value + "\""); } else { lSb.Append(lItem.Value); } } } return(lSb.ToString()); }
protected virtual void ParseBody() { string strFullConentType = _headers["Content-Type"]; if (strFullConentType == null) { strFullConentType = ""; } //string strContentTypeValue = null; Hashtable parametrs; MimeEntry.ParseHeader(strFullConentType, out _contentType, out parametrs); // Step 2. Parse Messagy Body [1/23/2004] if (!_contentType.StartsWith("multipart/")) { _charSet = (string)parametrs["charset"]; if (_charSet == null) { _charSet = Encoding.Default.HeaderName; } string ContentEncoding = _headers["Content-Transfer-Encoding"]; if (ContentEncoding == null) { ContentEncoding = "8bit"; } string strDisposition = _headers["Content-Disposition"]; if (strDisposition != null) { Hashtable DispositionParameters; string DispositionType; MimeEntry.ParseHeader(strDisposition, out DispositionType, out DispositionParameters); DispositionType = DispositionType.ToLower(); if (DispositionType == "attachment") { this._disposition = Disposition.Attachment; } else if (DispositionType == "inline") { this._disposition = Disposition.Inline; } _fileName = (string)DispositionParameters["filename"]; if (_fileName != null) { _fileName = Rfc822HeaderCollection.DeocodeHeaderValue(_fileName); } } //string BodyString = Encoding.Default.GetString(this._BinaryData.GetBuffer(),this._BodyOffset,(int)(this._BinaryData.Length - this._BodyOffset)); Encoding encoding = null; try { encoding = Encoding.GetEncoding(CharSet); } catch { encoding = Encoding.Default; } string BodyString = encoding.GetString(this._BinaryData.GetBuffer(), this._BodyOffset, (int)(this._BinaryData.Length - this._BodyOffset)); //string BodyString = Encoding.ASCII.GetString(this._BinaryData.GetBuffer(),this._BodyOffset,(int)(this._BinaryData.Length - this._BodyOffset)); //string BodyString2 = Encoding.UTF8.GetString(this._BinaryData.GetBuffer(),this._BodyOffset,(int)(this._BinaryData.Length - this._BodyOffset)); switch (ContentEncoding.ToLower()) { case "quoted-printable": _body = encoding.GetBytes(MimeEntry.QDecode(encoding, BodyString)); break; case "7bit": //_body = Encoding.ASCII.GetBytes(BodyString); _body = encoding.GetBytes(BodyString); break; default: case "8bit": _body = encoding.GetBytes(BodyString); break; case "base64": BodyString = BodyString.Trim(); if (BodyString.Length > 0) { int base64FixCount = 0; // Fix If Base 64 is broken while (true) { try { _body = Convert.FromBase64String(BodyString); break; } catch (System.FormatException) { // Remove not supported chars if (base64FixCount == 0) { BodyString = Regex.Replace(BodyString, "[^a-zA-Z0-9+/=]+", string.Empty); } else if (base64FixCount == 1) { BodyString += "="; } else { BodyString = BodyString.Substring(0, BodyString.Length - 1); } if (BodyString.Length == 0 || base64FixCount == 25) // Max 25 Attempts to fix chars { _body = new byte[] { }; break; } base64FixCount++; } } } else { _body = new byte[] {} }; break; case "binary": _body = encoding.GetBytes(BodyString); break; //default: // throw new Pop3ServerIncorectEMailFormatException("Not supported content-encoding " + ContentEncoding + " !"); } } else { DataParseStatus parseStatus = _mimeEntries.ParseMimeEntries(_BinaryData.GetBuffer(), (int)_BinaryData.Length, ref _BodyOffset, this.Headers); } }