Ejemplo n.º 1
0
 private Uri CamelMessageUri(B_U_Camel.MessageInfo message_info)
 {
     return(EvolutionMailQueryable.EmailUri(this.account_name, this.folder_name, message_info.uid));
 }
Ejemplo n.º 2
0
        private Indexable CamelMessageToIndexable(B_U_Camel.MessageInfo messageInfo, string msg_file)
        {
            // Don't index messages flagged as junk
            if (messageInfo.IsJunk)
            {
                return(null);
            }

            // Many properties will be set by the filter when
            // processing the cached data, if it's there.  So
            // don't set a number of properties in that case.
            bool have_content = File.Exists(msg_file);

            Uri       uri       = CamelMessageUri(messageInfo);
            Indexable indexable = new Indexable(uri);

            indexable.Timestamp = messageInfo.SentDate;
            indexable.MimeType  = "message/rfc822";
            indexable.HitType   = "MailMessage";

            indexable.AddProperty(Property.NewUnsearched("fixme:account", this.imap_name));
            indexable.AddProperty(Property.NewUnsearched("fixme:folder", this.folder_name));
            indexable.AddProperty(Property.NewUnsearched("fixme:client", "evolution"));

            if (!have_content)
            {
                indexable.AddProperty(Property.New("dc:title", GMime.Utils.HeaderDecodePhrase(messageInfo.subject)));
                indexable.AddProperty(Property.NewDate("fixme:date", messageInfo.SentDate));
            }

            GMime.InternetAddressList addrs;
            addrs = GMime.InternetAddressList.Parse(messageInfo.to);
            foreach (GMime.InternetAddress ia in addrs)
            {
                GMime.InternetAddressMailbox mailbox = ia as GMime.InternetAddressMailbox;

                if (!have_content)
                {
                    indexable.AddProperty(Property.NewUnsearched("fixme:to", ia.ToString(false)));
                    if (ia is GMime.InternetAddressMailbox)
                    {
                        indexable.AddProperty(Property.New("fixme:to_address", mailbox.Address));
                    }

                    indexable.AddProperty(Property.New("fixme:to_name", ia.Name));
                }

                if (this.folder_name == "Sent" && ia is GMime.InternetAddressMailbox)
                {
                    indexable.AddProperty(Property.NewUnsearched("fixme:sentTo", mailbox.Address));
                }
            }
            addrs.Dispose();

            addrs = GMime.InternetAddressList.Parse(messageInfo.cc);
            foreach (GMime.InternetAddress ia in addrs)
            {
                GMime.InternetAddressMailbox mailbox = ia as GMime.InternetAddressMailbox;

                if (!have_content)
                {
                    indexable.AddProperty(Property.NewUnsearched("fixme:cc", ia.ToString(false)));
                    if (ia is GMime.InternetAddressMailbox)
                    {
                        indexable.AddProperty(Property.New("fixme:cc_address", mailbox.Address));
                    }

                    indexable.AddProperty(Property.New("fixme:cc_name", ia.Name));
                }

                if (this.folder_name == "Sent" && ia is GMime.InternetAddressMailbox)
                {
                    indexable.AddProperty(Property.NewUnsearched("fixme:sentTo", mailbox.Address));
                }
            }
            addrs.Dispose();

            addrs = GMime.InternetAddressList.Parse(messageInfo.from);
            foreach (GMime.InternetAddress ia in addrs)
            {
                GMime.InternetAddressMailbox mailbox = ia as GMime.InternetAddressMailbox;

                if (!have_content)
                {
                    indexable.AddProperty(Property.NewUnsearched("fixme:from", ia.ToString(false)));
                    if (ia is GMime.InternetAddressMailbox)
                    {
                        indexable.AddProperty(Property.New("fixme:from_address", mailbox.Address));
                    }

                    indexable.AddProperty(Property.New("fixme:from_name", ia.Name));
                }

                if (this.folder_name != "Sent" && ia is GMime.InternetAddressMailbox)
                {
                    indexable.AddProperty(Property.NewUnsearched("fixme:gotFrom", mailbox.Address));
                }
            }
            addrs.Dispose();

            indexable.AddProperty(Property.NewKeyword("fixme:mlist", messageInfo.mlist));

            Property flag_prop = Property.NewUnsearched("fixme:flags", messageInfo.flags);

            flag_prop.IsMutable = true;
            indexable.AddProperty(flag_prop);

            if (this.folder_name == "Sent")
            {
                indexable.AddProperty(Property.NewFlag("fixme:isSent"));
            }

            if (messageInfo.IsAnswered)
            {
                indexable.AddProperty(Property.NewFlag("fixme:isAnswered"));
            }

            if (messageInfo.IsDeleted)
            {
                indexable.AddProperty(Property.NewFlag("fixme:isDeleted"));
            }

            if (messageInfo.IsDraft)
            {
                indexable.AddProperty(Property.NewFlag("fixme:isDraft"));
            }

            if (messageInfo.IsFlagged)
            {
                indexable.AddProperty(Property.NewFlag("fixme:isFlagged"));
            }

            if (messageInfo.IsSeen)
            {
                indexable.AddProperty(Property.NewFlag("fixme:isSeen"));
            }

            if (messageInfo.HasAttachments && !have_content)
            {
                indexable.AddProperty(Property.NewFlag("fixme:hasAttachments"));
            }

            if (messageInfo.IsAnsweredAll)
            {
                indexable.AddProperty(Property.NewFlag("fixme:isAnsweredAll"));
            }

            if (have_content)
            {
                indexable.ContentUri = UriFu.PathToFileUri(msg_file);
            }
            else
            {
                indexable.NoContent = true;
            }

            return(indexable);
        }
