/// <summary> /// Returns parsed IMAP SEARCH <b>HEADER (field-name) (string)</b> key. /// </summary> /// <param name="r">String reader.</param> /// <returns>Returns parsed IMAP SEARCH <b>HEADER (field-name) (string)</b> key.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when parsing fails.</exception> internal static IMAP_Search_Key_Header Parse(StringReader r) { if (r == null) { throw new ArgumentNullException("r"); } string word = r.ReadWord(); if (!string.Equals(word, "HEADER", Helpers.GetDefaultIgnoreCaseComparison())) { throw new ParseException("Parse error: Not a SEARCH 'HEADER' key."); } string fieldName = IMAP_Utils.ReadString(r); if (fieldName == null) { throw new ParseException("Parse error: Invalid 'HEADER' field-name value."); } string value = IMAP_Utils.ReadString(r); if (value == null) { throw new ParseException("Parse error: Invalid 'HEADER' string value."); } return(new IMAP_Search_Key_Header(fieldName, value)); }
/// <summary> /// Returns parsed IMAP SEARCH <b>SUBJCET (string)</b> key. /// </summary> /// <param name="r">String reader.</param> /// <returns>Returns parsed IMAP SEARCH <b>SUBJECT (string)</b> key.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when parsing fails.</exception> internal static IMAP_Search_Key_Subject Parse(StringReader r) { if (r == null) { throw new ArgumentNullException("r"); } string word = r.ReadWord(); if (!String2.Equals(word, "SUBJECT", StringComparison2.InvariantCultureIgnoreCase)) { throw new ParseException("Parse error: Not a SEARCH 'SUBJECT' key."); } string value = IMAP_Utils.ReadString(r); if (value == null) { throw new ParseException("Parse error: Invalid 'SUBJECT' value."); } return(new IMAP_Search_Key_Subject(value)); }
/// <summary> /// Returns parsed IMAP SEARCH <b>BODY (string)</b> key. /// </summary> /// <param name="r">String reader.</param> /// <returns>Returns parsed IMAP SEARCH <b>BODY (string)</b> key.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when parsing fails.</exception> internal static IMAP_Search_Key_Body Parse(StringReader r) { if (r == null) { throw new ArgumentNullException("r"); } string word = r.ReadWord(); if (!string.Equals(word, "BODY", StringComparison.InvariantCultureIgnoreCase)) { throw new ParseException("Parse error: Not a SEARCH 'BODY' key."); } string value = IMAP_Utils.ReadString(r); if (value == null) { throw new ParseException("Parse error: Invalid 'BODY' value."); } return(new IMAP_Search_Key_Body(value)); }
/// <summary> /// Returns parsed IMAP SEARCH <b>CC (string)</b> key. /// </summary> /// <param name="r">String reader.</param> /// <returns>Returns parsed IMAP SEARCH <b>CC (string)</b> key.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when parsing fails.</exception> internal static IMAP_Search_Key_Cc Parse(StringReader r) { if (r == null) { throw new ArgumentNullException("r"); } string word = r.ReadWord(); if (!string.Equals(word, "CC", Helpers.GetDefaultIgnoreCaseComparison())) { throw new ParseException("Parse error: Not a SEARCH 'CC' key."); } string value = IMAP_Utils.ReadString(r); if (value == null) { throw new ParseException("Parse error: Invalid 'CC' value."); } return(new IMAP_Search_Key_Cc(value)); }
/// <summary> /// Parses IMAP FETCH BODYSTRUCTURE single part entity from reader. /// </summary> /// <param name="r">Fetch reader.</param> /// <returns>Returns parsed bodystructure entity.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception> public static IMAP_t_Fetch_r_i_BodyStructure_e_SinglePart Parse(StringReader r) { if (r == null) { throw new ArgumentNullException("r"); } IMAP_t_Fetch_r_i_BodyStructure_e_SinglePart retVal = new IMAP_t_Fetch_r_i_BodyStructure_e_SinglePart(); /* RFC 3501 7.4.2. * * Normal single part entity fields. * body type * body subtype * body parameter parenthesized list * body id * body description * body encoding * body size - Encoded bytes count. * --- extention fields * * Message/xxx type entity fields. * body type * body subtype * body parameter parenthesized list * body id * body description * body encoding * body size - Encoded bytes count. * --- message special fields * envelope structure * body structure * body encoded text lines count * --- extention fields * * Text/xxx type entity fields. * body type * body subtype * body parameter parenthesized list * body id * body description * body encoding * body size - Encoded bytes count. * --- text special fields * body encoded text lines count * --- extention fields * * Extention fields. * body MD5 * body disposition * body language * body location */ // body type // body subtype // body parameter parenthesized list string type = IMAP_Utils.ReadString(r); string subtype = IMAP_Utils.ReadString(r); if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(subtype)) { retVal.m_pContentType = new MIME_h_ContentType(type + "/" + subtype); } r.ReadToFirstChar(); // Parse Content-Type parameters if (r.StartsWith("(")) { StringReader pramsReader = new StringReader(r.ReadParenthesized()); if (retVal.m_pContentType != null) { while (pramsReader.Available > 0) { string name = IMAP_Utils.ReadString(pramsReader); if (string.IsNullOrEmpty(name)) { break; } string value = IMAP_Utils.ReadString(pramsReader); if (value == null) { value = ""; } retVal.m_pContentType.Parameters[name] = MIME_Encoding_EncodedWord.DecodeTextS(value); } } } // NIL else { IMAP_Utils.ReadString(r); } // body id - nstring retVal.m_ContentID = IMAP_Utils.ReadString(r); // body description - nstring retVal.m_ContentDescription = IMAP_Utils.ReadString(r); // body encoding - string retVal.m_ContentTransferEncoding = IMAP_Utils.ReadString(r); // body size - Encoded bytes count. string size = IMAP_Utils.ReadString(r); if (string.IsNullOrEmpty(size)) { retVal.m_ContentSize = -1; } else { retVal.m_ContentSize = Convert.ToInt64(size); } if (string.Equals("text", type, StringComparison.InvariantCultureIgnoreCase)) { // body encoded text lines count string linesCount = IMAP_Utils.ReadString(r); if (string.IsNullOrEmpty(size)) { retVal.m_LinesCount = -1; } else { retVal.m_LinesCount = Convert.ToInt32(linesCount); } } if (string.Equals("message", type, StringComparison.InvariantCultureIgnoreCase)) { // envelope structure r.ReadToFirstChar(); // Read ENVELOPE if (r.StartsWith("(")) { string prams = r.ReadParenthesized(); } // NIL else { IMAP_Utils.ReadString(r); } // body structure r.ReadToFirstChar(); // Read BODYSTRUCTURE if (r.StartsWith("(")) { string prams = r.ReadParenthesized(); } // NIL else { IMAP_Utils.ReadString(r); } // body encoded text lines count string linesCount = IMAP_Utils.ReadString(r); if (string.IsNullOrEmpty(size)) { retVal.m_LinesCount = -1; } else { retVal.m_LinesCount = Convert.ToInt32(linesCount); } } // body MD5 - nstring retVal.m_Md5 = IMAP_Utils.ReadString(r); // body disposition - "(" string SP body-fld-param ")" / nil // body-fld-param = "(" string SP string *(SP string SP string) ")" / nil if (r.StartsWith("(")) { string disposition = IMAP_Utils.ReadString(r); if (!string.IsNullOrEmpty(disposition)) { retVal.m_pContentDisposition = new MIME_h_ContentDisposition(disposition); } r.ReadToFirstChar(); // Parse Content-Dispostion parameters. if (r.StartsWith("(")) { StringReader pramsReader = new StringReader(r.ReadParenthesized()); if (retVal.m_pContentDisposition != null) { while (pramsReader.Available > 0) { string name = IMAP_Utils.ReadString(pramsReader); if (string.IsNullOrEmpty(name)) { break; } string value = IMAP_Utils.ReadString(pramsReader); if (value == null) { value = ""; } retVal.m_pContentDisposition.Parameters[name] = MIME_Encoding_EncodedWord.DecodeTextS(value); } } } // NIL else { IMAP_Utils.ReadString(r); } } // NIL else { IMAP_Utils.ReadString(r); } // body language - nstring / "(" string *(SP string) ")" r.ReadToFirstChar(); if (r.StartsWith("(")) { retVal.m_Language = r.ReadParenthesized(); } else { retVal.m_Language = IMAP_Utils.ReadString(r); } // body location - nstring retVal.m_Location = IMAP_Utils.ReadString(r); return(retVal); }
/// <summary> /// Parses IMAP FETCH BODYSTRUCTURE multipart entity from reader. /// </summary> /// <param name="r">Fetch reader.</param> /// <returns>Returns parsed bodystructure entity.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>r</b> is null reference.</exception> public static IMAP_t_Fetch_r_i_BodyStructure_e_Multipart Parse(StringReader r) { if (r == null) { throw new ArgumentNullException("r"); } IMAP_t_Fetch_r_i_BodyStructure_e_Multipart retVal = new IMAP_t_Fetch_r_i_BodyStructure_e_Multipart(); /* RFC 3501 7.4.2. * * Normal fields. * 1*(body-parts) - parenthesized list of body parts * subtype * --- extention fields * * Extention fields. * body parameter parenthesized list * body disposition * body language * body location */ #region Normal fields // Read child entities. while (r.Available > 0) { r.ReadToFirstChar(); if (r.StartsWith("(")) { StringReader bodyPartReader = new StringReader(r.ReadParenthesized()); bodyPartReader.ReadToFirstChar(); IMAP_t_Fetch_r_i_BodyStructure_e part = null; // multipart if (bodyPartReader.StartsWith("(")) { part = IMAP_t_Fetch_r_i_BodyStructure_e_Multipart.Parse(bodyPartReader); } // single-part else { part = IMAP_t_Fetch_r_i_BodyStructure_e_SinglePart.Parse(bodyPartReader); } part.SetParent(retVal); retVal.m_pBodyParts.Add(part); } else { break; } } // subtype string subtype = IMAP_Utils.ReadString(r); if (!string.IsNullOrEmpty(subtype)) { retVal.m_pContentType = new MIME_h_ContentType("multipart/" + subtype); } #endregion #region Extention field // body parameter parenthesized list r.ReadToFirstChar(); if (r.StartsWith("(")) { StringReader pramsReader = new StringReader(r.ReadParenthesized()); if (retVal.m_pContentType != null) { while (pramsReader.Available > 0) { string name = IMAP_Utils.ReadString(pramsReader); if (string.IsNullOrEmpty(name)) { break; } string value = IMAP_Utils.ReadString(pramsReader); if (value == null) { value = ""; } retVal.m_pContentType.Parameters[name] = MIME_Encoding_EncodedWord.DecodeTextS(value); } } } // NIL else { IMAP_Utils.ReadString(r); } // body disposition - "(" string SP body-fld-param ")" / nil // body-fld-param = "(" string SP string *(SP string SP string) ")" / nil if (r.StartsWith("(")) { string disposition = IMAP_Utils.ReadString(r); if (!string.IsNullOrEmpty(disposition)) { retVal.m_pContentDisposition = new MIME_h_ContentDisposition(disposition); } r.ReadToFirstChar(); // Parse Content-Dispostion parameters. if (r.StartsWith("(")) { StringReader pramsReader = new StringReader(r.ReadParenthesized()); if (retVal.m_pContentDisposition != null) { while (pramsReader.Available > 0) { string name = IMAP_Utils.ReadString(pramsReader); if (string.IsNullOrEmpty(name)) { break; } string value = IMAP_Utils.ReadString(pramsReader); if (value == null) { value = ""; } retVal.m_pContentDisposition.Parameters[name] = MIME_Encoding_EncodedWord.DecodeTextS(value); } } } // NIL else { IMAP_Utils.ReadString(r); } } // NIL else { IMAP_Utils.ReadString(r); } // body language - nstring / "(" string *(SP string) ")" r.ReadToFirstChar(); if (r.StartsWith("(")) { retVal.m_Language = r.ReadParenthesized(); } else { retVal.m_Language = IMAP_Utils.ReadString(r); } // body location - nstring retVal.m_Location = IMAP_Utils.ReadString(r); #endregion return(retVal); }