[PATCH] add evo imap folders to be indexed by beagle



Hi guys,

I have attached a patch that indexes imap folders as well as local
folders from evolution.  There is one limitation which I will fix
soon, and it is that if 2 folders for the same imap account have the
same name but at different levels of hierarchy...then it indexes both
folders using the same dataName.

Hope the patch is of use.

Take Care

Zaheer Abbas Merali

PS Thanks Nat for showing the demo of Beagle at Guadec :)
Index: IndexMail.cs
===================================================================
RCS file: /cvs/gnome/beagle/tools/IndexMail.cs,v
retrieving revision 1.16
diff -u -r1.16 IndexMail.cs
--- a/IndexMail.cs	16 Jun 2004 00:44:59 -0000	1.16
+++ b/IndexMail.cs	2 Jul 2004 16:01:45 -0000
@@ -603,9 +603,117 @@
 				PathFinder.WriteAppDataLine ("IndexMail", dataName, latestTime.Ticks.ToString ());
 		}
 
+		public void ScanImap (String folderName, String fullFolderName, String accountName, String summaryFile)
+		{
+			Camel.Summary summary = Camel.Summary.load (summaryFile);
+
+			String dataName = "lastScan-" + folderName;
+
+			DateTime lastTime = new DateTime (0);
+			String lastTimeStr = PathFinder.ReadAppDataLine ("IndexMail", dataName);
+			if (lastTimeStr != null) {
+				try {
+					long ticks = long.Parse (lastTimeStr);
+					lastTime = new DateTime (ticks);
+				} catch { }
+			}
+
+			DateTime latestTime = lastTime;
+
+			ASCIIEncoding encoding = new ASCIIEncoding ();
+			Stream imapStream = null;
+
+			/* FIXME: Problems with basing everything off of the summary
+			   (1) We don't notice when messages are expunged -- they will stay in the index.
+			   (2) We don't notice changes in the flags.
+			*/
+
+			int count = 0, indexedCount = 0;
+			foreach (Camel.ImapMessageInfo mi in summary.messages) {
+                                //Console.WriteLine("Message Info: "+mi);
+
+				if ((count & 15) == 0)
+					MessageStatus ("{0}: indexed {1} messages ({2}/{3} {4:###.0}%)",
+						       folderName, indexedCount,
+						       count, summary.header.count, 
+						       100.0 * count / summary.header.count);
+				++count;
+
+				if (lastTime < mi.Date) {
+
+					if (latestTime < mi.Date)
+						latestTime = mi.Date;
+                                        String imapFile = Path.Combine(fullFolderName,mi.uid)+".";
+					//Console.WriteLine("Message file: "+imapFile);
+					try {
+						imapStream = new FileStream (imapFile, FileMode.Open, FileAccess.Read);
+					
+	
+      						TextReader textReader = new StreamReader (imapStream, encoding);
+						LineReader reader = new LineReader (textReader);
+
+						// Parse an RFC 2822 message from the array of lines
+						MailMessage msg = new MailMessage (reader, mi.size);
+
+					//Console.WriteLine ("From: {0}", mi.from);
+					//Console.WriteLine ("Subject: {0}", mi.subject);
+                                        //Console.WriteLine ("Account: "+accountName);
+						Schedule (new IndexableMail (accountName,
+									     folderName,
+									     mi,
+									     msg));
+	                                        imapStream.Close();
+					}
+					catch { }
+					++indexedCount;
+				}
+			}
+
+			MessageFinished ("{0}: indexed {1} of {2} messages", folderName, indexedCount, count);
+
+			//if (mboxStream != null)
+			//	mboxStream.Close ();
+
+			if (latestTime != lastTime)
+				PathFinder.WriteAppDataLine ("IndexMail", dataName, latestTime.Ticks.ToString ());
+		}
+
+
 	}
+        
+ 
+
 
 	class IndexMailTool {
+		static void scanImapAccount(String account, DirectoryInfo currentd, MailScanner scanner)
+		{
+                        foreach (DirectoryInfo folder in currentd.GetDirectories()) {
+                                if (folder.Name.EndsWith("folders")) {
+	                                foreach (DirectoryInfo d in folder.GetDirectories()) {
+	                                        Console.WriteLine("Imap folder: "+d.Name);
+	                                        String summaryFile = null;
+	                                        foreach (FileInfo f in d.GetFiles()) {
+	                                                if (f.Name == "summary") {
+	                                                   summaryFile = f.FullName;
+	                                                   break;
+	                                                }
+	                                        }
+	                                        if (summaryFile != null) {
+	                                                scanner.ScanImap(account+"-"+d.Name,d.FullName,
+	                                                                 account,summaryFile);
+	                                        // also repeat scanImapAccount for current folder
+	                                                scanImapAccount(account, d, scanner);
+	
+	                                        }
+	                                 }
+                                                              
+                                                              
+                                                              
+
+                                           
+	                         }
+                        }
+		}
 
 		static void Main (String[] args)
 		{
@@ -652,6 +760,19 @@
 			}
 			
 			scanner.Flush ();
+
+                        String imap = Environment.GetEnvironmentVariable ("HOME");
+                        imap = Path.Combine (imap, ".evolution/mail/imap");
+                        
+                        dir = new DirectoryInfo (imap);
+
+                        foreach (DirectoryInfo account in dir.GetDirectories()) {
+                                Console.WriteLine("Imap: "+account.Name);
+                                scanImapAccount(account.Name, account, scanner);
+                        }
+                        scanner.Flush();
+
+
 		}
 	}
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]