Exemple #1
0
        public void addFlagRead()
        {
            using (var client = new ImapClient())
            {
                client.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect);
                client.AuthenticationMechanisms.Remove(Constant.GoogleOAuth);
                client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword);
                Console.WriteLine(client.IsAuthenticated);


                FolderAccess     inboxAccess = client.Inbox.Open(FolderAccess.ReadWrite);
                IMailFolder      destination = client.GetFolder(Constant.InboxFolder);
                IList <UniqueId> uids        = client.Inbox.Search(SearchQuery.All);

                if (destination != null)
                {
                    for (int i = 0; i < uids.Count; i++)
                    {
                        destination.SetFlags(i, MessageFlags.Seen, true);
                    }

                    Console.WriteLine(uids.Count + "-Marked as Read");
                }
                client.Disconnect(true);
            }
        }
        //public StorageFolder mru;


        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            /*--- 表示するフォルダを登録する ---*/
            FolderAccess a = new FolderAccess();
            await a.FolderSelectSaveAsync();

            //await a.FolderGet();
        }
Exemple #3
0
        public void ReOpen(IMailFolder folder, FolderAccess folderAccess)
        {
            if (folder.IsOpen)
            {
                folder.Close();
            }

            folder.Open(folderAccess);
        }
        static string GetDefaultMessage(FolderAccess access)
        {
            if (access == FolderAccess.ReadWrite)
            {
                return("The folder is not currently open in read-write mode.");
            }

            return("The folder is not currently open.");
        }
