public void TestOutlookSendLinkMapi_ReplaceAttachments() { SendLinkInfo sendLink = new SendLinkInfo(); sendLink.DisplayName = "Attachments.html"; sendLink.Link = "A Link"; sendLink.FilePath = Path.Combine(TestRoot, "Attachments.html"); OutlookEmailWrapper email = new OutlookEmailWrapper(_outlookSession, Path.Combine(TestRoot, "Test RTF 2010.msg")); OutlookSendLinkMAPI mapi = new OutlookSendLinkMAPI(); int count = email.MailItem.Attachments.Count; int[] posArray = new int[count]; string[] recordKeyArray = new string[count]; using (var wsMailItem = new WsMailItem(email.MailItem)) { for (int i = 1; i <= count; i++) { posArray[i - 1] = wsMailItem.Attachments[i].Position; recordKeyArray[i - 1] = mapi.GetRecordKey(wsMailItem, i); } for (int i = 1; i <= count; i++) { IWSMailAttachmentTransform mat = new OutlookIImplFactory().CreateWSMailAttachmentTransform(); mat.SendLinkReplaceRtfAttachments(wsMailItem, sendLink.FilePath, sendLink.DisplayName); } Redemption.SafeMailItem safeMailItem = RedemptionLoader.new_SafeMailItem(); using (new ComRelease(safeMailItem)) { safeMailItem.Item = wsMailItem.UnSafeMailItem;// email.MailItem; int[] posArray2 = new int[safeMailItem.Attachments.Count]; string[] names = new string[count]; for (int i = 1; i <= safeMailItem.Attachments.Count; i++) { posArray2[i - 1] = safeMailItem.Attachments[i].Position; names[i - 1] = safeMailItem.Attachments[i].DisplayName; } for (int i = 0; i < safeMailItem.Attachments.Count; i++) { Assert.AreEqual(posArray[i], posArray2[i]); Assert.AreEqual(names[i], "Attachments.html"); } } } }
private List<SendLinkInfo> GetFilesToUpload(IEnumerable<Attachment> processedAttachments, string id) { List<SendLinkInfo> files = new List<SendLinkInfo>(); LocalCopyOfFileManager lcofm = new LocalCopyOfFileManager(false, GetWorkingDirectory(id)); foreach (Attachment serviceAttachment in processedAttachments) { string displayName = serviceAttachment.Name; FileInfo tempFile = new FileInfo(lcofm.GetLocalCopyOfFileTarget(displayName)); using (FileStream fs = new FileStream(tempFile.FullName, FileMode.Create)) { fs.Write(serviceAttachment.Content, 0, serviceAttachment.Content.Length); fs.Close(); } SendLinkInfo sendLinkInfo = new SendLinkInfo { ContentId = serviceAttachment.Id, DisplayName = displayName, FilePath = tempFile.FullName }; files.Add(sendLinkInfo); } return files; }
public void TestOutlookRtf2007() { _mailItem.ApplicationVersion = "12.0.0.0"; string path = Path.Combine(TestRoot, @"Outlook2007.rtf"); Assert.IsTrue(File.Exists(path), @"Test file should really exist"); string rtf = File.ReadAllText(path); List<SendLinkInfo> links = new List<SendLinkInfo>(); const string desc1 = "This is the first file to be inserted"; const string link1 = @"http://www.workshare.com/files/file00000003.doc"; SendLinkInfo sendlinkinfo = new SendLinkInfo { DisplayName = desc1, Link = link1 }; links.Add(sendlinkinfo); SendLinkInfo sendlinkinfo2 = new SendLinkInfo { DisplayName = "This is now the second file", Link = @"http://www.workshare.com/files/file00000004.doc" }; links.Add(sendlinkinfo2); rtf = OutlookFormattedTextProcessor.NewFormattedBodyText(rtf, links, _mailItem); Assert.IsNotNull(rtf); }
internal SendLinkInfo CreateSendLinkContentFile(List<SendLinkInfo> links, string id) { try { string redirectLink; if (links != null && links.Count > 0) { redirectLink = links[0].Link; } else { // This code path should never be executed, but as a fall-back we get the // root server address as the redirection link. (something like: https://box.workshare.com) var uri = new Uri(Interop.Options.OptionApi.GetString("SendLinkServiceUrl")); redirectLink = string.Format("{0}://{1}", uri.Scheme, uri.Host); } string htmlContent = Resources.SendLinkBaseHtml; htmlContent = htmlContent.Replace("#URL_REPLACEMENT_TAG#", redirectLink); string filename = string.Format("{0}.xhtml", Interop.Options.OptionApi.GetString("SendLinkContentFileName")); string proposedFileName = GetProposedFileName(filename, string.Empty, id); File.WriteAllText(proposedFileName, htmlContent); SendLinkInfo sendLinkInfo = new SendLinkInfo { FilePath = proposedFileName, DisplayName = filename }; return sendLinkInfo; } catch (Exception ex) { Interop.Logging.Logger.LogError(ex); throw; } }
public void TestOutlookRtf2003() { _mailItem.ApplicationVersion = "11.0.0.0"; string path = Path.Combine(TestRoot, @"Outlook2003.rtf"); Assert.IsTrue(File.Exists(path), @"Test file should really exist"); string rtf = File.ReadAllText(path); List<SendLinkInfo> links = new List<SendLinkInfo>(); const string desc1 = "This is the firstest file to be inserted"; const string link1 = @"http://www.workshare.com/files/file00000005.doc"; SendLinkInfo sendlinkinfo = new SendLinkInfo { DisplayName = desc1, Link = link1 }; links.Add(sendlinkinfo); SendLinkInfo sendlinkinfo2 = new SendLinkInfo { DisplayName = "This here is now the second file", Link = @"http://www.workshare.com/files/file00000006.doc" }; links.Add(sendlinkinfo2); rtf = OutlookFormattedTextProcessor.NewFormattedBodyText(rtf, links, _mailItem); // search for field int indexField = rtf.IndexOf(@"{\field"); Assert.IsTrue(indexField > 0, "Could not find any field!"); int indexFieldEnd = FindMatchingBrace(rtf, indexField + 1); // hyperlink is in, plus description, within acceptable distance Assert.IsTrue(rtf.IndexOf(@"HYPERLINK", indexField, indexFieldEnd - indexField) > 0, "failed to find the HYPERLINK"); int indexLink1 = rtf.IndexOf(link1, indexField, indexFieldEnd - indexField); int indexDesc1 = rtf.IndexOf(desc1, indexField, indexFieldEnd - indexField); Assert.IsTrue(indexDesc1 - indexLink1 < 80, "description too far from hyperlink to be credible"); // location in the rtf is good (after pnseclvl9, before "Here is some more text") int indexPnseclvl9 = rtf.IndexOf("pnseclvl9"); int indexBodyText = rtf.IndexOf("Some text"); Assert.IsTrue(indexPnseclvl9 < indexField, "field should be after pnseclvl9"); Assert.IsTrue(indexFieldEnd < indexBodyText, "field should be before body text"); // File.WriteAllText(path + "_out.rtf", rtf); }
public void TestOutlookText2003() { _mailItem.ApplicationVersion = "11.0.0.0"; string path = Path.Combine(TestRoot, @"Outlook2003.txt"); Assert.IsTrue(File.Exists(path), @"Test file should really exist"); string text = File.ReadAllText(path); List<SendLinkInfo> links = new List<SendLinkInfo>(); const string desc1 = "This is deemed to be the first file"; const string link1 = @"http://www.workshare.com/files/file00000001.doc"; SendLinkInfo sendlinkinfo = new SendLinkInfo { DisplayName = desc1, Link = link1 }; links.Add(sendlinkinfo); SendLinkInfo sendlinkinfo2 = new SendLinkInfo { DisplayName = "This is deemed to be the second file", Link = @"http://www.workshare.com/files/file00000002.doc" }; links.Add(sendlinkinfo2); string text2 = OutlookFormattedTextProcessor.NewFormattedBodyText(text, links, _mailItem); Assert.IsNotEmpty(text2); Assert.AreNotEqual(text, text2); /* This is deemed to be the first file http://www.workshare.com/files/file00000001.doc This is deemed to be the second file http://www.workshare.com/files/file00000002.doc */ int ahref = text2.IndexOf("This is deemed to be the first file", StringComparison.Ordinal); Assert.IsTrue(ahref > 0, "Could not find file 1 text!"); ahref = text2.IndexOf("This is deemed to be the second file", StringComparison.Ordinal); Assert.IsTrue(ahref > 0, "Could not find file 2 text!"); ahref = text2.IndexOf("http://www.workshare.com/files/file00000001.doc", StringComparison.Ordinal); Assert.IsTrue(ahref > 0, "Could not find link ref!"); }
public void TestOutlookText2010() { _mailItem.ApplicationVersion = "14.0.0.0"; string path = Path.Combine(TestRoot, @"Outlook2010.txt"); Assert.IsTrue(File.Exists(path), @"Test file should really exist"); string text = File.ReadAllText(path); List<SendLinkInfo> links = new List<SendLinkInfo>(); const string desc1 = "This is deemed to be the first file"; const string link1 = @"http://www.workshare.com/files/file00000001.doc"; SendLinkInfo sendlinkinfo = new SendLinkInfo { DisplayName = desc1, Link = link1 }; links.Add(sendlinkinfo); SendLinkInfo sendlinkinfo2 = new SendLinkInfo { DisplayName = "This is deemed to be the second file", Link = @"http://www.workshare.com/files/file00000002.doc" }; links.Add(sendlinkinfo2); string text2 = OutlookFormattedTextProcessor.NewFormattedBodyText(text, links, _mailItem); Assert.IsNull(text2); }
public void TestOutlookHtml2003() { _mailItem.ApplicationVersion = "11.0.0.0"; string path = Path.Combine(TestRoot, @"Outlook2003.htm"); Assert.IsTrue(File.Exists(path), @"Test file should really exist"); string html = File.ReadAllText(path); List<SendLinkInfo> links = new List<SendLinkInfo>(); const string desc1 = "This is deemed to be the first file"; const string link1 = @"http://www.workshare.com/files/file00000001.doc"; SendLinkInfo sendlinkinfo = new SendLinkInfo { DisplayName = desc1, Link = link1 }; links.Add(sendlinkinfo); SendLinkInfo sendlinkinfo2 = new SendLinkInfo { DisplayName = "This is deemed to be the second file", Link = @"http://www.workshare.com/files/file00000002.doc" }; links.Add(sendlinkinfo2); string html2 = OutlookFormattedTextProcessor.NewFormattedBodyText(html, links, _mailItem); Assert.IsNotEmpty(html2); Assert.AreNotEqual(html, html2); int ahref = html2.IndexOf("<a href='http://www.workshare.com/files/file00000001.doc'>View these files using Workshare</a>", StringComparison.Ordinal); Assert.IsTrue(ahref > 0, "Could not find \"a href\"!"); }
protected internal override bool ReplaceAttachments(MailItem mailItem, string recordKey, SendLinkInfo filenames) { try { bool bFound = false; int i = 0; for (i = 1; i <= mailItem.Attachments.Count; i++) { string key = GetRecordKey(mailItem, i); if (key == recordKey) { bFound = true; break; } } if (bFound) { int position = mailItem.Attachments[i].Position; mailItem.Attachments.Remove(i); AddAttachment(mailItem, filenames, position); } return true; } catch (Exception ex) { Interop.Logging.Logger.LogError(ex); throw; } }
private bool AddAttachment(MailItem mailItem, SendLinkInfo filenames, int renderingPosition = 1) { try { // MSDN - Position, This parameter applies only to e-mail messages using Microsoft Outlook Rich Text format: // it is the position where the attachment should be placed within the body text of the message. // A value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. // A value 'n' greater than the number of characters in the body of the e-mail item specifies that the attachment should be placed at the end. // A value of 0 makes the attachment hidden. // FogBugz 13768 - Outlook 2013 crashes when mail body is RTF and SendLink action executes. // Specifying the position of the attachment in RTF body will throw Access Violation in Outlook 2013. // Add the Attachment then set Position. Attachment attachment = mailItem.Attachments.Add(filenames.FilePath, OlAttachmentType.olByValue, System.Reflection.Missing.Value, filenames.DisplayName); if (attachment != null) { attachment.Position = renderingPosition; return true; } } catch (Exception ex) { Interop.Logging.Logger.LogError(ex); throw; } return false; }
private SendLinkInfo CreateSendLinkContentFile(List<SendLinkInfo> links) { try { string redirectLink; if (links != null && links.Count > 0) { redirectLink = links[0].Link; } else { var uri = new Uri(OptionApi.GetString("SendLinkServiceUrl")); redirectLink = string.Format("{0}://{1}", uri.Scheme, uri.Host); } string htmlContent = Resources.SendLinkBaseHtml; htmlContent = htmlContent.Replace("#URL_REPLACEMENT_TAG#", redirectLink); //17216 [WS 8.0]No html file is generated when document processed which is attached through File->share->Email->send as Attachment. ZenQ // You can't attach .htm or .html files - any other extenion is ok. string filename = string.Format("{0}.xhtml", OptionApi.GetString("SendLinkContentFileName")); string proposedFileName = GetProposedFileName(filename, string.Empty, true); File.WriteAllText(proposedFileName, htmlContent); var sendLinkInfo = new SendLinkInfo {FilePath = proposedFileName, DisplayName = filename}; return sendLinkInfo; } catch (Exception ex) { Logger.LogError(ex); throw; } }
private List<SendLinkInfo> GetAttachments(IEnumerable<PolicyContent.Attachment> listAttachments, string id) { List<SendLinkInfo> files = new List<SendLinkInfo>(); foreach (PolicyContent.Attachment attachment in listAttachments) { string displayName = attachment.Name; string ext = Path.GetExtension(attachment.FileName); string fileName = Path.GetFileName(attachment.FileName); int dotCountInFileName = fileName.Count(f => f == '.'); if (string.IsNullOrEmpty(ext) || (fileName.EndsWith(".msg") && dotCountInFileName > 1)) { // TFS 9217 // In case of Outlook (.msg) files (an exported email-message or a distribution list) Outlook doesnt show file extension in // attachment display name. Hence the extension is absent from attachment.Name property as well. If there is a dot // in file's name, this causes issues, as the part of the name after dot gets considered as extension, which is wrong. // Thats why we check for .msg file and dotCount in it. foreach (CustomProperty cp in attachment.Properties) { if (cp.Name == "LocalFileName") { ext = Path.GetExtension(cp.Value); break; } } displayName = fileName; } string proposedFileName = GetProposedFileName(displayName, ext, id); File.Copy(attachment.FileName, proposedFileName, true); SendLinkInfo sendLinkInfo = new SendLinkInfo { FilePath = proposedFileName, DisplayName = displayName }; files.Add(sendLinkInfo); } return files; }
protected internal virtual bool ReplaceAttachments(MailItem mailItem, string recordKey, SendLinkInfo filenames) { throw new NotImplementedException(); }
private bool AddAttachment(MailItem mailItem, SendLinkInfo filenames, int renderingPosition = 1) { try { using (IWSMail mail = Oif.CreateWSMail(mailItem)) { // MSDN - Position, This parameter applies only to e-mail messages using Microsoft Outlook Rich Text format: // it is the position where the attachment should be placed within the body text of the message. // A value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. // A value 'n' greater than the number of characters in the body of the e-mail item specifies that the attachment should be placed at the end. // A value of 0 makes the attachment hidden. IWSAttachment attachment = mail.Attachments.Add(filenames.FilePath, OlAttachmentType.olByValue, renderingPosition, filenames.DisplayName); if (attachment != null) { return true; } } } catch (Exception ex) { Interop.Logging.Logger.LogError(ex); throw; } return false; }
public void TestOutlookSendLinkOOM_ReplaceAttachments() { SendLinkInfo sendLink = new SendLinkInfo(); sendLink.DisplayName = "Attachments.html"; sendLink.Link = "A Link"; sendLink.FilePath = Path.Combine(TestRoot, "Attachments.html"); OutlookEmailWrapper email = new OutlookEmailWrapper(_outlookSession, Path.Combine(TestRoot, "Test Rtf 2010.msg")); OutlookSendLinkOOM oom = new OutlookSendLinkOOM(); int count = email.MailItem.Attachments.Count; int[] posArray = new int[count]; string[] recordKeyArray = new string[count]; using (var wsMailItem = new WsMailItem(email.MailItem)) { for (int i = 1; i <= count; i++) { posArray[i - 1] = wsMailItem.Attachments[i].Position; recordKeyArray[i - 1] = oom.GetRecordKey(wsMailItem, i); } for (int i = 1; i <= count; i++) { oom.ReplaceAttachments(wsMailItem, recordKeyArray[i - 1], sendLink); } int[] posArray2 = new int[wsMailItem.Attachments.Count]; string[] names = new string[count]; for (int i = 1; i <= wsMailItem.Attachments.Count; i++) { posArray2[i - 1] = wsMailItem.Attachments[i].Position; names[i - 1] = wsMailItem.Attachments[i].DisplayName; } for (int i = 0; i < wsMailItem.Attachments.Count; i++) { Assert.AreEqual(posArray[i], posArray2[i]); Assert.AreEqual(names[i], "Attachments.html"); } } }
public static void UploadFiles(this SkyDoxUploader skyDoxUploader, string fromFolder, string skydoxFolderDescription, PermissionFlags permissionFlags, int howMany = 0, bool useTestDisplayName = false) { // Get all the file names. var rand = new Random(); var filenames = (from f in new DirectoryInfo(fromFolder).EnumerateFiles() where !f.Attributes.HasFlag(FileAttributes.Hidden) && !f.Attributes.HasFlag(FileAttributes.System) orderby rand.Next() select new { Path = f.FullName, Ext = f.Extension } ).ToArray(); if (howMany <= 0) { howMany = filenames.Length; } var infos = new List<SendLinkInfo>(); for (int i = 1; i <= howMany; i++) { var file = filenames[i % filenames.Length]; var sli = new SendLinkInfo { ContentId = i.ToString(CultureInfo.InvariantCulture), DisplayName = useTestDisplayName ? "test file " + i : Path.GetFileNameWithoutExtension(file.Path), FilePath = file.Path }; infos.Add(sli); } // Create a (fairly) unique folder name. string folderName = string.Format("An upload test ({0:dd-MMM-yyyy, HH.mm.ss})", DateTime.Now); DateTime expiry = DateTime.UtcNow.AddMonths(1); string folderLink; bool result = skyDoxUploader.UploadFiles( folderName, skydoxFolderDescription, expiry, false, new[] { "*****@*****.**" }, permissionFlags, infos, false, out folderLink); Assert.IsTrue(result, "Failed to upload files."); }