public Indexable GetNextIndexable()
        {
            GMime.Message message = null;
            try {
                message = mbox_parser.ConstructMessage();
            } catch (System.IO.FileNotFoundException e) {
                Logger.Log.Warn("mbox " + mbox_file + " deleted while parsing.");
                return(null);
            }

            try {
                // Again comment from Evo :P
                // Work around what I think is a bug in GMime: If you
                // have a zero-byte file or seek to the end of a
                // file, parser.Eos () will return true until it
                // actually tries to read something off the wire.
                // Since parser.ConstructMessage() always returns a
                // message (which may also be a bug), we'll often get
                // one empty message which we need to deal with here.
                //
                // Check if its empty by seeing if the Headers
                // property is null or empty.
                if (message == null || message.Headers == null || message.Headers == "")
                {
                    return(null);
                }

                // mbox KIO slave uses the From line as URI - how weird!
                // are those lines supposed to be unique ???
                string     id  = mbox_parser.From;
                System.Uri uri = EmailUri(id);

                Indexable indexable = indexer.MessageToIndexable(mbox_file, uri, message, indexer.GetFolderMbox(mbox_file));

                if (indexable == null)
                {
                    return(null);
                }

                ++indexed_count;

                return(indexable);
            } finally {
                if (message != null)
                {
                    message.Dispose();
                }
            }
        }
