示例#1
0
		/// <summary>
		/// Retrieves a mail message by its unique identifier message attribute providing
		/// fine-grained control over which message parts to retrieve.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve</param>
		/// <param name="callback">A delegate which will be invoked for every MIME body
		/// part of the mail message to determine whether it should be fetched from the
		/// server or skipped.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-3"]/*'/>
		public MailMessage GetMessage(uint uid, ExaminePartDelegate callback,
			bool seen = true, string mailbox = null) {
			if (!Authed)
				throw new NotAuthenticatedException();
			lock (sequenceLock) {
				PauseIdling();
				SelectMailbox(mailbox);
				string header = GetMailHeader(uid, seen, mailbox);
				MailMessage message = MessageBuilder.FromHeader(header);
				string structure = GetBodystructure(uid, mailbox);
				try {
					Bodypart[] parts = Bodystructure.Parse(structure);
					foreach (Bodypart part in parts) {
						// Let the delegate decide whether the part should be fetched or not.
						if (callback(part) == true) {
							string content = GetBodypart(uid, part.PartNumber, seen, mailbox);
							message.AddBodypart(part, content);
						}
					}
				} catch (FormatException) {
					throw new BadServerResponseException("Server returned erroneous " +
						"body structure:" + structure);
				}
				ResumeIdling();
				return message;
			}
		}
示例#2
0
		/// <summary>
		/// Retrieves a set of mail messages by their unique identifier message attributes
		/// providing fine-grained control over which message parts to retrieve of each
		/// respective message.
		/// </summary>
		/// <param name="uids">An array of unique identifiers of the mail messages to
		/// retrieve</param>
		/// <param name="callback">A delegate which will be invoked for every MIME body
		/// part of a mail message to determine whether it should be fetched from the
		/// server or skipped.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the fetched
		/// messages on the server.</param>
		/// <param name="mailbox">The mailbox the messages will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail messages could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An array of initialized instances of the MailMessage class representing
		/// the fetched mail messages</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessages-3"]/*'/>
		public MailMessage[] GetMessages(uint[] uids, ExaminePartDelegate callback,
			bool seen = true, string mailbox = null) {
			List<MailMessage> list = new List<MailMessage>();
			foreach (uint uid in uids)
				list.Add(GetMessage(uid, callback, seen, mailbox));
			return list.ToArray();
		}
示例#3
0
		/// <summary>
		/// Retrieves a set of mail messages by their unique identifier message attributes
		/// providing fine-grained control over which message parts to retrieve of each
		/// respective message.
		/// </summary>
		/// <param name="uids">An array of unique identifiers of the mail messages to
		/// retrieve</param>
		/// <param name="callback">A delegate which will be invoked for every MIME body
		/// part of a mail message to determine whether it should be fetched from the
		/// server or skipped.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the fetched
		/// messages on the server.</param>
		/// <param name="mailbox">The mailbox the messages will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail messages could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An array of initialized instances of the MailMessage class representing
		/// the fetched mail messages</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessages-3"]/*'/>
		public List<MessageInfo> GetMessages(long[] uids, ExaminePartDelegate callback,
			bool seen = true, MessageReceived messageReceived = null) {
                if (!Authed)
                    throw new NotAuthenticatedException();
                lock (sequenceLock)
                {
                    if (this.selectedMailbox == null)
                        throw new InvalidOperationException("No mailbox or folder currently selected.");

                    List<MessageInfo> infos = GetMailHeader(uids, seen);

                    Dictionary<long,string> structures = GetBodystructure(uids);
                    try
                    {
                        foreach (MessageInfo info in infos)
                        {
                            Bodypart[] parts = Bodystructure.Parse(structures[info.UID]);
                            foreach (Bodypart part in parts)
                            {
                                /* Let delegate decide if part should be fetched or not */
                                if (callback(part) == true)
                                {
                                    string content = GetBodypart(info.UID, part.PartNumber, seen);
                                    info.Envelope.AddBodypart(part, content);
                                }
                            }

                            if (messageReceived != null)
                                messageReceived.Invoke(info);
                        }
                    }
                    catch (FormatException)
                    {
                        throw new BadServerResponseException("Server returned erroneous " +
                            "body structure.");
                    }
                   
                    return infos;
                }
		}
示例#4
0
		/// <summary>
		/// Retrieves a mail message by its unique identifier message attribute providing
		/// fine-grained control over which message parts to retrieve.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve</param>
		/// <param name="callback">A delegate which will be invoked for every MIME body
		/// part of the mail message to determine whether it should be fetched from the
		/// server or skipped.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-3"]/*'/>
		public MessageInfo GetMessage(long uid, ExaminePartDelegate callback,
			bool seen = true) {
			if (!Authed)
				throw new NotAuthenticatedException();
			lock (sequenceLock) {
                if (this.selectedMailbox == null)
                    throw new InvalidOperationException("No mailbox or folder currently selected.");

				MessageInfo info = GetMailHeader(uid, seen);
				string structure = GetBodystructure(uid);
				try {
					Bodypart[] parts = Bodystructure.Parse(structure);
					foreach (Bodypart part in parts) {
						/* Let delegate decide if part should be fetched or not */
						if (callback(part) == true) {
							string content = GetBodypart(uid, part.PartNumber, seen);
							info.Envelope.AddBodypart(part, content);
						}
					}
				} catch (FormatException) {
					throw new BadServerResponseException("Server returned erroneous " +
						"body structure:" + structure);
				}
			
				return info;
			}
		}
