/** * Advance to the next mail in the mbox file. */ public bool HasNextIndexable() { if (mbox_fd < 0) { Logger.Log.Debug("Opening mbox {0}", mbox_file); try { KMailQueryable.InitializeGMime(); } catch (Exception e) { Logger.Log.Warn(e, "Caught exception trying to initalize gmime:"); return(false); } try { mbox_fd = Mono.Unix.Native.Syscall.open(mbox_file, Mono.Unix.Native.OpenFlags.O_RDONLY); } catch (System.IO.FileNotFoundException e) { Logger.Log.Warn("mbox " + mbox_file + " deleted while indexing."); return(false); } mbox_stream = new GMime.StreamFs(mbox_fd); if (initial_scan && !IsUpToDate(mbox_file)) { // this is the initial scan and // file has changed since last scan => // set mboxlastoffset to 0 and seek to 0 mbox_stream.Seek((int)(MboxLastOffset = 0)); } else { mbox_stream.Seek((int)MboxLastOffset); } mbox_parser = new GMime.Parser(mbox_stream); mbox_parser.ScanFrom = true; } if (mbox_parser.Eos()) { // save the state ASAP Checkpoint(); mbox_stream.Close(); mbox_fd = -1; mbox_stream.Dispose(); mbox_stream = null; mbox_parser.Dispose(); mbox_parser = null; Logger.Log.Debug("{0}: Finished indexing {1} messages", folder_name, indexed_count); return(false); } else { return(true); } }
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(); } }
public override bool HasNextIndexable () { if (this.account_name == null) { if (!Setup ()) { this.queryable.RemoveGenerator (this); return false; } } if (this.mbox_fd < 0) { Logger.Log.Debug ("Opening mbox {0}", this.mbox_info.Name); try { InitializeGMime (); } catch (Exception e) { Logger.Log.Warn (e, "Caught exception trying to initalize gmime:"); return false; } this.mbox_fd = Mono.Unix.Native.Syscall.open (this.mbox_info.FullName, Mono.Unix.Native.OpenFlags.O_RDONLY); if (this.mbox_fd < 0) { Log.Error ("Unable to open {0}: {1}", this.mbox_info.FullName, Mono.Unix.Native.Stdlib.strerror (Mono.Unix.Native.Stdlib.GetLastError ())); return false; } this.mbox_stream = new GMime.StreamFs (this.mbox_fd); this.mbox_stream.Seek (this.MboxLastOffset); this.mbox_parser = new GMime.Parser (this.mbox_stream); this.mbox_parser.ScanFrom = true; FileInfo info = new FileInfo (this.mbox_info.FullName); this.file_size = info.Length; } if (this.mbox_parser.Eos ()) { long offset = this.mbox_parser.FromOffset; this.mbox_stream.Close (); this.mbox_fd = -1; this.mbox_stream.Dispose (); this.mbox_stream = null; this.mbox_parser.Dispose (); this.mbox_parser = null; Logger.Log.Debug ("{0}: Finished indexing {1} messages", this.folder_name, this.indexed_count); if (offset >= 0) this.MboxLastOffset = offset; this.CrawlFinished (); return false; } else return true; }
public override bool HasNextIndexable() { if (this.account_name == null) { if (!Setup()) { this.queryable.RemoveGenerator(this); return(false); } } if (this.mbox_fd < 0) { Logger.Log.Debug("Opening mbox {0}", this.mbox_info.Name); try { InitializeGMime(); } catch (Exception e) { Logger.Log.Warn(e, "Caught exception trying to initalize gmime:"); return(false); } this.mbox_fd = Mono.Unix.Native.Syscall.open(this.mbox_info.FullName, Mono.Unix.Native.OpenFlags.O_RDONLY); if (this.mbox_fd < 0) { Log.Error("Unable to open {0}: {1}", this.mbox_info.FullName, Mono.Unix.Native.Stdlib.strerror(Mono.Unix.Native.Stdlib.GetLastError())); return(false); } this.mbox_stream = new GMime.StreamFs(this.mbox_fd); this.mbox_stream.Seek(this.MboxLastOffset); this.mbox_parser = new GMime.Parser(this.mbox_stream); this.mbox_parser.ScanFrom = true; FileInfo info = new FileInfo(this.mbox_info.FullName); this.file_size = info.Length; } if (this.mbox_parser.Eos()) { long offset = this.mbox_parser.FromOffset; this.mbox_stream.Close(); this.mbox_fd = -1; this.mbox_stream.Dispose(); this.mbox_stream = null; this.mbox_parser.Dispose(); this.mbox_parser = null; Logger.Log.Debug("{0}: Finished indexing {1} messages", this.folder_name, this.indexed_count); if (offset >= 0) { this.MboxLastOffset = offset; } this.CrawlFinished(); return(false); } else { return(true); } }
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); }
/** * Advance to the next mail in the mbox file. */ public bool HasNextIndexable () { if (mbox_fd < 0) { Logger.Log.Debug ("Opening mbox {0}", mbox_file); try { KMailQueryable.InitializeGMime (); } catch (Exception e) { Logger.Log.Warn (e, "Caught exception trying to initalize gmime:"); return false; } try { mbox_fd = Mono.Unix.Native.Syscall.open (mbox_file, Mono.Unix.Native.OpenFlags.O_RDONLY); } catch (System.IO.FileNotFoundException e) { Logger.Log.Warn ("mbox " + mbox_file + " deleted while indexing."); return false; } mbox_stream = new GMime.StreamFs (mbox_fd); if (initial_scan && !IsUpToDate (mbox_file)) // this is the initial scan and // file has changed since last scan => // set mboxlastoffset to 0 and seek to 0 mbox_stream.Seek ((int)(MboxLastOffset = 0)); else mbox_stream.Seek ((int) MboxLastOffset); mbox_parser = new GMime.Parser (mbox_stream); mbox_parser.ScanFrom = true; } if (mbox_parser.Eos ()) { // save the state ASAP Checkpoint (); mbox_stream.Close (); mbox_fd = -1; mbox_stream.Dispose (); mbox_stream = null; mbox_parser.Dispose (); mbox_parser = null; Logger.Log.Debug ("{0}: Finished indexing {1} messages", folder_name, indexed_count); return false; } else return true; }
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); }
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 (); } }