Beispiel #1
0
        public static void Main(string[] args)
        {
            PrintWelcome();
            Arguments argParser = new Arguments(args);

            if (argParser["c"] != null)
            {
                _config = new IMAPConfig(argParser["c"]);
            }
            else if (argParser.ArgsDefined(new string[] { "s", "p", "u" }))
            {
                string server   = argParser["s"];
                string username = argParser["u"];
                string password = argParser["p"];
                bool   useSSL   = argParser["ssl"] != null ? true : false;
                _config = new IMAPConfig(server, username, password, useSSL, false, "");
            }
            else
            {
                ColorConsole.WriteLine("\n\n^13:00Invalid parameters specified.\n");
                PrintHelp();
                return;
            }

            bool autoConnect = argParser["auto"] != null;

            _shell = new Shell.IMAPShell(_config, autoConnect);
            _shell.Start();
        }
Beispiel #2
0
        /// <summary>
        /// Main constructor.
        /// </summary>
        /// <param name="config">The configuration instance to use for this client</param>
        /// <param name="logger">Custom logger to use with this client. Use null for default logger.</param>
        public IMAPClient(IMAPConfig config, IMAPLogger logger, int maxWorkers)
        {
            _config = config;
            _imap   = new IMAP();

            _logger = logger ?? new IMAPLogger(config);
            //_imap.InfoLogged += Log;
            _imap.Logger = _logger;
            _folders     = new IMAPFolderCollection();

            Log(IMAPBase.LogTypeEnum.IMAP, "------------------------------------------------------");
            Log(IMAPBase.LogTypeEnum.INFO, "InterIMAP Client Initialized");

            if (config.CacheFile != String.Empty)
            {
                this.UsingCache = true;
                Log(IMAPBase.LogTypeEnum.INFO, String.Format("Using Local Cache File: {0}", config.CacheFile));
            }

            if (config.AutoLogon)
            {
                Logon();
            }

            if (UsingCache)
            {
                FileInfo finfo = new FileInfo(config.CacheFile);
                if (finfo.Exists)
                {
                    // this config has a cache file specified. Load the cache into the object model

                    LoadCache();
                    if (!OfflineMode && config.AutoSyncCache)
                    {
                        SyncCache();
                    }
                }
                else
                {
                    _folders.Clear();
                    _folders = _imap.ProcessFolders(_config.DefaultFolderName);
                    //IMAPFolderCollection tempFolders = _imap.ProcessFolders(_config.DefaultFolderName);
                    foreach (IMAPFolder f in _folders)
                    {
                        f.SetClient(this);
                        if (_config.AutoGetMsgID)
                        {
                            f.GetMessageIDs(false);
                        }
                    }



                    BuildNewCache();
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Create a new connection pool for the specified client
 /// </summary>
 /// <param name="client"></param>
 public IMAPConnectionPool(IMAPAsyncClient client)
 {
     _numConnections = 5;
     _workers        = new List <IMAPConnectionWorker>();
     _config         = null;
     _client         = client;
     _config         = _client.Config;
     _loggers        = new List <WorkerLogger>();
 }
 /// <summary>
 /// Create a new connection pool for the specified client
 /// </summary>
 /// <param name="client"></param>
 public IMAPConnectionPool(IMAPAsyncClient client)
 {
     _numConnections = 5;
     _workers = new List<IMAPConnectionWorker>();
     _config = null;
     _client = client;
     _config = _client.Config;
     _loggers = new List<WorkerLogger>();
 }
Beispiel #5
0
        public IMAPShell(IMAPConfig config, bool autoConnect)
        {
            _config        = config;
            _client        = new IMAPAsyncClient(config, 5);
            _currentFolder = null;
            _autoConnect   = autoConnect;

            InitCommandMap();
        }
 /// <summary>
 /// Create a new IMAPAsyncClient using the specified configuration and number of worker connections
 /// </summary>
 /// <param name="config"></param>
 /// <param name="numberWorkers"></param>
 public IMAPAsyncClient(IMAPConfig config, int numberWorkers)
 {
     _config = config;
     _connectionPool = new IMAPConnectionPool(this);
     _numConnections = numberWorkers;
     _dataManager = new DataManager(this);
     _mailboxManager = new IMAPMailboxManager(this);
     _requestManager = new IMAPRequestManager(this);
     _aggregator = new LoggerAggregator();
 }
 /// <summary>
 /// Create a new IMAPAsyncClient using the specified configuration and number of worker connections
 /// </summary>
 /// <param name="config"></param>
 /// <param name="numberWorkers"></param>
 public IMAPAsyncClient(IMAPConfig config, int numberWorkers)
 {
     _config         = config;
     _connectionPool = new IMAPConnectionPool(this);
     _numConnections = numberWorkers;
     _dataManager    = new DataManager(this);
     _mailboxManager = new IMAPMailboxManager(this);
     _requestManager = new IMAPRequestManager(this);
     _aggregator     = new LoggerAggregator();
 }
Beispiel #8
0
 /// <summary>
 /// Create new IMAPConnection object specifying the IMAPConfig to use
 /// </summary>
 public IMAPConnection(IMAPConfig config, WorkerLogger logger)
 {
     _config     = config;
     _useSSL     = _config.UseSSL;
     _serverHost = _config.Host;
     _serverPort = _useSSL ? IMAP_DEFAULT_SSL_PORT : IMAP_DEFAULT_PORT;
     _username   = _config.UserName;
     _password   = _config.Password;
     _logger     = logger;
 }
 /// <summary>
 /// 
 /// </summary>        
 public IMAPConnectionWorker(IMAPAsyncClient client, int id)
 {
     _client = client;
     _workerID = id;
     _logger = new WorkerLogger(id);
     _config = _client.Config;
     _conn = new IMAPConnection(_config, _logger);
     _shuttingDown = false;
     _loggedIn = false;
     _processingRequest = false;
 }
Beispiel #10
0
 /// <summary>
 ///
 /// </summary>
 public IMAPConnectionWorker(IMAPAsyncClient client, int id)
 {
     _client            = client;
     _workerID          = id;
     _logger            = new WorkerLogger(id);
     _config            = _client.Config;
     _conn              = new IMAPConnection(_config, _logger);
     _shuttingDown      = false;
     _loggedIn          = false;
     _processingRequest = false;
 }
Beispiel #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "Getting folder list...";
            IMAPConfig config = new IMAPConfig(@"c:\test1.cfg");

            client = new IMAPAsyncClient(config, 5);
            //IMAPConnectionPool.GetInstance().StartUp(config, 5);
            client.Start();
            client.RequestManager.SubmitRequest(new FolderTreeRequest("\"\"", FolderTreeCallback), false);
            button1.Enabled = false;
            button2.Enabled = true;
        }
Beispiel #12
0
        /// <summary>
        /// Prompts the user to enter the filename of the new settings file to create
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newConfigToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog diag = new SaveFileDialog();

            diag.OverwritePrompt = true;
            if (diag.ShowDialog() == DialogResult.OK)
            {
                configFile = diag.FileName;
                config     = new IMAPConfig();
                config.SaveConfig(configFile);
                BindConfigInfo();
                UpdateTitle();
                configChanged = false;
            }

            ToggleEnabled(true);
        }
Beispiel #13
0
        public bool ServerLogin(string folder = null)
        {
            try
            {
                if (Server != null && Server.LoggedOn)
                {
                    return(true);
                }

                IMAPConfig config = new IMAPConfig(HostIMAP, PortIMAP, Email, Password, EnableSslIMAP, false, folder);
                IMAPClient client = new IMAPClient(config, null, 1);
                client.Logon();
                Server = client;

                return(true);
            }
            catch (Exception ex)
            {
                ex.ToOutput();
                return(false);
            }
        }
Beispiel #14
0
        private List <Note> GetMailList(string server, string username, string password, string notefolder)
        {
            List <Note> noteList = new List <Note>();

            if (cancelled)
            {
                return(noteList);
            }

            IMAPConfig config = new IMAPConfig(server, username, password, true, true, "/");

            client = new IMAPAsyncClient(config, 2);
            if (client.Start(false) == false)
            {
                cancelled = true;
                return(noteList);
            }

            GetMailsListRecursive(notefolder, ref noteList);

            return(noteList);
        }
        public CommitFileLogic(SLWebApiClient slWebApiClient, string imapServer, string username, string password, bool useSsl, string folderPathToPoll)
        {
            this.slWebApiClient = slWebApiClient;
            this.imapServer     = imapServer;
            this.username       = username;
            this.password       = password;
            this.subFolderNames = new List <string>();

            string[] pathParts = folderPathToPoll.Split(new char[] { '/' });
            this.folderName = pathParts[0];

            if (pathParts.Length > 1)
            {
                for (int i = 1; i < pathParts.Length; i++)
                {
                    subFolderNames.Add(pathParts[i]);
                }
            }

            imapConfig = new IMAPConfig(imapServer, username, password, useSsl, false, folderPathToPoll);
            cConfigurationFolderPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Configuration\";
        }
Beispiel #16
0
        /// <summary>
        /// Prompts user to select an existing config file, and then opens it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openConfigToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();

            diag.Multiselect = false;

            if (diag.ShowDialog() == DialogResult.OK)
            {
                configFile = diag.FileName;
                Stream          s = File.Open(configFile, FileMode.Open);
                BinaryFormatter b = new BinaryFormatter();
                config = (IMAPConfig)b.Deserialize(s);


                s.Close();

                BindConfigInfo();
                UpdateTitle();
                configChanged = false;
            }

            ToggleEnabled(true);
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("USAGE: ConfigGenerator <configfilename>");
                return;
            }

            IMAPConfig config = new IMAPConfig();

            Console.WriteLine("ConfigGenerator for InterIMAP");
            Console.WriteLine("Copyright (C) 2008 Jason Miesionczek");
            Console.WriteLine();
            Console.Write("Enter Hostname: ");
            string host = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Username: "******"Password: "******"Use SSL [y/N]: ");
            string ssl = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Auto Logon [y/N]: ");
            string logon = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Debug Mode [y/N]: ");
            string debug = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Default Folder: ");
            string defaultFolder = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Local cache file: ");
            string cache = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Cache Format [xml/binary]: ");
            string format = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Auto Sync Cache [Y/n]: ");
            string sync = Console.ReadLine();

            Console.WriteLine();
            Console.Write("Auto Retrieve All Message UIDs [Y/n]: ");
            string getids = Console.ReadLine();

            config.AutoLogon         = logon.Equals("y") ? true : false;
            config.DebugMode         = debug.Equals("y") ? true : false;
            config.DefaultFolderName = defaultFolder;
            config.Host          = host;
            config.Password      = password;
            config.UserName      = username;
            config.UseSSL        = ssl.Equals("y") ? true : false;
            config.CacheFile     = cache;
            config.Format        = format.Equals("xml") ? CacheFormat.XML : (format.Equals("binary") ? CacheFormat.Binary : CacheFormat.XML);
            config.AutoGetMsgID  = getids.Equals("n") ? false : true;
            config.AutoSyncCache = sync.Equals("y") ? true : false;
            config.SaveConfig(args[0]);
            Console.WriteLine("{0} created successfully.", args[0]);
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            //IMAPConfig config = new IMAPConfig("<host>", "<username>", "<password>", false, true, "");
            //config.SaveConfig("settings.cfg");
            IMAPConfig config = new IMAPConfig(@"c:\test1.cfg");

            config.CacheFile = "";

            IMAPClient client = null;

            try
            {
                client = new IMAPClient(config, null, 5);
            }
            catch (IMAPException e)
            {
                Console.WriteLine(e.Message);
                return;
            }


            //IMAPFolder drafts = client.Folders["Drafts"];

            //IMAPMessage newMessage = new IMAPMessage();
            //newMessage.From.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**"));
            //newMessage.To.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**"));
            //newMessage.Date = DateTime.Now;
            //newMessage.Subject = "this is a new message";
            //drafts.AppendMessage(newMessage, "this is the content of the new message");
            //IMAPFolder f = client.Folders["INBOX"];
            //Console.WriteLine(f.Messages.Count);
            //IMAPMessage msg = f.GetMessageByID(21967);
            //Console.WriteLine(msg.TextData.Data);
            //foreach (IMAPFileAttachment attachment in msg.Attachments)
            //{
            //    attachment.SaveFile("C:\\");
            //}
            //Console.ReadLine();

            IMAPFolder f = client.Folders["INBOX"];

            int[] msgCount = null;

            while (msgCount.Length == 0)
            {
                msgCount = f.CheckForNewMessages();
                Thread.Sleep(1000);
            }

            foreach (int id in msgCount)
            {
                IMAPMessage msg = f.GetMessageByID(id);
                // do some logic here
                msg.MarkAsRead();
            }

            //IMAPFolder f = client.Folders["Deleted Items"];
            //IMAPMessage m = f.GetMessageByID(707);
            //IMAPFolder d = client.Folders["Deleted Items"];
            //IMAPMessage m = d.Messages[0];
            //IMAPMessage m = f.GetMessageByID(375);
            //IMAPMessage m = f.Messages[0];
            //m.RefreshData(true, true);

            //client._imap.ProcessMessageHeader(m, 0); // 2893
            //client._imap.ProcessBodyStructure(m);
            //client._imap.ProcessMessageHeader(m, 0);
            //client._imap.ProcessBodyStructure(m);
            //client._imap.ProcessBodyParts(m);
            //client._imap.ProcessAttachments(m);
            //IMAPSearchQuery query = new IMAPSearchQuery();
            //query.Range = new DateRange(DateTime.Now.AddDays(-6), DateTime.Now);
            //IMAPSearchResult sResult = f.Search(query);

            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(-6), DateTime.Now));
            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchFrom("Christine Fade", "*****@*****.**"));
            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchNew());

            //IMAPFolder test = f.SubFolders["Test"];
            //IMAPFolder del = client.Folders["Deleted Items"];
            //f.CopyMessageToFolder(f.Messages[0], test);
            //test.DeleteMessage(test.Messages[0]);
            //f.MoveMessageToFolder(f.Messages[0], test);

            //test.EmptyFolder();
            //Console.WriteLine("{0} - {1}", sResult.Query.Range.StartDate, sResult.Query.Range.EndDate);
            //foreach (IMAPMessage msg in sResult.Messages)
            //{
            //    msg.RefreshData(true, true, false);
            //    Console.WriteLine("{0}: {1}", msg.Date, msg.Subject);
            //    Console.WriteLine(msg.TextData.Data);
            //}
            //m.Attachments[1].SaveFile("C:\\");
            Console.ReadLine();
            foreach (IMAPMessage msg in client.Folders["INBOX"].Messages)
            {
                if (msg.BodyParts.Count == 0)
                {
                    Console.WriteLine(msg.Uid);
                }
            }
            client.Logoff();
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            IMAPConfig config = new IMAPConfig("imap.gmail.com", "atmospherian", "Xr3pr1s3Y", true, true, "");

            config.SaveConfig(@"c:\settings.cfg");
            //IMAPConfig config = new IMAPConfig(@"c:\test1.cfg");
            IMAPAsyncClient client = new IMAPAsyncClient(config, 5);

            client.MailboxManager.CreateNewMailbox(@"c:\test.mbx");


            client.Start();
            FolderTreeRequest ftr = new FolderTreeRequest("\"\"", null);

            client.RequestManager.SubmitAndWait(ftr, false);

            IBatchRequest batch = new SimpleBatchRequest();

            foreach (IFolder folder in client.MailboxManager.GetAllFolders())
            {
                FolderDataRequest fdr = new FolderDataRequest(folder, null);
                fdr.RequestCompleted += delegate(IRequest req)
                {
                    FolderDataProcessor fdp = req.GetProcessorAsType <FolderDataProcessor>();
                    IFolder             f   = fdp.Request.Command.ParameterObjects[0] as IFolder;
                    Console.WriteLine("Data for {0} loaded. {1} Messages found.", f.Name, f.Exists);
                };
                batch.Requests.Add(fdr);
            }

            client.RequestManager.SubmitBatchAndWait(batch, false);
            batch.Requests.Clear();
            foreach (IFolder folder in client.MailboxManager.GetAllFolders())
            {
                MessageListRequest mlr = new MessageListRequest(folder, null);
                mlr.RequestCompleted += delegate(IRequest req)
                {
                    MessageListProcessor fdp = req.GetProcessorAsType <MessageListProcessor>();
                    IFolder f = fdp.Request.Command.ParameterObjects[0] as IFolder;
                    Console.WriteLine("Message List for {0} loaded. {1} Messages found.", f.Name, f.Exists);
                };

                batch.Requests.Add(mlr);
            }

            client.RequestManager.SubmitBatchAndWait(batch, false);

            client.MailboxManager.DownloadEntireAccount(delegate(int messagesCompleted, int totalMessages, IFolder currentFolder)
            {
                Console.WriteLine();
                Console.WriteLine("Message {0} of {1} downloaded from {2}", messagesCompleted, totalMessages, currentFolder.Name);
            }, delegate(int totalFolders, int totalMessages, long totalTime)
            {
                Console.WriteLine("{0} Messages in {1} folders downloaded in {2} minutes.", totalMessages, totalFolders, new TimeSpan(totalTime).Minutes);
            });


            //config.CacheFi

            Console.WriteLine("Press any key");
            Console.ReadLine();



            client.Stop();
        }
 /// <summary>
 /// Create new IMAPConnection object specifying the IMAPConfig to use
 /// </summary>
 public IMAPConnection(IMAPConfig config, WorkerLogger logger)
 {
     _config = config;
     _useSSL = _config.UseSSL;
     _serverHost = _config.Host;
     _serverPort = _useSSL ? IMAP_DEFAULT_SSL_PORT : IMAP_DEFAULT_PORT;
     _username = _config.UserName;
     _password = _config.Password;
     _logger = logger;
 }
 /// <summary>
 /// Default constructor. Only used for deserialization purposes.
 /// </summary>
 public IMAPClient()
 {
     _config = null;
     _imap = new IMAP();
     _folders = new IMAPFolderCollection();
 }
