Beispiel #1
0
        public ThunderbirdIndexableGenerator(ThunderbirdIndexer indexer, TB.Account account, string db_file)
        {
            this.indexer = indexer;
            this.indexer.NotificationEvent += OnNotification;
            this.account       = account;
            this.full_index    = true;
            this.db_file       = db_file;
            this.done          = false;
            this.relative_path = Thunderbird.GetRelativePath(db_file);

            // Load the database and make sure the enumerator is up to date. Otherwise we will
            // get lots of null exceptions when enumerating the database.
            LoadDatabase();
            ResetEnumerator();

            // Fetch all already stored uris in the index. This way we can remove one uri at the time
            // while we are indexing and thus in the end now which mails that doesn't exist anymore.
            if (relative_path != null)
            {
                stored_cache = indexer.Lucene.GetStoredUriStrings(account.Server, relative_path);
            }
            else
            {
                Logger.Log.Debug("Relative path could not be determined for: {0}. Indexing speed will suffer.",
                                 db_file);
            }
        }
        public void RemoveAccount(TB.Account account)
        {
            TB.Account acc = GetParentAccount(account.Path);

            if (acc == null)
            {
                return;
            }

            ScheduleRemoval(Property.NewKeyword("fixme:account", acc.Server), Scheduler.Priority.Delayed);
            OnNotification(new NotificationEventArgs(NotificationType.StopIndexing, account));
            account_list.Remove(acc);
        }
        public void IndexFile(string file)
        {
            TB.Account account = GetParentAccount(file);

            if (account == null || supported_types [account.Type] == null || Thunderbird.GetFileSize(file) < 1)
            {
                return;
            }

            object[] param = new object[] { this, account, file };
            ThunderbirdIndexableGenerator generator = Activator.CreateInstance(
                (Type)supported_types [account.Type], param) as ThunderbirdIndexableGenerator;

            AddIIndexableTask(generator, file);
        }
		public ThunderbirdIndexableGenerator (ThunderbirdIndexer indexer, TB.Account account, string db_file)
		{
			this.indexer = indexer;
			this.indexer.NotificationEvent += OnNotification;
			this.account = account;
			this.full_index = true;
			this.db_file = db_file;
			this.done = false;
			this.relative_path = Thunderbird.GetRelativePath (db_file);
			
			// Load the database and make sure the enumerator is up to date. Otherwise we will
			// get lots of null exceptions when enumerating the database.
			LoadDatabase ();
			ResetEnumerator ();

			// Fetch all already stored uris in the index. This way we can remove one uri at the time
			// while we are indexing and thus in the end now which mails that doesn't exist anymore.
			if (relative_path != null)
				stored_cache = indexer.Lucene.GetStoredUriStrings (account.Server, relative_path);
			else
				Logger.Log.Debug ("Relative path could not be determined for: {0}. Indexing speed will suffer.",
					db_file);
		}
        public void IndexAccount(TB.Account account)
        {
            TB.Account stored_account = GetParentAccount(account.Path);

            // We need to act upon changes made to accounts during Thunderbird runtime.
            // The user might change from plain to SSL, which leads to a new port number
            // that has to be taken in account for when indexing.
            if (stored_account == null && Directory.Exists(account.Path) && supported_types [account.Type] != null)
            {
                account_list.Add(account);
                IndexDirectory(account.Path);
                //Logger.Log.Info ("Indexing {0} account {1}", account.Type.ToString (), account.Server);
            }
            else if (stored_account == null && File.Exists(account.Path) && supported_types [account.Type] != null)
            {
                account_list.Add(account);
                IndexFile(account.Path);
                //Logger.Log.Info ("Indexing {0} account {1}", account.Type.ToString (), account.Server);
            }
            else if (stored_account != null &&
                     (stored_account.Server != account.Server ||
                      stored_account.Port != account.Port ||
                      stored_account.Type != account.Type ||
                      stored_account.Delimiter != account.Delimiter))
            {
                account_list.Remove(stored_account);
                account_list.Add(account);

                // Make sure all running indexables are aware of this since it can affect the way they index
                NotificationEventArgs args;
                args      = new NotificationEventArgs(NotificationType.UpdateAccountInformation, stored_account);
                args.Data = (object)account;
                OnNotification(args);

                Logger.Log.Info("Updated {0} with new account details", account.Server);
            }
        }
Beispiel #6
0
        protected virtual void OnNotification(object o, NotificationEventArgs args)
        {
            if (args.Account != account)
            {
                return;
            }

            switch (args.Type)
            {
            case NotificationType.StopIndexing:
                indexer.NotificationEvent -= OnNotification;
                Logger.Log.Debug("Stopping running task {0}", account.Server);
                break;

            case NotificationType.RestartIndexing:
                LoadDatabase();
                break;

            case NotificationType.UpdateAccountInformation:
                account = (TB.Account)args.Data;
                LoadDatabase();
                break;
            }
        }
