private static void PerformMailFix(string folderId, RDOSession session, TimeSpan delta) { RDOFolder folder = session.GetFolderFromID(folderId); if ((folder.FolderKind == rdoFolderKind.fkSearch) || (delta == TimeSpan.Zero)) { return; } DateTime oldTimeStamp, newTimeStamp; foreach (RDOMail item in folder.Items) { oldTimeStamp = item.ReceivedTime; newTimeStamp = Options.BackInTime ? (oldTimeStamp - delta) : (oldTimeStamp + delta); item.ReceivedTime = newTimeStamp; if (!Options.TestMode) { item.Save(); } count++; Debug.WriteLine($" ReceivedTime is {oldTimeStamp}, set to {newTimeStamp}"); } foreach (RDOFolder subFolder in folder.Folders) { Debug.WriteLine($" Processing subfolder {subFolder.Name}"); PerformMailFix(subFolder.EntryID, session, delta); } }
private void convertButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(pstOutputPath.Text) || string.IsNullOrEmpty(folderInputPath.Text)) { MessageBox.Show("Please select both paths !"); return; } RDOSession session = new RDOSession(); // throws exception 1 session.LogonPstStore(pstOutputPath.Text); RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox); string[] fileEntries = Directory.GetFiles(folderInputPath.Text, "*.eml"); foreach (string filePath in fileEntries) { RDOMail mail = folder.Items.Add("IPM.Mail"); mail.Sent = true; mail.Import(filePath, 1024); // folder.Items.Add(mail); mail.Save(); } session.Logoff(); MessageBox.Show("Done converting !"); }
public string getMails() { StringBuilder sb = new StringBuilder(); RDOFolder folder = rdo.GetDefaultFolder(rdoDefaultFolders.olFolderInbox); string sSQL = "Select Subject from Folder WHERE Subject LIKE '%Your license order%'"; //sSQL = "Select Subject from Folder where Subject<>''"; RDOMail item; RDOItems items = folder.Items; item = items.Find(sSQL); if (item == null) { sb.Append("no data found"); } while (item != null) { sb.Append("===========================\r\n"); sb.Append(item.ReceivedByName + ":"); sb.Append(item.Subject + ":"); if (item.Attachments.Count > 0) { foreach (RDOAttachment a in item.Attachments) { sb.Append("\t" + a.FileName + "\r\n"); } } sb.Append("\r\n"); item = items.FindNext(); } return(sb.ToString()); foreach (RDOMail m in folder.Items) { try { sb.Append("===========================\r\n"); sb.Append(m.ReceivedByName + ":"); sb.Append(m.Subject + ":"); if (m.Attachments.Count > 0) { foreach (RDOAttachment a in m.Attachments) { sb.Append("\t" + a.FileName + "\r\n"); } } sb.Append("\r\n"); } catch (Exception ex) { helpers.addExceptionLog(m.ToString() + " is not an email"); } } return(sb.ToString()); }
public static void SyncPSTFiles() { if (Global.isSyncing) { Log.Append("ERROR: Cannot sync pst files because email synchronization is in progress"); return; } TimeSpan startTime = DateTime.Now.TimeOfDay; Log.Append("Syncing all available .pst files..."); string[] pstFiles = Directory.GetFiles(pstSyncDirectoryPath, "*.pst*"); foreach (string filePath in pstFiles.Where(x => !x.Contains("tmp"))) { string dumpPath = pstDumpDirectoryPath + Path.GetFileName(filePath); File.Move(filePath, dumpPath); Log.Append(String.Format(" Syncing emails from pst file '{0}'", Path.GetFileName(filePath))); RDOSession session = new RDOSession(); session.LogonPstStore(dumpPath); RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox); // Log-purpose parameters int pstEmailCount = folder.Items.Count; int currentEmailCount = 0; foreach (RDOMail mail in folder.Items) { currentEmailCount++; Email email = new Email() { ID = Global.GetAttachmentID(), UID = mail.EntryID, To = mail.To, From = mail.SenderEmailAddress, Subject = mail.Subject, MailDate = mail.SentOn }; email.RetrieveMsg(); Global.AppendEmail(email, String.Format("{0}/{1}", currentEmailCount, pstEmailCount)); mail.SaveAs(Global.messagesDirectoryPath + email.ID + ".eml", rdoSaveAsType.olRFC822); } session.Logoff(); } pstFiles.Where(x => !x.Contains("tmp")).ForEach(x => Log.Append(String.Format(" Moving pst. file \"{0}\"", x))); Log.Append(String.Format("Synced all available PST files. Process took {0}", Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds))); }
private List <RDOMail> GetFolderItems(RDOFolder folder) { var folderItemList = new List <RDOMail>(); for (int i = 1; i <= folder.Items.Count; i++) { folderItemList.Add(folder.Items[i]); } return(folderItemList); }
private string GetFullFolderRoute(RDOFolder folder) { string route = folder.Name; while (!string.IsNullOrWhiteSpace(folder.Parent.Name)) { folder = folder.Parent; route = $"{folder.Name} \\ {route} "; } return(route); }
private SortedList <string, Rfc822Message> getOutlookMessages() { System.Collections.Generic.SortedList <string, Rfc822Message> messages = new System.Collections.Generic.SortedList <string, Rfc822Message>(); //Dim tempApp As Outlook.Application //Dim tempInbox As Outlook.MAPIFolder //Dim InboxItems As Outlook.Items //Dim tempMail As Object = Nothing //Dim objattachments, objAttach RDOSession session = null; //object inbox = null; try { //tempApp = New Outlook.Application session = (RDOSession)Interaction.CreateObject("Redemption.RDOSession"); session.Logon(); } catch (System.Exception ex) { GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, "Unable to create Outlook object: " + ex.Message, false); return(null); } //tempInbox = tempApp.GetNamespace("Mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) RDOFolder inbox = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox); //InboxItems = tempInbox.Items //Dim msg As Outlook.MailItem foreach (MailItem msg in inbox.Items) { //For Each msg In InboxItems if (!string.IsNullOrEmpty(UtilFunctions.findIssueTag((Rfc822Message)msg).Trim())) { if (!UtilFunctions.searchUID(msg.EntryID)) { // No. Add to list messages.Add(msg.EntryID, (Rfc822Message)msg); } } if (!runFlag | !isEnabled) { break; // TODO: might not be correct. Was : Exit For } } session.Logoff(); string cnt = messages.Count.ToString(); cnt += " Outlook messages were found"; GlobalShared.Log.Log((int)LogClass.logType.Info, cnt, false); return(messages); }
private RDOFolder GetRDOFolder(TreeNode nd) { if (nd.Tag == "Store") { return(mySession.Stores.GetStoreFromID(nd.Name, missing).IPMRootFolder); } else { TreeNode top = GetTopNode(nd); RDOFolder fld = mySession.Stores.GetStoreFromID(top.Name, missing).GetFolderFromID(nd.Name, missing); return(fld); } }
private RDOFolder GetFolder(string folderName, RDOFolder parent = null) { //when the parent is null, we assume its about an folder in the root folder RDOFolder folder = null; if (parent == null) { if (Regex.IsMatch(folderName, Constants.POSSIBLE_INBOX_FILENAME_REGEX, RegexOptions.IgnoreCase)) { folder = GetDefaultFolder(rdoDefaultFolders.olFolderInbox, folderName); } else if (Regex.IsMatch(folderName, Constants.POSSIBLE_OUTBOX_FILENAME_REGEX, RegexOptions.IgnoreCase)) { folder = GetDefaultFolder(rdoDefaultFolders.olFolderOutbox, folderName); } else if (Regex.IsMatch(folderName, Constants.POSSIBLE_SEND_FILENAME_REGEX, RegexOptions.IgnoreCase)) { folder = GetDefaultFolder(rdoDefaultFolders.olFolderSentMail, folderName); } else if (Regex.IsMatch(folderName, Constants.POSSIBLE_DELETED_FILENAME_REGEX, RegexOptions.IgnoreCase)) { folder = GetDefaultFolder(rdoDefaultFolders.olFolderDeletedItems, folderName); } else if (Regex.IsMatch(folderName, Constants.POSSIBLE_JUNK_FILENAME_REGEX, RegexOptions.IgnoreCase)) { folder = GetDefaultFolder(rdoDefaultFolders.olFolderJunk, folderName); } } //an nested folder or an non default folder in the root if (folder == null) { RDOFolder folderToSearchIn = parent ?? session.Stores.DefaultStore.IPMRootFolder; //searches the non default folders for that name foreach (RDOFolder currentFolder in folderToSearchIn.Folders) { if (currentFolder.Name.Equals(folderName, StringComparison.OrdinalIgnoreCase)) { folder = currentFolder; break; } } //if the folder not exists, creates it if (folder == null) { folder = folderToSearchIn.Folders.Add(folderName); folder.Save(); } } return(folder); }
public void LoadFolders(TreeNode ndParent, RDOFolder parent) { ndParent.Nodes.Clear(); foreach (RDOFolder folder in parent.Folders) { if (folder.FolderKind == rdoFolderKind.fkGeneric && folder.DefaultItemType == (int)rdoItemType.olMailItem) { TreeNode nd = ndParent.Nodes.Add(folder.EntryID, folder.Name); nd.ImageIndex = 7; nd.SelectedImageIndex = 5; LoadFolders(nd, folder); } } }
public static DateTime GetNewestDateTimeInFolder(string folderID, RDOSession session) { DateTime dt = DateTime.MinValue; RDOFolder folder = session.GetFolderFromID(folderID); foreach (RDOMail item in folder.Items) { if (item.ReceivedTime > dt) { dt = item.ReceivedTime; } } return(dt); }
private void AddMailsToFolder(FolderMailItem folderMailItem, RDOFolder parent = null) { RDOFolder folder = GetFolder(folderMailItem.Name, parent); AddFilesToFolder(folderMailItem.Files, folder); if (folderMailItem.Folders != null && folderMailItem.Folders.Any()) { foreach (FolderMailItem nestedFolderMailItem in folderMailItem.Folders) { AddMailsToFolder(nestedFolderMailItem, folder); } } }
private void AddFilesToFolder(List <MailItem> files, RDOFolder folder) { if (files != null && files.Any()) { foreach (MailItem mailItem in files) { RDOMail mail = folder.Items.Add("IPM.Mail"); mail.Sent = true; mail.Import(mailItem.FullPath, 1024); // folder.Items.Add(mail); mail.Save(); } } }
private string GetFolder(RDOFolder rDOFolder, string foldersStructure, string folderPosition) { if (rDOFolder.Folders.Count > 0) { var localfolderPosition = folderPosition; for (int i = 1; i <= rDOFolder.Folders.Count; i++) { folderPosition = $"{folderPosition}.{i}"; var folderDetails = $"{rDOFolder.Folders[i].Name} (Folder Type: {rDOFolder.Folders[i].FolderKind}, FolderItemsCount: {rDOFolder.Folders[i].Items.Count})"; foldersStructure += $"{folderPosition}. {folderDetails}\n"; foldersStructure = GetFolder(rDOFolder.Folders[i], foldersStructure, folderPosition); folderPosition = localfolderPosition; } } return(foldersStructure); }
private RDOFolder GetDefaultFolder(rdoDefaultFolders type, string name) { RDOFolder folder = null; try { folder = session.GetDefaultFolder(type); } catch (System.Runtime.InteropServices.COMException e) { //if(e.Message.ToUpper().Contains("MAPI_E_NOT_FOUND")) folder = session.Stores.DefaultStore.IPMRootFolder.Folders.Add(name, type); folder.Save(); } return(folder); }
public List <FolderDTO> GetFolder(RDOFolder folder, List <FolderDTO> folderList) { if (folder.Folders.Count != 0) { for (int i = 1; i <= folder.Folders.Count; i++) { GetFolder(folder.Folders[i], folderList); } } var newFolderDto = new FolderDTO() { Name = folder.Name, Route = GetFullFolderRoute(folder), FolderItems = GetFolderItems(folder) }; folderList.Add(newFolderDto); return(folderList); }
public static void ExtractPstFolder(RDOFolder folder, string folderPath) { if (folder == null) { throw new ArgumentNullException("folder"); } if (folderPath == null) { throw new ArgumentNullException("folderPath"); } if (folder.FolderKind == rdoFolderKind.fkSearch) { return; } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } foreach (RDOFolder child in folder.Folders) { ExtractPstFolder(child, Path.Combine(folderPath, ToFileName(child.Name))); } foreach (var item in folder.Items) { RDOMail mail = item as RDOMail; if (mail == null) { continue; } mail.SaveAs(Path.Combine(folderPath, ToFileName(mail.Subject)) + ".eml", rdoSaveAsType.olRFC822); } }
private RDOFolder FindFolder(RDOFolder folder, IReadOnlyList <string> folders, int index) { if (index >= folders.Count) { return(folder); } var name = folders[index]; foreach (RDOFolder child in folder.Folders) { if (string.Equals(child.Name, name, StringComparison.OrdinalIgnoreCase)) { return(FindFolder(child, folders, index + 1)); } } var f = folder.Folders.Add(name); f.Save(); return(FindFolder(f, folders, index + 1)); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { SelectedFolder = GetRDOFolder(e.Node); }
public OutlookContactsProvider(IGUICallbacks host, SyncEngine syncEngine) { owner = host; outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook.NameSpace ns = outlookApp .GetNamespace("MAPI"); nsObject = ns.MAPIOBJECT; if (!IsRedemptionInstalled()) { Process reg = new Process(); reg.StartInfo.FileName = "regsvr32.exe"; reg.StartInfo.Arguments = "/s Redemption.dll"; reg.StartInfo.UseShellExecute = false; reg.StartInfo.CreateNoWindow = true; reg.StartInfo.RedirectStandardOutput = true; reg.Start(); reg.WaitForExit(); reg.Close(); } else { } rdoSession = new RDOSessionClass(); try { rdoSession.MAPIOBJECT = nsObject; } catch { Microsoft.Office.Interop.Outlook.MAPIFolder mf = outlookApp.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); string pstPath = GetStorePath(mf.StoreID); //string pstPath = @"C:\Users\maxim\AppData\Local\Microsoft\Outlook\Outlook.pst"; rdoSession.LogonPstStore(pstPath, 1, "", "", 0); } rdoAddressBook = rdoSession.AddressBook; rdoAddressList = rdoAddressBook.GAL; rdoFld = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderContacts); rdoItems = rdoFld.Items; this.syncEngine = syncEngine; }
public void UpdateTask() { SyncSem.WaitOne(); if (syncEngine.SyncCanceled) { UpdateSem.Release(); return; } syncEngine.CurrentTotal += MapAdded.Count + MapUpdated.Count; rdoSession = new RDOSessionClass(); rdoSession.MAPIOBJECT = nsObject; rdoAddressBook = rdoSession.AddressBook; rdoAddressList = rdoAddressBook.GAL; rdoFld = rdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderContacts); rdoItems = rdoFld.Items; foreach (Contact c in MapUpdated.Values) { if (owner != null) { Dispatcher.Invoke(new SyncProgressEventHandler(owner.Progress), this, "Updating " + "(" + syncEngine.CurrentItemNum + "/" + syncEngine.CurrentTotal + ")", syncEngine.CurrentItemNum, syncEngine.CurrentTotal); syncEngine.CurrentItemNum++; } RDOContactItem ctc = rdoItems[indexByFullname[c.FullName]] as RDOContactItem; FillProviderCreatedItem(c, ctc); ctc.Save(); } foreach (Contact contact in MapAdded.Values) { if (owner != null) { Dispatcher.Invoke(new SyncProgressEventHandler(owner.Progress), this, "Updating " + "(" + syncEngine.CurrentItemNum + "/" + syncEngine.CurrentTotal + ")", syncEngine.CurrentItemNum, syncEngine.CurrentTotal); syncEngine.CurrentItemNum++; } if (contact.FullName != "") { RDOContactItem ctc = rdoItems.Add("IPM.Contact") as RDOContactItem; if (ctc != null) FillProviderCreatedItem(contact, ctc); ctc.Save(); } else { } } UpdateSem.Release(); }
public static int AdjustTimeStamp(string mailbox) { string ProjectDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); RedemptionLoader.DllLocation64Bit = ProjectDir + @"\redemption64.dll"; RedemptionLoader.DllLocation32Bit = ProjectDir + @"\redemption.dll"; if (!File.Exists(RedemptionLoader.DllLocation32Bit) || !File.Exists(RedemptionLoader.DllLocation64Bit)) { Console.WriteLine("ERROR: redemption64.dll (64-bit) or redemption.dll (32-bit) is missing from EXE directory"); Console.WriteLine($"redemption64.dll should be here: {RedemptionLoader.DllLocation64Bit}"); Console.WriteLine($"redemption.dll should be here: {RedemptionLoader.DllLocation32Bit}"); Console.WriteLine("\nTerminating with exit code -1"); return(-1); } RDOSession session = RedemptionLoader.new_RDOSession(); session.Logon(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); var stores = session.Stores; // store == "mailbox" within an Outlook profile foreach (RDOStore rdoStore in stores) { Console.WriteLine($"\nChecking Mailbox {rdoStore.Name}"); if ((rdoStore.Name.ToLower().Contains(mailbox.ToLower()))) { Console.WriteLine($" Processing Mailbox {rdoStore.Name}"); TimeSpan delta = TimeSpan.Zero; // the amount of time to shift RDOFolder IPMRoot = rdoStore.IPMRootFolder; foreach (RDOFolder folder in IPMRoot.Folders) // find newest e-mail in Inbox { Debug.WriteLine($" Top Level Folder {folder.Name}"); if (folder.Name == "Inbox") { Debug.WriteLine($" Found {folder.Name} - EntryID {folder.EntryID}"); DateTime dtNewest = GetNewestDateTimeInFolder(folder.EntryID, session); delta = DateTime.Now - dtNewest; Console.WriteLine($" Newest item in {folder.Name} is {dtNewest}, delta == {delta}"); } } ConsoleColor OrigConsoleColor = Console.ForegroundColor; char keypress; do { if (delta > new TimeSpan(100, 0, 0, 0)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\aARE YOU SURE! THIS IS OVER 100 DAYS!"); Console.ForegroundColor = OrigConsoleColor; } Console.Write("\n Adjust Inbox and Sent Items "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(Options.BackInTime ? "BACKWARD " : "FORWARD "); Console.Write($"{delta.Days}d {delta.Hours}h {delta.Minutes}m"); Console.ForegroundColor = OrigConsoleColor; Console.Write("? [Y]es/[N]o/[C]ustom] :"); keypress = char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); switch (keypress) { case 'y': Console.WriteLine($" Processing Mailbox {rdoStore.Name}..."); foreach (RDOFolder folder in IPMRoot.Folders) // adjust dates on all items in Inbox and Sent Items (and their subfolders) { Debug.WriteLine($" Processing Folder {folder.Name}"); if (folder.Name == "Inbox" || folder.Name == "Sent Items") { Debug.WriteLine($" Found {folder.Name} - EntryID {folder.EntryID}"); PerformMailFix(folder.EntryID, session, delta); } } break; case 'c': Console.WriteLine(" 6.12:32 6 days 12 hours 32 minutes 00 seconds"); Console.WriteLine(" 6:32 8 hours 32 minutes"); Console.WriteLine(" -6.12:32 GO BACKWARD 6 days 12 hours 32 minutes 00 seconds"); Console.Write(" Enter Custom Offset [-][d].[hh]:[mm] --> "); if (TimeSpan.TryParse(Console.ReadLine(), out delta)) { if (delta < TimeSpan.Zero) // This is a cheap way to get Abs(TimeSpan) without having to access each field of the struct. { Options.BackInTime = true; delta = delta - delta - delta; } else { Options.BackInTime = false; } } break; default: break; } } while (keypress == 'c'); } } session.Logoff(); return(count); }
static void Main(string[] args) { // <3 visual studio string origpath = Path.GetFullPath(@"..\..\..\backup.pst"); // Just full of spam string targetpath = Path.GetFullPath(@"..\..\..\..\snapshot.pst"); // This will be the challenge // Copy over the original pst File.Copy(origpath, targetpath, true); // Have to use Redemption for this, since outlook is "secure" // Open the PST RDOSession session = new RDOSession(); session.LogonPstStore(targetpath); // Load the target inbox RDOFolder inboxFolder = session.GetFolderFromPath("PRIVATE INBOX"); RDOItems inbox = inboxFolder.Items; inbox.Sort("ReceivedTime", false); // Pre-sort them in ascending order Console.WriteLine(inbox.Count); // Encode the flag in DateTimes, hiding it in the year (2000 + c) // e.g. 3/9/2102 12:45:54 AM ==> 102 => 'f' var flag = "flag{w1k1L3ak5_g0T_n0tH1ng_0n_m3}".Select(c => EncodeChar(c)).ToList(); // fun var aliases = Cycle(aliasStrings).GetEnumerator(); var subjects = Cycle(subjectStrings).GetEnumerator(); // Approximately space out the emails int range = inbox.Count / flag.Count; for (int i = 0; i < flag.Count; i++) { // Copy the delivery time from a random email in this range DateTime recvTime = inbox[rand.Next(i * range, (i + 1) * range)].ReceivedTime; DateTime flagtime = flag[i]; Console.WriteLine($"{flagtime} => {recvTime}"); // Create a fake email with the two times and other fun stuff RDOMail flagmail = inbox.Add("IPM.Note"); flagmail.Importance = 1; flagmail.ReceivedTime = recvTime; flagmail.SentOn = flagtime; flagmail.Subject = subjects.Next(); flagmail.To = "*****@*****.**"; flagmail.Sender = session.GetAddressEntryFromID(session.AddressBook.CreateOneOffEntryID(aliases.Next(), "SMTP", "*****@*****.**", false, false)); flagmail.Save(); } // Sort the emails by delivery time, scattering the spoofed ones (in order) across the dump inbox = inboxFolder.Items; Console.WriteLine(inbox.Count); inbox.Sort("ReceivedTime", false); // Guess we're doing it this way -__- Console.WriteLine("Flag is in place, moving to inbox..."); RDOFolder targetInbox = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox); foreach (RDOMail email in inbox) { email.CopyTo(targetInbox); } targetInbox.Save(); Console.WriteLine("Done!"); }
public OutlookPstManager(Redemption.RDOSession session, Redemption.RDOFolder baseFolder) { this._session = session; this._baseFolder = baseFolder; }