Exemple #2
0
        void DropEmailUriList(Gtk.DragDataReceivedArgs args)
        {
            string uri_string = Encoding.UTF8.GetString(args.SelectionData.Data);

            subject_list = new List <string>();

            UriList uri_list = new UriList(uri_string);

            foreach (Uri uri in uri_list)
            {
                Logger.Debug("Evolution: Dropped URI: {0}", uri.LocalPath);

                int mail_fd = Syscall.open(uri.LocalPath, OpenFlags.O_RDONLY);
                if (mail_fd == -1)
                {
                    continue;
                }

                GMime.Stream stream = new GMime.StreamFs(mail_fd);
                GMime.Parser parser = new GMime.Parser(stream);
                parser.ScanFrom = true;

                // Use GMime to read the RFC822 message bodies (in temp
                // files pointed to by a uri-list) in MBOX format, so we
                // can get subject/sender/date info.
                while (!parser.Eos())
                {
                    GMime.Message message = parser.ConstructMessage();
                    if (message == null)
                    {
                        break;
                    }

                    Logger.Debug("Evolution: Message Subject: {0}", message.Subject);
                    subject_list.Add(message.Subject);
                    message.Dispose();
                }
                ;

                parser.Dispose();
                stream.Close();
                stream.Dispose();
            }
        }
        void HandleDrop(int xx, int yy, bool first, Uri uri, string cm_path_folderitem, string msgid)
        {
            // get subject
            string subject = "<unknown>";
            int    mail_fd = Syscall.open(uri.LocalPath, OpenFlags.O_RDONLY);

            if (mail_fd != -1)
            {
                GMime.Stream stream = new GMime.StreamFs(mail_fd);
                GMime.Parser parser = new GMime.Parser(stream);

                parser.ScanFrom = false;
                while (!parser.Eos())
                {
                    GMime.Message message = parser.ConstructMessage();
                    if (message == null)
                    {
                        break;
                    }
                    subject = message.Subject;
                    message.Dispose();
                }
                parser.Dispose();
                stream.Close();
                stream.Dispose();
            }

            // Place the cursor in the position where the uri was
            // dropped, adjusting x,y by the TextView's VisibleRect.
            Gdk.Rectangle rect = Window.Editor.VisibleRect;
            xx += rect.X;
            yy += rect.Y;
            Gtk.TextIter cursor = Window.Editor.GetIterAtLocation(xx, yy);
            Buffer.PlaceCursor(cursor);

            int start_offset;

            if (!first)
            {
                cursor = Buffer.GetIterAtMark(Buffer.InsertMark);

                if (cursor.LineOffset == 0)
                {
                    Buffer.Insert(ref cursor, "\n");
                }
                else
                {
                    Buffer.Insert(ref cursor, ", ");
                }
            }

            EmailLink link_tag;

            link_tag          = (EmailLink)Note.TagTable.CreateDynamicTag("link:cm-mail");
            link_tag.EmailUri = cm_path_folderitem + "/<" + msgid + ">";

            cursor       = Buffer.GetIterAtMark(Buffer.InsertMark);
            start_offset = cursor.Offset;
            Buffer.Insert(ref cursor, subject);
            Gtk.TextIter start = Buffer.GetIterAtOffset(start_offset);
            Gtk.TextIter end   = Buffer.GetIterAtMark(Buffer.InsertMark);
            Buffer.ApplyTag(link_tag, start, end);
        }
		private void DoGMailQuery (string query, int maxhits, IQueryResult result)
		{
			Log.Debug ("GMailSearchDriver: Searching for [{0}]", query);
			MessageSet results = imap_client.Search (query, false);
			if (results == null) {
				return;
			}

			Log.Debug ("Recvd {0} messages", results.Messages.Count);

			// Get the messages in reverse order; latest first
			ArrayList matched_ids = new ArrayList (results.Messages);
			matched_ids.Reverse ();

			const int MAX_QUEUED_HITS = 25;
			int left = Math.Min (maxhits, matched_ids.Count);
			ArrayList result_batch = new ArrayList (MAX_QUEUED_HITS);

			MailCollection emails;
			GMime.StreamMem stream;
			GMime.Parser parser;
			GMime.Message message;
			Hit hit;

			foreach (string id in matched_ids) {
				if (left -- == 0)
					break;
				Log.Debug ("Fetching headers for message id {0}", id);

				emails = imap_client.FetchMessages (id, id, false,true,false);
				if (emails == null || emails.Count == 0) {
					Log.Error ("IMAP error: {0}", imap_client.LastError);
					continue;
				}

				foreach (Mail m in emails) {
					hit = null;

					using (stream = new GMime.StreamMem (m.Header))
					using (parser = new GMime.Parser (stream))
					using (message = parser.ConstructMessage ())
						hit = MessageToHit (message);

					if (hit == null) {
						Log.Error ("Bad IMAP email {0}: no msg-id", id);
						continue;
					} else {
						result_batch.Add (hit);
					}
				}

				if (result_batch.Count >= MAX_QUEUED_HITS) {
					result.Add (result_batch);
					result_batch.Clear ();
				}
			}

			result.Add (result_batch, matched_ids.Count);
		}
        void HandleDrop(int xx, int yy, bool first, Uri uri, string cm_path_folderitem, string msgid)
        {
            // get subject
            string subject = "<unknown>";
            int mail_fd = Syscall.open(uri.LocalPath, OpenFlags.O_RDONLY);
            if(mail_fd != -1) {
                GMime.Stream stream = new GMime.StreamFs(mail_fd);
                GMime.Parser parser = new GMime.Parser(stream);

                parser.ScanFrom = false;
                while(!parser.Eos()) {
                    GMime.Message message = parser.ConstructMessage();
                    if(message == null)
                        break;
                    subject = message.Subject;
                    message.Dispose();
                }
                parser.Dispose();
                stream.Close();
                stream.Dispose();
            }

            // Place the cursor in the position where the uri was
            // dropped, adjusting x,y by the TextView's VisibleRect.
            Gdk.Rectangle rect = Window.Editor.VisibleRect;
            xx += rect.X;
            yy += rect.Y;
            Gtk.TextIter cursor = Window.Editor.GetIterAtLocation(xx, yy);
            Buffer.PlaceCursor(cursor);

            int start_offset;

            if(!first) {
                cursor = Buffer.GetIterAtMark(Buffer.InsertMark);

                if(cursor.LineOffset == 0)
                    Buffer.Insert(ref cursor, "\n");
                else
                    Buffer.Insert(ref cursor, ", ");
            }

            EmailLink link_tag;
            link_tag = (EmailLink) Note.TagTable.CreateDynamicTag("link:cm-mail");
            link_tag.EmailUri = cm_path_folderitem + "/<" + msgid + ">";

            cursor = Buffer.GetIterAtMark(Buffer.InsertMark);
            start_offset = cursor.Offset;
            Buffer.Insert(ref cursor, subject);
            Gtk.TextIter start = Buffer.GetIterAtOffset(start_offset);
            Gtk.TextIter end = Buffer.GetIterAtMark(Buffer.InsertMark);
            Buffer.ApplyTag(link_tag, start, end);
        }
