Ejemplo n.º 1
0
        private void frmClient_FormClosed(object sender, FormClosedEventArgs e)
        {
            List <Form> lForms = new List <Form>();

            foreach (var lForm in mNamedChildren.Values)
            {
                lForms.Add(lForm);
                lForm.FormClosed -= ZNamedChildClosed;
            }

            foreach (var lForm in mUnnamedChildren)
            {
                lForms.Add(lForm);
                lForm.FormClosed -= ZUnnamedChildClosed;
            }

            foreach (var lForm in lForms)
            {
                try { lForm.Close(); }
                catch { }
            }

            if (mClient != null)
            {
                try { mClient.Dispose(); }
                catch { }
            }
        }
Ejemplo n.º 2
0
        static void WebVersion()
        {
// the first part of the example is just getting settings
//  it isn't really what I want to show you

            var lConfig =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            var lSettings = lConfig.AppSettings.Settings;

            var lUIDValiditySetting = lSettings[kUIDValidity];

            if (lUIDValiditySetting == null)
            {
                lUIDValiditySetting =
                    new KeyValueConfigurationElement(kUIDValidity, string.Empty);

                lSettings.Add(lUIDValiditySetting);
            }

            var lUIDSetting = lSettings[kUID];

            if (lUIDSetting == null)
            {
                lUIDSetting = new KeyValueConfigurationElement(kUID, string.Empty);
                lSettings.Add(lUIDSetting);
            }

// now what I want to show you

            cIMAPClient lClient = new cIMAPClient();

// connect
//
            lClient.SetServer(kHost);
            lClient.SetPlainCredentials(kUserId, kPassword, eTLSRequirement.indifferent);
            lClient.Connect();

// select the inbox for update
            lClient.Inbox.Select(true);

            cUID lFromUID;

// check the UIDValidity to make sure it hasn't changed
            if (uint.TryParse(lUIDValiditySetting.Value, out var lUIDValidity) &&
                lUIDValidity == lClient.Inbox.UIDValidity.Value &&
                uint.TryParse(lUIDSetting.Value, out var lUID))
            {
                lFromUID = new cUID(lUIDValidity, lUID);
            }
            else
            {
                lFromUID = new cUID(lClient.Inbox.UIDValidity.Value, 1);
            }

// note the UIDNext for the next run
            uint lUIDNext = lClient.Inbox.UIDNext.Value;

// only process if there are more messages than at the last run
            if (lUIDNext > lFromUID.UID)
            {
                // this example is meant to demonstrate building a filter, so here it is
                var lFilter =
                    cFilter.UID >= lFromUID&
                    cFilter.From.Contains("*****@*****.**") &
                    !cFilter.Deleted;

                // loop through the messages
                foreach (var lMessage in lClient.Inbox.Messages(lFilter))
                {
                    // only process the message if it looks as expected
                    if (lMessage.Attachments.Count == 1 &&
                        lMessage.PlainText() == "FILE FOR PROCESSING")
                    {
                        // save the attachement
                        lMessage.Attachments[0].SaveAs
                            ($".\\SavedAttachment.{lMessage.UID.UIDValidity}.{lMessage.UID.UID}");

                        // mark the message as deleted
                        lMessage.Deleted = true;
                    }
                }

                // store the start point for the next run
                lUIDValiditySetting.Value = lFromUID.UIDValidity.ToString();
                lUIDSetting.Value         = lUIDNext.ToString();
                lConfig.Save(ConfigurationSaveMode.Modified);

                // expunge the deleted messages
                lClient.Inbox.Expunge(true);
            }

// done
            lClient.Disconnect();
            lClient.Dispose();
        }
Ejemplo n.º 3
0
        // to test this include ", eTLSRequirement.indifferent" on the SetPlainCredentials

        static void NewWebVersion()
        {
            cIMAPClient lClient = new cIMAPClient();

// connect
            lClient.SetServer(kHost);
            lClient.SetPlainCredentials(kUserId, kPassword);
            lClient.Connect();

            Console.WriteLine(new string('-', 79));
            Console.WriteLine();

// list mailboxes in the first personal namespace

            Console.WriteLine("A list of mailboxes;");

            var lNamespace = lClient.Namespaces.Personal[0];

            foreach (var lMailbox in lNamespace.Mailboxes())
            {
                Console.WriteLine(lMailbox.Name);
            }

            Console.WriteLine();
            Console.WriteLine(new string('-', 79));
            Console.WriteLine();

// list status of inbox

            Console.WriteLine(
                "{0} unseen messages out of {1} in the inbox",
                lClient.Inbox.UnseenCount,
                lClient.Inbox.MessageCount);

            Console.WriteLine();
            Console.WriteLine(new string('-', 79));
            Console.WriteLine();

// select the inbox so we can look at the messages in it
            lClient.Inbox.Select();

// list unseen messages in the inbox
            foreach (var lMessage in lClient.Inbox.Messages(!cFilter.Seen))
            {
                Console.WriteLine("Sent: " + lMessage.Sent);
                Console.WriteLine("From: " + lMessage.From.DisplaySortString);
                Console.WriteLine("Subject: " + lMessage.Subject);
                Console.WriteLine();

                var lAttachments = lMessage.Attachments;

                if (lAttachments.Count > 0)
                {
                    Console.WriteLine(lAttachments.Count + " attachments;");

                    foreach (var lAttachment in lAttachments)
                    {
                        Console.WriteLine(
                            lAttachment.FileName + "\t" +
                            lAttachment.SaveSizeInBytes() + "b");
                    }

                    Console.WriteLine();
                }

                Console.WriteLine(lMessage.PlainText());

                Console.WriteLine();
                Console.WriteLine(new string('-', 79));
                Console.WriteLine();
            }

// done
            lClient.Disconnect();
            lClient.Dispose();
        }