Exemplo n.º 1
0
        public override void Initialise(List <MailFolder> folderList)
        {
            Status = MessageProcessorStatus.Initialising;

            /*
             * try
             * {
             *  _filestream = new StreamReader(_mboxPath);
             * }
             * catch (Exception ex)
             * {
             *  Logger.Error("Opening mbox file [" + _mboxPath + "] failed : " + ex.Message, ex);
             *  Status = MessageProcessorStatus.UnknownError;
             *  throw ex;
             * }
             */
            // Build the folder list
            foreach (var folderMap in _folderMap)
            {
                _mainFolderList.Add(new MailFolder()
                {
                    DestinationFolder = folderMap.Value,
                    SourceFolder      = folderMap.Value,
                });
            }
            NextReader.Initialise(_mainFolderList);
            Status = MessageProcessorStatus.Initialised;
        }
Exemplo n.º 2
0
        public override void Initialise(List <MailFolder> folderList)
        {
            Status  = MessageProcessorStatus.Initialising;
            service = ExchangeHelper.ExchangeConnect(_hostname, _username, _password);
            folders = new List <ExchangeFolder>();
            // Use Exchange Helper to get all the folders for this account
            ExchangeHelper.GetAllSubFolders(service,
                                            new ExchangeFolder()
            {
                Folder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot)
            }, folders,
                                            false);
            if (IncludePublicFolders)
            {
                Logger.Debug("Including Public Folders");
                ExchangeHelper.GetAllSubFolders(service,
                                                new ExchangeFolder()
                {
                    Folder = Folder.Bind(service, WellKnownFolderName.PublicFoldersRoot), IsPublicFolder = true
                }, folders,
                                                false);
            }

            // Are we limited folders to a specific list?
            if (_limitFolderList != null)
            {
                var newFolders = new List <ExchangeFolder>();
                foreach (var mailbox in _limitFolderList)
                {
                    var mailboxMatch = mailbox.ToLower().Replace('/', '\\');;
                    newFolders.AddRange(folders.Where(folder => folder.FolderPath.ToLower().Equals(mailboxMatch)));
                }
                folders = newFolders;
            }

            // Scan the folders to get message counts
            ExchangeHelper.GetFolderSummary(service, folders, _startDate, _endDate);
            folders.ForEach(folder => TotalMessages += !TestOnly ? folder.MessageCount : (folder.MessageCount > 20 ? 20 : folder.MessageCount));
            Logger.Debug("Found " + folders.Count + " folders and " + TotalMessages + " messages.");

            // Now build the folder list that we pass on to the next folders.
            foreach (var exchangeFolder in folders)
            {
                var folder = new MailFolder()
                {
                    SourceFolder      = exchangeFolder.FolderPath,
                    DestinationFolder = exchangeFolder.MappedDestination,
                    MessageCount      = exchangeFolder.MessageCount,
                };
                _mainFolderList.Add(folder);
            }
            // Now initialise the next read, I am not going to start reading unless I know the pipeline is groovy
            NextReader.Initialise(_mainFolderList);
            Status = MessageProcessorStatus.Initialised;
            Logger.Info("ExchangeExporter Initialised");
        }
