//strip out the VC property on receipt so that replies and forwards report correctly //redundant as the VC addin will only add it back public static void ItemSent(object item) { try { Outlook.MailItem email = (Outlook.MailItem)item; Outlook.ItemProperties properties = email.ItemProperties; Outlook.ItemProperty property = properties.Cast <Outlook.ItemProperty>().Where(c => c.Name == "In Virtual Cabinet").FirstOrDefault(); string fileId = XLOutlook.ReadParameter("VCFileID", email); //Only if the e-mail is not a draft handled within VC //strip out the field if (property != null && (fileId == null || fileId == "")) { //MessageBox.Show(property.Name + ":" + property.Value); property.Delete(); //MessageBox.Show("Deleted"); } XLOutlook.UpdateParameter("VCFileID", "", email); //for testing purposes try it again to make sure it is gone //property = properties.Cast<Outlook.ItemProperty>().Where(c => c.Name == "In Virtual Cabinet").FirstOrDefault(); //if (property == null) //{ // MessageBox.Show("Gone"); //} //else //{ // MessageBox.Show(property.Name + ":" + property.Value); //} } catch (Exception ex) { XLtools.LogException("ItemSent", ex.ToString()); } }
public static void CreateToDo(XLVirtualCabinet.FileInfo file) { try { if (ToDoFolder == null) { SetToDoFolder(); } Outlook.TaskItem toDo = Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olTaskItem) as Outlook.TaskItem; string desc = file.ClientString; desc = desc + " - " + file.Description; toDo.Subject = desc; toDo.StartDate = DateTime.Now; toDo.DueDate = DateTime.Now.AddDays(1); //toDo.Body = file.FileID; XLOutlook.UpdateParameter(fileIdName, file.FileID, toDo); toDo.Move(ToDoFolder); toDo.Save(); } catch (Exception ex) { XLant.XLtools.LogException("CreateToDo", ex.ToString()); MessageBox.Show("Could not add To Do", "Add To Do", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void IndexDraft(Outlook.MailItem email) { try { XLant.XLVirtualCabinet.BondResult outcome = IndexEmail(email, "Draft"); if (outcome.ExitCode != 0) { MessageBox.Show("Unable to index document, please index manually. Error code: " + outcome.ExitCode.ToString() + "-" + outcome.StandardOutput.ToString()); } else { UpdateVCTick(email); // As the filing has been successfull, get the FileId returned from Bond via the Standard Output string fileid = Regex.Match(outcome.StandardOutput, @"\d+").ToString(); string folderpath = XLtools.TempPath(); string commandfilepath = ""; commandfilepath = folderpath + "\\" + (String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now)) + ".bond"; StreamWriter commandfile = new StreamWriter(commandfilepath, false, System.Text.Encoding.Default); commandfile.WriteLine("<<MODE=EDIT>>"); commandfile.WriteLine("<<INDEX01=" + fileid + ">>"); commandfile.WriteLine("<<OPENDOCUMENT=FALSE>>"); commandfile.Flush(); commandfile.Close(); // Call Bond to check out the document XLVirtualCabinet.BondResult result = XLVirtualCabinet.LaunchCabi(commandfilepath, false); // Dispose of the command file object commandfile.Dispose(); // Look for the file in the edited documents folder based on the FileId List <string> msgfile = new List <string>(); string[] Files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Virtual Cabinet\\Edited documents"); int FilesCount = Files.Length; // Collect all the entries which match the fileID for (int i = 0; i < FilesCount; i++) { string f = Files[i].ToString(); if (Path.GetFileName(f).StartsWith(fileid + "-")) { msgfile.Add(f); } } if (msgfile.Count != 1) { Exception exception = new Exception("Unable to find the mail message. Your file has been indexed but could not have the file ID added."); } else { // Add the Virtual Cabinet FileId to the Subject of the email (still open on screen) // UserProperties and Custom Headers do not persist, so using something that does. Body could be another option. XLOutlook.UpdateParameter("VCFileID", fileid, email); //email.Subject = email.Subject + @" FileId:" + fileid.ToString(); // Save the MailItem email.Save(); // Save the email in the default MSG format if (File.Exists(msgfile[0])) { File.Delete(msgfile[0]); } email.SaveAs(msgfile[0]); // Create a command file to save the document as a new version based on the FileId commandfilepath = folderpath + "\\" + (String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now)) + ".bond"; commandfile = new StreamWriter(commandfilepath, false, System.Text.Encoding.Default); commandfile.WriteLine("<<MODE=SAVE>>"); commandfile.WriteLine("<<INDEX01=" + fileid + ">>"); commandfile.Flush(); commandfile.Close(); // Call Bond to save the email back to VC result = XLVirtualCabinet.LaunchCabi(commandfilepath, false); // Dispose of the command file object commandfile.Dispose(); // Close the email in Outlook to prevent further changes that won't be saved to VC email.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave); // Delete the email from the Drafts folder in Outlook email.UnRead = false; email.Delete(); } } } catch (Exception ex) { MessageBox.Show("Unable to index draft email"); XLtools.LogException("IndexDraft", ex.ToString()); } }