Beispiel #22
0
        public Form1()
        {
            InitializeComponent();

            config = new IMAPConfig();
        }
        /// <summary>
        /// Main constructor. 
        /// </summary>
        /// <param name="config">The configuration instance to use for this client</param>
        /// <param name="logger">Custom logger to use with this client. Use null for default logger.</param>
        public IMAPClient(IMAPConfig config, IMAPLogger logger, int maxWorkers)
        {
            _config = config;
            _imap = new IMAP();

            _logger = logger ?? new IMAPLogger(config);
            //_imap.InfoLogged += Log;
            _imap.Logger = _logger;
            _folders = new IMAPFolderCollection();

            Log(IMAPBase.LogTypeEnum.IMAP, "------------------------------------------------------");
            Log(IMAPBase.LogTypeEnum.INFO, "InterIMAP Client Initialized");

            if (config.CacheFile != String.Empty)
            {
                this.UsingCache = true;
                Log(IMAPBase.LogTypeEnum.INFO, String.Format("Using Local Cache File: {0}", config.CacheFile));
            }

            if (config.AutoLogon)
                Logon();

            if (UsingCache)
            {
                FileInfo finfo = new FileInfo(config.CacheFile);
                if (finfo.Exists)
                {
                    // this config has a cache file specified. Load the cache into the object model

                    LoadCache();
                    if (!OfflineMode && config.AutoSyncCache)
                        SyncCache();
                }
                else
                {

                    _folders.Clear();
                    _folders = _imap.ProcessFolders(_config.DefaultFolderName);
                    //IMAPFolderCollection tempFolders = _imap.ProcessFolders(_config.DefaultFolderName);
                    foreach (IMAPFolder f in _folders)
                    {
                        f.SetClient(this);
                        if (_config.AutoGetMsgID)
                            f.GetMessageIDs(false);
                    }

                    BuildNewCache();
                }

            }
        }
Beispiel #24
0
 /// <summary>
 /// Default constructor. Only used for deserialization purposes.
 /// </summary>
 public IMAPClient()
 {
     _config  = null;
     _imap    = new IMAP();
     _folders = new IMAPFolderCollection();
 }