Exemplo n.º 3
0
 public override void Initialise(List <MailFolder> folderList)
 {
     Status   = MessageProcessorStatus.Initialising;
     _folders = new List <ImapFolder>();
     try
     {
         _imapClient = new ImapClient(_server, _useSsl ? 993 : 143, _username, _password, AuthMethod.Login, _useSsl,
                                      delegate { return(true); });
         Logger.Debug("Logged into " + _server + " as " + _username);
         var folders = _imapClient.ListMailboxes();
         if (_startDate != null || _endDate != null)
         {
             // ok we need to do a search
             if (_startDate != null)
             {
                 _searchCondition = SearchCondition.Since((DateTime)_startDate);
             }
             if (_endDate != null)
             {
                 _searchCondition = _searchCondition == null
                     ? SearchCondition.Before((DateTime)_endDate)
                     : _searchCondition.And(SearchCondition.Before((DateTime)_endDate));
             }
             Logger.Debug("Only getting messages " + _searchCondition);
         }
         // Are we limiting the folder list?
         if (_limitFolderList != null)
         {
             var newFolders = new List <String>();
             foreach (var mailbox in _limitFolderList)
             {
                 var mailboxMatch = mailbox.ToLower().Replace('\\', '/');;
                 newFolders.AddRange(folders.Where(folder => folder.ToLower().Equals(mailboxMatch)));
             }
             folders = newFolders;
         }
         foreach (var folderPath in folders)
         {
             bool isPublicFolder    = false;
             var  destinationFolder = FolderMapping.ApplyMappings(folderPath, Provider);
             if (IncludePublicFolders && (String.Equals(destinationFolder, PublicFolderRoot) || destinationFolder.StartsWith(PublicFolderRoot + @"\")))
             {
                 isPublicFolder = true;
                 var start = PublicFolderRoot.Length + (destinationFolder.StartsWith(PublicFolderRoot + @"\") ? 1 : 0);
                 destinationFolder = destinationFolder.Substring(start, destinationFolder.Length - start);
             }
             if (!String.IsNullOrWhiteSpace(destinationFolder))
             {
                 try
                 {
                     var folder = _imapClient.GetMailboxInfo(folderPath);
                     if (folder.Messages == 0)
                     {
                         Logger.Debug("Skipping folder " + folderPath + ", no messages at all.");
                         continue;
                     }
                     int messageCount = 0;
                     if (_searchCondition != null)
                     {
                         var uids = _imapClient.Search(_searchCondition, folderPath);
                         messageCount = uids.Count();
                     }
                     else
                     {
                         messageCount = folder.Messages;
                     }
                     // Add it to our main folder list
                     _mainFolderList.Add(new MailFolder()
                     {
                         DestinationFolder = destinationFolder,
                         MessageCount      = FailedMessageCount,
                         SourceFolder      = folderPath
                     });
                     if (messageCount == 0)
                     {
                         Logger.Debug("Skipping folder " + folderPath + ", no messages within criteria.");
                         continue;
                     }
                     _folders.Add(new ImapFolder()
                     {
                         MappedDestination = destinationFolder,
                         FolderPath        = folder,
                         IsPublicFolder    = isPublicFolder
                     });
                     TotalMessages += !_testOnly ? messageCount : (messageCount > 20 ? 20 : messageCount);
                     Logger.Debug("Will process " + folderPath + " => " + (isPublicFolder ? "[PUBLIC FOLDER]/" : "") + destinationFolder + ", " + messageCount + " messages, " + TotalMessages + " messages total so far.");
                 }
                 catch (Exception ex)
                 {
                     Logger.Error("Failed to get Mailbox " + folderPath + ", skipping.", ex);
                 }
             }
             else
             {
                 Logger.Info("Ignoring folder " + folderPath + ", no destination specified.");
             }
         }
     }
     catch (InvalidCredentialsException ex)
     {
         Logger.Error("Imap Runner for " + _username + " [********] to " + _server + " failed : " + ex.Message, ex);
         throw new MessageProcessorException("Imap Runner for " + _username + " [********] to " + _server + " failed : " + ex.Message)
               {
                   Status = MessageProcessorStatus.SourceAuthFailure
               };
     }
     catch (SocketException ex)
     {
         Logger.Error("Imap Runner for " + _username + " [********] to " + _server + " failed : " + ex.Message, ex);
         throw new MessageProcessorException("Imap Runner for " + _username + " [********] to " + _server + " failed : " + ex.Message)
               {
                   Status = MessageProcessorStatus.ConnectionError
               };
     }
     NextReader.Initialise(_mainFolderList);
     Status = MessageProcessorStatus.Initialised;
     Logger.Info("ExchangeExporter Initialised");
 }