Exemple #5
0
 private InboxDetail BuildInboxDetail(IMailFolder folder, FolderAccess folderAccess)
 {
     return(new InboxDetail()
     {
         Name = folder.FullName,
         MessageCount = folder.Count,
         UnreadCount = folder.Unread,
         Access = folderAccess
     });
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
        /// </summary>
        /// <remarks>
        /// Creates a new <see cref="FolderNotOpenException"/>.
        /// </remarks>
        /// <param name="folderName">The folder name.</param>
        /// <param name="access">The minimum folder access required by the operation.</param>
        /// <param name="message">The error message.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="folderName"/> is <c>null</c>.
        /// </exception>
        public FolderNotOpenException(string folderName, FolderAccess access, string message) : base(message)
        {
            if (folderName == null)
            {
                throw new ArgumentNullException("folderName");
            }

            FolderName   = folderName;
            FolderAccess = access;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
        /// </summary>
        /// <remarks>
        /// Creates a new <see cref="FolderNotOpenException"/>.
        /// </remarks>
        /// <param name="folderName">The folder name.</param>
        /// <param name="access">The minimum folder access required by the operation.</param>
        /// <param name="message">The error message.</param>
        /// <param name="innerException">The inner exception.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="folderName"/> is <c>null</c>.
        /// </exception>
        public FolderNotOpenException(string folderName, FolderAccess access, string message, Exception innerException) : base(message, innerException)
        {
            if (folderName == null)
            {
                throw new ArgumentNullException(nameof(folderName));
            }

            FolderName   = folderName;
            FolderAccess = access;
        }
Exemple #8
0
        private async Task <IMailFolder> GetFolder(
            ImapClient client,
            string folder,
            FolderAccess access = FolderAccess.ReadOnly)
        {
            var result = await client.GetFolderAsync(folder);

            await result.OpenAsync(access);

            return(result);
        }
Exemple #9
0
        /// <summary>
        /// This will overwrite the files for which, the server pulls the same names
        /// </summary>
        public void getAttachmentsThroughMessageSummary()
        {
            using (var client = new ImapClient())
            {
                client.ServerCertificateValidationCallback = (s, c, ch, e) => true;
                client.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect);
                client.AuthenticationMechanisms.Remove(Constant.GoogleOAuth);
                client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword);

                if (client.IsConnected == true)
                {
                    FolderAccess            inboxAccess = client.Inbox.Open(FolderAccess.ReadWrite);
                    IList <IMessageSummary> items       = client.Inbox.Fetch(0, -1,
                                                                             MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure | MessageSummaryItems.Envelope);
                    int unnamed = 0;

                    foreach (var message in items)
                    {
                        foreach (var attachment in message.BodyParts)
                        {
                            MimeKit.MimePart mime =
                                (MimeKit.MimePart)client.Inbox.GetBodyPart(message.UniqueId, attachment);
                            string fileName = mime.FileName;

                            if (string.IsNullOrEmpty(fileName))
                            {
                                fileName = string.Format("unnamed-{0}", ++unnamed);
                            }

                            FormatOptions options = FormatOptions.Default.Clone();
                            options.ParameterEncodingMethod = ParameterEncodingMethod.Rfc2047;

                            using (
                                FileStream stream =
                                    File.Create(Path.Combine("C:\\Users\\maddirsh\\Desktop\\MimeKit\\", fileName)))
                            {
                                mime.ContentObject.DecodeTo(stream);
                            }

                            Console.WriteLine("End");
                        }
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
        }
Exemple #10
0
        public FolderAccess[] getInfo()
        {
            Dictionary <string, string>[] rows = classMysql.getArrayByQuery("" +
                                                                            "SELSECT ^ " +
                                                                            "FROM tb_folder_access");
            FolderAccess[] folderAccesses = new FolderAccess[rows.GetLength(0)];

            for (int i = 0; i < rows.GetLength(0); i++)
            {
                folderAccesses[i].id            = Convert.ToInt32(rows[i]["id"]);
                folderAccesses[i].idAcceddGroup = Convert.ToInt32(rows[i]["id_access_group"]);
                folderAccesses[i].idFolder      = Convert.ToInt32(rows[i]["id_folder"]);
                folderAccesses[i].read          = Convert.ToBoolean(rows[i]["read"]);
                folderAccesses[i].write         = Convert.ToBoolean(rows[i]["write"]);
            }

            return(folderAccesses);
        }
        /// <summary>
        /// 依据节点类型创建"空白"的数据信息对象,其HasBeenLoadFromStorage属性为false
        /// (无需数据存储的节点,如OnlyText例此,其HasBeenLoadFromStorage始终为true)
        /// </summary>
        /// <param name="NodeType"></param>
        /// <returns></returns>
        public static NodeDataObject CreateDataInfoNode(String NodeType, String EFConnectionString)
        {
            NodeDataObject nodeDataObject = new NodeDataObject();

            if (NodeType == "OnlyText")
            {
                nodeDataObject.DataItem = new OnlyTextInfo()
                {
                    MainWindow = _mainWindow
                };
                nodeDataObject.AccessObject = null;
            }
            if (NodeType == "Folder")
            {
                FolderInfo info = new FolderInfo()
                {
                    MainWindow = _mainWindow
                };
                FolderAccess access = new FolderAccess(EFConnectionString);
                info.SetRootControlDataAccessObj(access);

                nodeDataObject.DataItem = info;
                //设置数据未装入标记
                nodeDataObject.DataItem.HasBeenLoadFromStorage = false;

                nodeDataObject.AccessObject = access;
            }
            if (NodeType == "DetailText")
            {
                DetailTextInfo info = new DetailTextInfo()
                {
                    MainWindow = _mainWindow
                };
                DetailTextAccess accessObj = new DetailTextAccess(EFConnectionString);

                info.SetRootControlDataAccessObj(accessObj);
                nodeDataObject.DataItem = info;
                //设置数据未装入标记
                nodeDataObject.DataItem.HasBeenLoadFromStorage = false;

                nodeDataObject.AccessObject = accessObj;
            }
            return(nodeDataObject);
        }
Exemple #12
0
        /// <summary>
        /// Looks like Microsoft keeps blocking me from the email server
        /// </summary>
        public void GetEmailSubjectBody()
        {
            using (var client = new ImapClient())
            {
                client.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect);
                client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword);

                FolderAccess     inboxAccess = client.Inbox.Open(FolderAccess.ReadWrite);
                IMailFolder      destination = client.GetFolder("Inbox");
                IList <UniqueId> uids        = client.Inbox.Search(SearchQuery.All);

                foreach (var x in uids)
                {
                    var message = destination.GetMessage(x);
                    //Console.WriteLine(message.From +"\n"+ message.Subject+ "\n" + message.Date + message.TextBody);
                    Console.WriteLine(message.GetTextBody(TextFormat.Plain));
                    Console.WriteLine();
                    Console.WriteLine(message.GetTextBody(TextFormat.Text));
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Move Messages with MimeKit, works with outlook, but not gmail
        /// </summary>
        public void moveInboxMessages()
        {
            using (var client = new ImapClient())
            {
                client.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect);
                client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword);


                FolderAccess     inboxAccess = client.Inbox.Open(FolderAccess.ReadWrite);
                IMailFolder      destination = client.GetFolder(Constant.ProcessedFolder);
                IList <UniqueId> uids        = client.Inbox.Search(SearchQuery.All);

                if (destination != null && uids.Count > 0)
                {
                    client.Inbox.MoveTo(uids, destination);
                    Console.WriteLine("Moved Messages");
                }

                client.Disconnect(true);
            }
        }
Exemple #14
0
		/// <summary>
		/// Opens the folder using the requested folder access.
		/// </summary>
		/// <remarks>
		/// <para>This variant of the <see cref="Open(FolderAccess,System.Threading.CancellationToken)"/>
		/// method is meant for quick resynchronization of the folder. Before calling this method,
		/// the <see cref="ImapClient.EnableQuickResync(CancellationToken)"/> method MUST be called.</para>
		/// <para>You should also make sure to add listeners to the <see cref="MailFolder.MessagesVanished"/> and
		/// <see cref="MailFolder.MessageFlagsChanged"/> events to get notifications of changes since
		/// the last time the folder was opened.</para>
		/// </remarks>
		/// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
		/// <param name="access">The requested folder access.</param>
		/// <param name="uidValidity">The last known <see cref="MailFolder.UidValidity"/> value.</param>
		/// <param name="highestModSeq">The last known <see cref="MailFolder.HighestModSeq"/> value.</param>
		/// <param name="uids">The last known list of unique message identifiers.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="access"/> is not a valid value.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="ImapClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="ImapClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="ImapClient"/> is not authenticated.
		/// </exception>
		/// <exception cref="FolderNotFoundException">
		/// The <see cref="ImapFolder"/> does not exist.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The QRESYNC feature has not been enabled.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The IMAP server does not support the QRESYNC extension.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ImapProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="ImapCommandException">
		/// The server replied with a NO or BAD response.
		/// </exception>
		public override FolderAccess Open (FolderAccess access, uint uidValidity, ulong highestModSeq, IList<UniqueId> uids, CancellationToken cancellationToken = default (CancellationToken))
		{
			var set = ImapUtils.FormatUidSet (uids);

			if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
				throw new ArgumentOutOfRangeException ("access");

			CheckState (false, false);

			if (IsOpen && Access == access)
				return access;

			if ((Engine.Capabilities & ImapCapabilities.QuickResync) == 0)
				throw new NotSupportedException ("The IMAP server does not support the QRESYNC extension.");

			if (!Engine.QResyncEnabled)
				throw new InvalidOperationException ("The QRESYNC extension has not been enabled.");

			var qresync = string.Format ("(QRESYNC ({0} {1}", uidValidity, highestModSeq);

			if (uids.Count > 0)
				qresync += " " + set;

			qresync += "))";

			var command = string.Format ("{0} %F {1}\r\n", SelectOrExamine (access), qresync);
			var ic = new ImapCommand (Engine, cancellationToken, this, command, this);
			ic.RegisterUntaggedHandler ("FETCH", QResyncFetch);

			if (access == FolderAccess.ReadWrite) {
				// Note: if the server does not respond with a PERMANENTFLAGS response,
				// then we need to assume all flags are permanent.
				PermanentFlags = SettableFlags | MessageFlags.UserDefined;
			} else {
				PermanentFlags = MessageFlags.None;
			}

			try {
				Engine.QueueCommand (ic);
				Engine.Wait (ic);

				ProcessResponseCodes (ic, this);

				if (ic.Response != ImapCommandResponse.Ok)
					throw ImapCommandException.Create (access == FolderAccess.ReadOnly ? "EXAMINE" : "SELECT", ic);
			} catch {
				PermanentFlags = MessageFlags.None;
				throw;
			}

			if (Engine.Selected != null && Engine.Selected != this) {
				var folder = Engine.Selected;

				folder.PermanentFlags = MessageFlags.None;
				folder.AcceptedFlags = MessageFlags.None;
				folder.Access = FolderAccess.None;

				folder.OnClosed ();
			}

			Engine.State = ImapEngineState.Selected;
			Engine.Selected = this;

			OnOpened ();

			return Access;
		}
Exemple #15
0
		static string SelectOrExamine (FolderAccess access)
		{
			return access == FolderAccess.ReadOnly ? "EXAMINE" : "SELECT";
		}
Exemple #16
0
		/// <summary>
		/// Asynchronously open the folder using the requested folder access.
		/// </summary>
		/// <remarks>
		/// Asynchronously opens the folder using the requested folder access.
		/// </remarks>
		/// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
		/// <param name="access">The requested folder access.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="access"/> is not a valid value.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="FolderNotFoundException">
		/// The <see cref="MailFolder"/> does not exist.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public virtual Task<FolderAccess> OpenAsync (FolderAccess access, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
				throw new ArgumentOutOfRangeException ("access");

			return Task.Factory.StartNew (() => {
				lock (SyncRoot) {
					return Open (access, cancellationToken);
				}
			}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
		}
Exemple #17
0
		/// <summary>
		/// Open the folder using the requested folder access.
		/// </summary>
		/// <remarks>
		/// Opens the folder using the requested folder access.
		/// </remarks>
		/// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
		/// <param name="access">The requested folder access.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="access"/> is not a valid value.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="FolderNotFoundException">
		/// The <see cref="MailFolder"/> does not exist.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public abstract FolderAccess Open (FolderAccess access, CancellationToken cancellationToken = default (CancellationToken));
Exemple #18
0
		/// <summary>
		/// Asynchronously opens the folder using the requested folder access.
		/// </summary>
		/// <remarks>
		/// <para>This variant of the <see cref="OpenAsync(FolderAccess,System.Threading.CancellationToken)"/>
		/// method is meant for quick resynchronization of the folder. Before calling this method,
		/// the <see cref="MailStore.EnableQuickResync(CancellationToken)"/> method MUST be called.</para>
		/// <para>You should also make sure to add listeners to the <see cref="MessagesVanished"/> and
		/// <see cref="MessageFlagsChanged"/> events to get notifications of changes since
		/// the last time the folder was opened.</para>
		/// </remarks>
		/// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
		/// <param name="access">The requested folder access.</param>
		/// <param name="uidValidity">The last known <see cref="UidValidity"/> value.</param>
		/// <param name="highestModSeq">The last known <see cref="HighestModSeq"/> value.</param>
		/// <param name="uids">The last known list of unique message identifiers.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="access"/> is not a valid value.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="FolderNotFoundException">
		/// The <see cref="MailFolder"/> does not exist.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The quick resynchronization feature has not been enabled.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The mail store does not support the quick resynchronization feature.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public virtual Task<FolderAccess> OpenAsync (FolderAccess access, uint uidValidity, ulong highestModSeq, IList<UniqueId> uids, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
				throw new ArgumentOutOfRangeException ("access");

			if (uids == null)
				throw new ArgumentNullException ("uids");

			if (uids.Count == 0)
				throw new ArgumentException ("No uids were specified.", "uids");

			return Task.Factory.StartNew (() => {
				lock (SyncRoot) {
					return Open (access, uidValidity, highestModSeq, uids, cancellationToken);
				}
			}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
		}
Exemple #19
0
		/// <summary>
		/// Opens the folder using the requested folder access.
		/// </summary>
		/// <remarks>
		/// <para>This variant of the <see cref="Open(FolderAccess,System.Threading.CancellationToken)"/>
		/// method is meant for quick resynchronization of the folder. Before calling this method,
		/// the <see cref="MailStore.EnableQuickResync(CancellationToken)"/> method MUST be called.</para>
		/// <para>You should also make sure to add listeners to the <see cref="MessagesVanished"/> and
		/// <see cref="MessageFlagsChanged"/> events to get notifications of changes since
		/// the last time the folder was opened.</para>
		/// </remarks>
		/// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
		/// <param name="access">The requested folder access.</param>
		/// <param name="uidValidity">The last known <see cref="UidValidity"/> value.</param>
		/// <param name="highestModSeq">The last known <see cref="HighestModSeq"/> value.</param>
		/// <param name="uids">The last known list of unique message identifiers.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="access"/> is not a valid value.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="IMailStore"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="IMailStore"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="IMailStore"/> is not authenticated.
		/// </exception>
		/// <exception cref="FolderNotFoundException">
		/// The <see cref="MailFolder"/> does not exist.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// The quick resynchronization feature has not been enabled.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// The mail store does not support the quick resynchronization feature.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="CommandException">
		/// The command failed.
		/// </exception>
		public abstract FolderAccess Open (FolderAccess access, uint uidValidity, ulong highestModSeq, IList<UniqueId> uids, CancellationToken cancellationToken = default (CancellationToken));
		static string GetDefaultMessage (FolderAccess access)
		{
			if (access == FolderAccess.ReadWrite)
				return "The folder is not currently open in read-write mode.";

			return "The folder is not currently open.";
		}
Exemple #21
0
 /// <summary>
 /// Opens the folder using the requested folder access.
 /// </summary>
 /// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
 /// <param name="access">The requested folder access.</param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <paramref name="access"/> is not a valid value.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 /// The <see cref="ImapClient"/> has been disposed.
 /// </exception>
 /// <exception cref="System.InvalidOperationException">
 /// The <see cref="ImapClient"/> is either not connected or not authenticated.
 /// </exception>
 /// <exception cref="System.IO.IOException">
 /// An I/O error occurred.
 /// </exception>
 /// <exception cref="ImapProtocolException">
 /// The server's response contained unexpected tokens.
 /// </exception>
 /// <exception cref="ImapCommandException">
 /// The server replied with a NO or BAD response.
 /// </exception>
 public FolderAccess Open(FolderAccess access)
 {
     return Open (access, CancellationToken.None);
 }
Exemple #22
0
        /// <summary>
        /// Opens the folder using the requested folder access.
        /// </summary>
        /// <remarks>
        /// <para>This variant of the <see cref="Open(FolderAccess,System.Threading.CancellationToken)"/>
        /// method is meant for quick resynchronization of the folder. Before calling this method,
        /// the <see cref="ImapClient.EnableQuickResync"/> method MUST be called.</para>
        /// <para>You should also make sure to add listeners to the <see cref="Vanished"/> and
        /// <see cref="MessageFlagsChanged"/> events to get notifications of changes since
        /// the last time the folder was opened.</para>
        /// </remarks>
        /// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
        /// <param name="access">The requested folder access.</param>
        /// <param name="uidValidity">The last known <see cref="UidValidity"/> value.</param>
        /// <param name="highestModSeq">The last known <see cref="HighestModSeq"/> value.</param>
        /// <param name="uids">The last known list of unique message identifiers.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="access"/> is not a valid value.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="ImapClient"/> has been disposed.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// <para>The <see cref="ImapClient"/> is either not connected or not authenticated.</para>
        /// <para>-or-</para>
        /// <para>The QRESYNC feature has not been enabled.</para>
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// The IMAP server does not support the QRESYNC extension.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        /// The operation was canceled via the cancellation token.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// An I/O error occurred.
        /// </exception>
        /// <exception cref="ImapProtocolException">
        /// The server's response contained unexpected tokens.
        /// </exception>
        /// <exception cref="ImapCommandException">
        /// The server replied with a NO or BAD response.
        /// </exception>
        public FolderAccess Open(FolderAccess access, UniqueId uidValidity, ulong highestModSeq, UniqueId[] uids, CancellationToken cancellationToken)
        {
            var set = ImapUtils.FormatUidSet (uids);

            if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
                throw new ArgumentOutOfRangeException ("access");

            CheckState (false, false);

            if (IsOpen && Access == access)
                return access;

            if ((Engine.Capabilities & ImapCapabilities.QuickResync) == 0)
                throw new NotSupportedException ();

            if (!Engine.QResyncEnabled)
                throw new InvalidOperationException ("The QRESYNC feature is not enabled.");

            var qresync = string.Format ("(QRESYNC ({0} {1}", uidValidity.Id, highestModSeq);

            if (uids.Length > 0)
                qresync += " " + set;

            qresync += "))";

            var command = string.Format ("{0} %F {1}\r\n", SelectOrExamine (access), qresync);
            var ic = new ImapCommand (Engine, cancellationToken, this, command, this);
            ic.RegisterUntaggedHandler ("FETCH", QResyncFetch);

            Engine.QueueCommand (ic);
            Engine.Wait (ic);

            ProcessResponseCodes (ic, null);

            if (ic.Result != ImapCommandResult.Ok)
                throw new ImapCommandException (access == FolderAccess.ReadOnly ? "EXAMINE" : "SELECT", ic.Result);

            if (Engine.Selected != null)
                Engine.Selected.Access = FolderAccess.None;

            Engine.State = ImapEngineState.Selected;
            Engine.Selected = this;

            return Access;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="FolderNotOpenException"/>.
		/// </remarks>
		/// <param name="folderName">The folder name.</param>
		/// <param name="access">The minimum folder access required by the operation.</param>
		/// <param name="message">The error message.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="folderName"/> is <c>null</c>.
		/// </exception>
		public FolderNotOpenException (string folderName, FolderAccess access, string message) : base (message)
		{
			if (folderName == null)
				throw new ArgumentNullException (nameof (folderName));

			FolderName = folderName;
			FolderAccess = access;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
 /// </summary>
 /// <remarks>
 /// Creates a new <see cref="FolderNotOpenException"/>.
 /// </remarks>
 /// <param name="folderName">The folder name.</param>
 /// <param name="access">The minimum folder access required by the operation.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="folderName"/> is <c>null</c>.
 /// </exception>
 public FolderNotOpenException(string folderName, FolderAccess access) : this(folderName, access, GetDefaultMessage(access))
 {
 }
Exemple #25
0
 /// <summary>
 /// Opens the folder using the requested folder access.
 /// </summary>
 /// <remarks>
 /// <para>This variant of the <see cref="Open(FolderAccess,System.Threading.CancellationToken)"/>
 /// method is meant for quick resynchronization of the folder. Before calling this method,
 /// the <see cref="ImapClient.EnableQuickResync(CancellationToken)"/> method MUST be called.</para>
 /// <para>You should also make sure to add listeners to the <see cref="Vanished"/> and
 /// <see cref="MessageFlagsChanged"/> events to get notifications of changes since
 /// the last time the folder was opened.</para>
 /// </remarks>
 /// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
 /// <param name="access">The requested folder access.</param>
 /// <param name="uidValidity">The last known <see cref="UidValidity"/> value.</param>
 /// <param name="highestModSeq">The last known <see cref="HighestModSeq"/> value.</param>
 /// <param name="uids">The last known list of unique message identifiers.</param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <paramref name="access"/> is not a valid value.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 /// The <see cref="ImapClient"/> has been disposed.
 /// </exception>
 /// <exception cref="System.InvalidOperationException">
 /// <para>The <see cref="ImapClient"/> is either not connected or not authenticated.</para>
 /// <para>-or-</para>
 /// <para>The QRESYNC feature has not been enabled.</para>
 /// </exception>
 /// <exception cref="System.NotSupportedException">
 /// The IMAP server does not support the QRESYNC extension.
 /// </exception>
 /// <exception cref="System.IO.IOException">
 /// An I/O error occurred.
 /// </exception>
 /// <exception cref="ImapProtocolException">
 /// The server's response contained unexpected tokens.
 /// </exception>
 /// <exception cref="ImapCommandException">
 /// The server replied with a NO or BAD response.
 /// </exception>
 public FolderAccess Open(FolderAccess access, UniqueId uidValidity, ulong highestModSeq, UniqueId[] uids)
 {
     return Open (access, uidValidity, highestModSeq, uids, CancellationToken.None);
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="FolderNotOpenException"/>.
		/// </remarks>
		/// <param name="folderName">The folder name.</param>
		/// <param name="access">The minimum folder access required by the operation.</param>
		/// <param name="message">The error message.</param>
		/// <param name="innerException">The inner exception.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="folderName"/> is <c>null</c>.
		/// </exception>
		public FolderNotOpenException (string folderName, FolderAccess access, string message, Exception innerException) : base (message, innerException)
		{
			if (folderName == null)
				throw new ArgumentNullException ("folderName");

			FolderName = folderName;
			FolderAccess = access;
		}
Exemple #27
0
		/// <summary>
		/// Opens the folder using the requested folder access.
		/// </summary>
		/// <remarks>
		/// Opens the folder using the requested folder access.
		/// </remarks>
		/// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
		/// <param name="access">The requested folder access.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="access"/> is not a valid value.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="ImapClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="ImapClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// The <see cref="ImapClient"/> is not authenticated.
		/// </exception>
		/// <exception cref="FolderNotFoundException">
		/// The <see cref="ImapFolder"/> does not exist.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="ImapProtocolException">
		/// The server's response contained unexpected tokens.
		/// </exception>
		/// <exception cref="ImapCommandException">
		/// The server replied with a NO or BAD response.
		/// </exception>
		public override FolderAccess Open (FolderAccess access, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
				throw new ArgumentOutOfRangeException ("access");

			CheckState (false, false);

			if (IsOpen && Access == access)
				return access;

			var condstore = (Engine.Capabilities & ImapCapabilities.CondStore) != 0 ? " (CONDSTORE)" : string.Empty;
			var command = string.Format ("{0} %F{1}\r\n", SelectOrExamine (access), condstore);
			var ic = new ImapCommand (Engine, cancellationToken, this, command, this);

			if (access == FolderAccess.ReadWrite) {
				// Note: if the server does not respond with a PERMANENTFLAGS response,
				// then we need to assume all flags are permanent.
				PermanentFlags = SettableFlags | MessageFlags.UserDefined;
			} else {
				PermanentFlags = MessageFlags.None;
			}

			try {
				Engine.QueueCommand (ic);
				Engine.Wait (ic);

				ProcessResponseCodes (ic, this);

				if (ic.Response != ImapCommandResponse.Ok)
					throw ImapCommandException.Create (access == FolderAccess.ReadOnly ? "EXAMINE" : "SELECT", ic);
			} catch {
				PermanentFlags = MessageFlags.None;
				throw;
			}

			if (Engine.Selected != null && Engine.Selected != this) {
				var folder = Engine.Selected;

				folder.PermanentFlags = MessageFlags.None;
				folder.AcceptedFlags = MessageFlags.None;
				folder.Access = FolderAccess.None;

				folder.OnClosed ();
			}

			Engine.State = ImapEngineState.Selected;
			Engine.Selected = this;

			OnOpened ();

			return Access;
		}
Exemple #28
0
        /// <summary>
        /// Opens the folder using the requested folder access.
        /// </summary>
        /// <returns>The <see cref="FolderAccess"/> state of the folder.</returns>
        /// <param name="access">The requested folder access.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="access"/> is not a valid value.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="ImapClient"/> has been disposed.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// The <see cref="ImapClient"/> is either not connected or not authenticated.
        /// </exception>
        /// <exception cref="System.OperationCanceledException">
        /// The operation was canceled via the cancellation token.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// An I/O error occurred.
        /// </exception>
        /// <exception cref="ImapProtocolException">
        /// The server's response contained unexpected tokens.
        /// </exception>
        /// <exception cref="ImapCommandException">
        /// The server replied with a NO or BAD response.
        /// </exception>
        public FolderAccess Open(FolderAccess access, CancellationToken cancellationToken)
        {
            if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
                throw new ArgumentOutOfRangeException ("access");

            CheckState (false, false);

            if (IsOpen && Access == access)
                return access;

            var condstore = (Engine.Capabilities & ImapCapabilities.CondStore) != 0 ? " (CONDSTORE)" : string.Empty;
            var command = string.Format ("{0} %F{1}\r\n", SelectOrExamine (access), condstore);
            var ic = Engine.QueueCommand (cancellationToken, this, command, this);

            Engine.Wait (ic);

            ProcessResponseCodes (ic, null);

            if (ic.Result != ImapCommandResult.Ok)
                throw new ImapCommandException (access == FolderAccess.ReadOnly ? "EXAMINE" : "SELECT", ic.Result);

            if (Engine.Selected != null)
                Engine.Selected.Access = FolderAccess.None;

            Engine.State = ImapEngineState.Selected;
            Engine.Selected = this;

            return Access;
        }
Exemple #29
0
 private IList <UniqueId> Connection(ImapClient client, UserEmailAccount currentAccount, FolderAccess accessMode = FolderAccess.ReadWrite)
 {
     client.Connect(currentAccount.IMAPServer, currentAccount.Port, SecureSocketOptions.SslOnConnect);
     client.Authenticate(currentAccount.EmailAddress, currentAccount.ApplicationPassword);
     //client.Connect("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);
     //client.Authenticate("*****@*****.**", "atssddvndnffxggx");
     client.Inbox.Open(accessMode);
     return(client.Inbox.Search(SearchQuery.All));
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="FolderNotOpenException"/>.
		/// </remarks>
		/// <param name="folderName">The folder name.</param>
		/// <param name="access">The minimum folder access required by the operation.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="folderName"/> is <c>null</c>.
		/// </exception>
		public FolderNotOpenException (string folderName, FolderAccess access) : this (folderName, access, GetDefaultMessage (access))
		{
		}