Ejemplo n.º 3
0
        public override Indexable GetNextIndexable()
        {
            Indexable indexable = null;

            // No more new messages to index, so start on the removals.
            if (this.delete_mode)
            {
                string uid = (string)this.deleted_list [0];
                Uri    uri = EvolutionMailQueryable.EmailUri(this.account_name, this.folder_name, uid);

                indexable = new Indexable(IndexableType.Remove, uri);

                this.deleted_list.RemoveAt(0);
                this.tracker.Remove(uid);

                this.delete_count++;

                return(indexable);
            }

            B_U_Camel.MessageInfo mi = (B_U_Camel.MessageInfo) this.summary_enumerator.Current;

            ++this.count;

            if (Debug)
            {
                Logger.Log.Debug("Constructed message {0} with uid {1}, flags {2}.",
                                 this.count, mi.uid, mi.flags);
            }

            uint flags;
            bool found = this.tracker.Get(mi.uid, out flags);

            if (!found)
            {
                // New, previously unseen message
                string msg_file;

                if (this.backend_type == ImapBackendType.Imap)
                {
                    msg_file = Path.Combine(summary_info.DirectoryName, mi.uid + ".");
                }
                else
                {
                    // This is taken from e-d-s's camel-data-cache.c.  No doubt
                    // NotZed would scream bloody murder if he saw this here.
                    int    hash       = (g_str_hash(mi.uid) >> 5) & CAMEL_DATA_CACHE_MASK;
                    string cache_path = String.Format("cache/{0:x}/{1}", hash, mi.uid);
                    msg_file = Path.Combine(summary_info.DirectoryName, cache_path);
                }

                indexable = this.CamelMessageToIndexable(mi, msg_file);

                if (Debug)
                {
                    Logger.Log.Debug("Unseen message, indexable {0} null", indexable == null ? "" : "not");
                }

                if (indexable != null)
                {
                    ++this.indexed_count;
                }
            }
            else if (found && flags != mi.flags)
            {
                // Previously seen message, but flags have changed.
                Uri uri = CamelMessageUri(mi);
                indexable      = new Indexable(uri);
                indexable.Type = IndexableType.PropertyChange;

                Property flag_prop = Property.NewUnsearched("fixme:flags", mi.flags);
                flag_prop.IsMutable = true;
                indexable.AddProperty(flag_prop);

                if (Debug)
                {
                    Logger.Log.Debug("Previously seen message, flags changed: {0} -> {1}", flags, mi.flags);
                }

                ++this.indexed_count;
            }
            else
            {
                if (Debug)
                {
                    Logger.Log.Debug("Previously seen message, unchanged.");
                }
            }

            this.tracker.Update(mi.uid, mi.flags);

            return(indexable);
        }