Beispiel #7
0
 public ContactIndexableGenerator(ThunderbirdIndexer indexer, TB.Account account, string abook_file)
     : base(indexer, account, abook_file)
 {
 }
Beispiel #8
0
 public MailIndexableGenerator(ThunderbirdIndexer indexer, TB.Account account, string mork_file)
     : base(indexer, account, mork_file)
 {
 }
 public NotificationEventArgs(NotificationType type, TB.Account account)
 {
     this.type    = type;
     this.account = account;
 }
        private void OnInotifyEvent(Inotify.Watch watch,
                                    string path,
                                    string subitem,
                                    string srcpath,
                                    Inotify.EventType type)
        {
            if (subitem == null)
            {
                return;
            }

            string full_path = Path.Combine(path, subitem);

            // If prefs.js is deleted... then we have nothing at all to index
            if (((type & Inotify.EventType.MovedTo) != 0 && srcpath == Path.Combine(path, "prefs.js")) ||
                ((type & Inotify.EventType.Delete) != 0 && subitem == "prefs.js"))
            {
                foreach (TB.Account account in account_list)
                {
                    RemoveAccount(account);
                }
                return;
            }

            // Update in case an account was removed or added
            // Thunderbird saves prefs.js with a different name and then replacing the old one
            // by "moving" it over the existing prefs.js. That's why MoveTo is used as inotfy type.
            if ((((type & Inotify.EventType.Modify) != 0 || (type & Inotify.EventType.MovedTo) != 0 ||
                  (type & Inotify.EventType.Create) != 0) && subitem == "prefs.js"))
            {
                UpdateAccounts(path);
                return;
            }

            // In case the address book file have been moved or deleted, we have to stop indexing it
            if (((type & Inotify.EventType.MovedTo) != 0 && srcpath == Path.Combine(path, "abook.mab")) ||
                ((type & Inotify.EventType.Delete) != 0 && subitem == "abook.mab"))
            {
                TB.Account account = GetParentAccount(full_path);

                if (account != null)
                {
                    RemoveAccount(account);
                }

                return;
            }

            // In case of a newly created addressbook, the current address book is modified or an old
            // address book is moved to where the address book can be found: either start indexing
            // or restart an already indexing IndeaxbleGenerator.
            if ((((type & Inotify.EventType.Modify) != 0 || (type & Inotify.EventType.MovedTo) != 0 ||
                  (type & Inotify.EventType.Create) != 0) && subitem == "abook.mab"))
            {
                TB.Account account = GetParentAccount(full_path);

                if (account == null && File.Exists(full_path))
                {
                    UpdateAccounts(path);
                    return;
                }
                else if (account == null)
                {
                    return;
                }

                // Tell any running indexable about this or start a new one
                if (queryable.ThisScheduler.ContainsByTag(full_path))
                {
                    OnNotification(new NotificationEventArgs(NotificationType.RestartIndexing, account));
                }
                else
                {
                    IndexFile(full_path);
                }

                return;
            }

            // Re-index files when needed
            if ((type & Inotify.EventType.Modify) != 0)
            {
                TB.Account account = GetParentAccount(full_path);

                if (account == null || !Thunderbird.IsMorkFile(path, subitem))
                {
                    return;
                }

                // In case we have a running IndexableGenerator, tell it that we have a file that needs to
                // be re-indexed.
                if (queryable.ThisScheduler.ContainsByTag(full_path))
                {
                    OnNotification(new NotificationEventArgs(NotificationType.RestartIndexing, account));
                }
                else
                {
                    IndexFile(full_path);
                }

                return;
            }

            // Index newly created directories
            if ((type & Inotify.EventType.Create) != 0 && (type & Inotify.EventType.IsDirectory) != 0)
            {
                if (GetParentAccount(full_path) != null && Inotify.Enabled)
                {
                    Inotify.Subscribe(full_path, OnInotifyEvent, Inotify.EventType.All);
                }

                return;
            }
        }
		public NotificationEventArgs (NotificationType type, TB.Account account)
		{
			this.type = type;
			this.account = account;
		}
		protected virtual void OnNotification (object o, NotificationEventArgs args)
		{
			if (args.Account != account)
				return;
			
			switch (args.Type) {
			case NotificationType.StopIndexing:
				indexer.NotificationEvent -= OnNotification;
				Logger.Log.Debug ("Stopping running task {0}", account.Server);
				break;
				
			case NotificationType.RestartIndexing:
				LoadDatabase ();
				break;
				
			case NotificationType.UpdateAccountInformation:
				account = (TB.Account) args.Data;
				LoadDatabase ();
				break;
				
			}
		}
Beispiel #13
0
 public NntpIndexableGenerator(ThunderbirdIndexer indexer, TB.Account account, string file)
     : base(indexer, account, file)
 {
 }