Exemple #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();                                    
        }
Exemple #2
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]);
        }
Exemple #3
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();
        }
Exemple #4
0
        /// <summary>
        /// Default constructor. Requires to be initialized with an IMAPConfig instance
        /// </summary>
        /// <param name="config"></param>
        /// <param name="extraParams">Used to pass in the ID of the current message worker</param>
        public IMAPLogger(IMAPConfig config, params object[] extraParams)
        {
            _config = config;
            _debugLevel = config.DebugDetail;
            _workerID = -1;

            if (extraParams.Length>0)
                _workerID = Convert.ToInt32(extraParams[0]);
        }
Exemple #5
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();
                }
            }
        }
Exemple #6
0
 public IMAPShell(IMAPConfig config, bool autoConnect)
 {
     _config = config;
     _client = new IMAPAsyncClient(config, 5);
     _currentFolder = null;
     _autoConnect = autoConnect;
     
     InitCommandMap();
 }
Exemple #7
0
        /// <summary>
        /// Default constructor. Requires to be initialized with an IMAPConfig instance
        /// </summary>
        /// <param name="config"></param>
        /// <param name="extraParams">Used to pass in the ID of the current message worker</param>
        public IMAPLogger(IMAPConfig config, params object[] extraParams)
        {
            _config     = config;
            _debugLevel = config.DebugDetail;
            _workerID   = -1;

            if (extraParams.Length > 0)
            {
                _workerID = Convert.ToInt32(extraParams[0]);
            }
        }
Exemple #8
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;
 }
Exemple #9
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);
        }
Exemple #10
0
        /// <summary>
        /// Creates a config object based on previously saved settings
        /// </summary>
        /// <param name="configFile"></param>
        public IMAPConfig(string configFile)
        {
            IMAPConfig c = new IMAPConfig();

            Stream          s = File.Open(configFile, FileMode.Open);
            BinaryFormatter b = new BinaryFormatter();

            c                       = (IMAPConfig)b.Deserialize(s);
            this._host              = c.Host;
            this._userName          = c.UserName;
            this._password          = c.Password;
            this._useSSL            = c.UseSSL;
            this._defaultFolderName = c.DefaultFolderName;
            this._autoLogon         = c.AutoLogon;
            this._debugMode         = c.DebugMode;
            this._cacheFile         = c.CacheFile;
            this._autoGetMsgID      = c.AutoGetMsgID;
            this._autoSyncCache     = c.AutoSyncCache;
            this._logFile           = c.LogFile;
            this._debugDetail       = c.DebugDetail;
            s.Close();
        }
Exemple #11
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);
            
        }
Exemple #12
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();
                }

            }
        }
Exemple #13
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();
        }
 public override void SetConfig(string host, int port, bool useSSL, string username, string password)
 {
     IMAPConfig conf = new IMAPConfig(host, username, password, useSSL, false, "");
     _client.Config = conf;
 }
Exemple #15
0
 /// <summary>
 /// Default constructor. Only used for deserialization purposes.
 /// </summary>
 public IMAPClient()
 {
     _config  = null;
     _imap    = new IMAP();
     _folders = new IMAPFolderCollection();
 }
Exemple #16
0
        /// <summary>
        /// Creates a config object based on previously saved settings
        /// </summary>
        /// <param name="configFile"></param>
        public IMAPConfig(string configFile)
        {
            IMAPConfig c = new IMAPConfig();

            Stream s = File.Open(configFile, FileMode.Open);
            BinaryFormatter b = new BinaryFormatter();
            c = (IMAPConfig)b.Deserialize(s);
            this._host = c.Host;
            this._userName = c.UserName;
            this._password = c.Password;
            this._useSSL = c.UseSSL;
            this._defaultFolderName = c.DefaultFolderName;
            this._autoLogon = c.AutoLogon;
            this._debugMode = c.DebugMode;
            this._cacheFile = c.CacheFile;
            this._autoGetMsgID = c.AutoGetMsgID;
            this._autoSyncCache = c.AutoSyncCache;
            this._logFile = c.LogFile;
            this._debugDetail = c.DebugDetail;
            s.Close();
        }
Exemple #17
0
        public Form1()
        {
            InitializeComponent();

            config = new IMAPConfig();
        }
Exemple #18
0
 /// <summary>
 /// Default constructor. Only used for deserialization purposes.
 /// </summary>
 public IMAPClient()
 {
     _config = null;
     _imap = new IMAP();
     _folders = new IMAPFolderCollection();
 }
Exemple #19
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;
        }