示例#5
0
		/// <summary>
		/// Retrieves the set of mail messages with the specified unique identifiers (UIDs) while only
		/// fetching those parts of the messages that satisfy the condition of the specified delegate. 
		/// </summary>
		/// <param name="uids">An enumerable collection of unique identifiers of the mail messages to
		/// retrieve.</param>
		/// <param name="callback">A delegate which will be invoked for every MIME body-part of each
		/// mail message to determine whether the part should be fetched from the server or
		/// skipped.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the fetched messages on the
		/// server.</param>
		/// <param name="mailbox">The mailbox the messages will be retrieved from. If this parameter is
		/// omitted, the value of the DefaultMailbox property is used to determine the mailbox to
		/// operate on.</param>
		/// <returns>An enumerable collection of initialized instances of the MailMessage class
		/// representing the fetched mail messages.</returns>
		/// <exception cref="ArgumentNullException">The uids parameter or the callback parameter is
		/// null.</exception>
		/// <exception cref="BadServerResponseException">The mail messages could not be fetched. The
		/// message property of the exception contains the error message returned by the
		/// server.</exception>
		/// <exception cref="ObjectDisposedException">The ImapClient object has been disposed.</exception>
		/// <exception cref="IOException">There was a failure writing to or reading from the
		/// network.</exception>
		/// <exception cref="NotAuthenticatedException">The method was called in non-authenticated
		/// state, i.e. before logging in.</exception>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each message which uniquely
		/// identifies the message within the respective mailbox. No two messages in a mailbox share
		/// the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessages-3"]/*'/>
		public IEnumerable<MailMessage> GetMessages(IEnumerable<uint> uids, ExaminePartDelegate callback,
			bool seen = true, string mailbox = null) {
			uids.ThrowIfNull("uids");
			List<MailMessage> list = new List<MailMessage>();
			foreach (uint uid in uids)
				list.Add(GetMessage(uid, callback, seen, mailbox));
			return list;
		}
示例#6
0
        public OpenPop.Mime.Message GetMessageB(uint uid, ExaminePartDelegate callback,
			bool seen = true, string mailbox = null) {
			AssertValid();
			callback.ThrowIfNull("callback");
			lock (sequenceLock) {
				PauseIdling();
				SelectMailbox(mailbox);

			    var message = GetMailHeaderB(uid, seen, mailbox);
				string structure = GetBodystructure(uid, mailbox);
				try {
					Bodypart[] parts = Bodystructure.Parse(structure);
					foreach (Bodypart part in parts) {
						// Let the delegate decide whether the part should be fetched or not.
						if (callback(part) == true) {
						    var p = GetBodypartB(
						        message.Headers, uid,
						        part.PartNumber,
						        seen, mailbox);

						    if (message.MessagePart.MessageParts == null) {
						        var type = typeof (OpenPop.Mime.MessagePart);
						        var prop = type.GetProperty(
						            "MessageParts", BindingFlags.Instance |
                                        BindingFlags.Public | BindingFlags.NonPublic);
                                prop.SetValue(
                                    message.MessagePart,
                                    new List<OpenPop.Mime.MessagePart>(4));
						    }

						    message.MessagePart.MessageParts.Add(p);
						}
					}
				} catch (FormatException) {
					throw new BadServerResponseException("The server returned an erroneous " +
						"body structure:" + structure);
				}
				ResumeIdling();
				return message;
			}
		}
示例#7
0
		/// <summary>
		/// Retrieves a mail message by its unique identifier message attribute providing
		/// fine-grained control over which message parts to retrieve.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve</param>
		/// <param name="callback">A delegate which will be invoked for every MIME body
		/// part of the mail message to determine whether it should be fetched from the
		/// server or skipped.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-3"]/*'/>
		public MailMessage GetMessage(uint uid, ExaminePartDelegate callback,
			bool seen = true, string mailbox = null) {
			if (!Authed)
				throw new NotAuthenticatedException();
			lock (sequenceLock) {
				PauseIdling();
				SelectMailbox(mailbox);
				string header = GetMailHeader(uid, seen, mailbox);
				MailMessage message = MessageBuilder.FromHeader(header);
				Bodypart[] parts = Bodystructure.Parse(
					GetBodystructure(uid, mailbox));
				foreach (Bodypart part in parts) {
					/* Let delegate decide if part should be fetched or not */
					if (callback(part) == true) {
						string content = GetBodypart(uid, part.PartNumber, seen, mailbox);
						message.AddBodypart(part, content);
					}
				}
				ResumeIdling();
				return message;
			}
		}