Exemple #6
0
        private void DoGMailQuery(string query, int maxhits, IQueryResult result)
        {
            Log.Debug("GMailSearchDriver: Searching for [{0}]", query);
            MessageSet results = imap_client.Search(query, false);

            if (results == null)
            {
                return;
            }

            Log.Debug("Recvd {0} messages", results.Messages.Count);

            // Get the messages in reverse order; latest first
            ArrayList matched_ids = new ArrayList(results.Messages);

            matched_ids.Reverse();

            const int MAX_QUEUED_HITS = 25;
            int       left            = Math.Min(maxhits, matched_ids.Count);
            ArrayList result_batch    = new ArrayList(MAX_QUEUED_HITS);

            MailCollection emails;

            GMime.StreamMem stream;
            GMime.Parser    parser;
            GMime.Message   message;
            Hit             hit;

            foreach (string id in matched_ids)
            {
                if (left-- == 0)
                {
                    break;
                }
                Log.Debug("Fetching headers for message id {0}", id);

                emails = imap_client.FetchMessages(id, id, false, true, false);
                if (emails == null || emails.Count == 0)
                {
                    Log.Error("IMAP error: {0}", imap_client.LastError);
                    continue;
                }

                foreach (Mail m in emails)
                {
                    hit = null;

                    using (stream = new GMime.StreamMem(m.Header))
                        using (parser = new GMime.Parser(stream))
                            using (message = parser.ConstructMessage())
                                hit = MessageToHit(message);

                    if (hit == null)
                    {
                        Log.Error("Bad IMAP email {0}: no msg-id", id);
                        continue;
                    }
                    else
                    {
                        result_batch.Add(hit);
                    }
                }

                if (result_batch.Count >= MAX_QUEUED_HITS)
                {
                    result.Add(result_batch);
                    result_batch.Clear();
                }
            }

            result.Add(result_batch, matched_ids.Count);
        }
		void DropEmailUriList (Gtk.DragDataReceivedArgs args)
		{
			string uri_string = Encoding.UTF8.GetString (args.SelectionData.Data);

			subject_list = new List<string>();

			UriList uri_list = new UriList (uri_string);
			foreach (Uri uri in uri_list) {
				Logger.Debug ("Evolution: Dropped URI: {0}", uri.LocalPath);

				int mail_fd = Syscall.open (uri.LocalPath, OpenFlags.O_RDONLY);
				if (mail_fd == -1)
					continue;

				GMime.Stream stream = new GMime.StreamFs (mail_fd);
				GMime.Parser parser = new GMime.Parser (stream);
				parser.ScanFrom = true;

				// Use GMime to read the RFC822 message bodies (in temp
				// files pointed to by a uri-list) in MBOX format, so we
				// can get subject/sender/date info.
				while (!parser.Eos()) {
					GMime.Message message = parser.ConstructMessage ();
					if (message == null)
						break;
					
					Logger.Debug ("Evolution: Message Subject: {0}", message.Subject);
					subject_list.Add (message.Subject);
					message.Dispose ();
				};

				parser.Dispose ();
				stream.Close ();
				stream.Dispose ();
			}
		}