diff --git a/src/Orchard.Web/Modules/Orchard.Email/Models/EmailMessage.cs b/src/Orchard.Web/Modules/Orchard.Email/Models/EmailMessage.cs index 3edcd8731..8c588ce91 100644 --- a/src/Orchard.Web/Modules/Orchard.Email/Models/EmailMessage.cs +++ b/src/Orchard.Web/Modules/Orchard.Email/Models/EmailMessage.cs @@ -1,4 +1,6 @@ -namespace Orchard.Email.Models { +using System.Collections.Generic; + +namespace Orchard.Email.Models { public class EmailMessage { public string Subject { get; set; } public string Body { get; set; } @@ -7,5 +9,9 @@ public string From { get; set; } public string Bcc { get; set; } public string Cc { get; set; } + /// + /// IEnumerable of strings representing attachments paths + /// + public IEnumerable Attachments { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Email/Services/SmtpMessageChannel.cs b/src/Orchard.Web/Modules/Orchard.Email/Services/SmtpMessageChannel.cs index 0ab833e6b..02e26892a 100644 --- a/src/Orchard.Web/Modules/Orchard.Email/Services/SmtpMessageChannel.cs +++ b/src/Orchard.Web/Modules/Orchard.Email/Services/SmtpMessageChannel.cs @@ -9,6 +9,8 @@ using Orchard.ContentManagement; using Orchard.DisplayManagement; using Orchard.Logging; using Orchard.Email.Models; +using System.Linq; +using System.IO; namespace Orchard.Email.Services { public class SmtpMessageChannel : Component, ISmtpChannel, IDisposable { @@ -51,7 +53,8 @@ namespace Orchard.Email.Services { ReplyTo = Read(parameters, "ReplyTo"), From = Read(parameters, "From"), Bcc = Read(parameters, "Bcc"), - Cc = Read(parameters, "CC") + Cc = Read(parameters, "CC"), + Attachments = (IEnumerable)(parameters.ContainsKey("Attachments") ? parameters["Attachments"] : new List()) }; if (emailMessage.Recipients.Length == 0) { @@ -105,8 +108,7 @@ namespace Orchard.Email.Services { if (!String.IsNullOrWhiteSpace(emailMessage.From)) { mailMessage.From = new MailAddress(emailMessage.From); - } - else { + } else { // Take 'From' address from site settings or web.config. mailMessage.From = !String.IsNullOrWhiteSpace(_smtpSettings.Address) ? new MailAddress(_smtpSettings.Address) @@ -119,9 +121,15 @@ namespace Orchard.Email.Services { } } + foreach (var attachmentPath in emailMessage.Attachments) { + if (File.Exists(attachmentPath)) { + mailMessage.Attachments.Add(new Attachment(attachmentPath)); + } else { + throw new FileNotFoundException(T("One or more attachments not found.").Text); + } + } _smtpClientField.Value.Send(mailMessage); - } - catch (Exception e) { + } catch (Exception e) { Logger.Error(e, "Could not send email"); } } @@ -129,7 +137,7 @@ namespace Orchard.Email.Services { private SmtpClient CreateSmtpClient() { // If no properties are set in the dashboard, use the web.config value. if (String.IsNullOrWhiteSpace(_smtpSettings.Host)) { - return new SmtpClient(); + return new SmtpClient(); } var smtpClient = new SmtpClient { @@ -155,7 +163,7 @@ namespace Orchard.Email.Services { } private IEnumerable ParseRecipients(string recipients) { - return recipients.Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries); + return recipients.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs index 4e0bc04a3..853384578 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Filters/OutputCacheFilter.cs @@ -41,6 +41,7 @@ namespace Orchard.OutputCache.Filters { private readonly ICacheService _cacheService; private readonly ISignals _signals; private readonly ShellSettings _shellSettings; + private readonly ICachingEventHandler _cachingEvents; private bool _isDisposed = false; public ILogger Logger { get; set; } @@ -55,7 +56,8 @@ namespace Orchard.OutputCache.Filters { IClock clock, ICacheService cacheService, ISignals signals, - ShellSettings shellSettings) { + ShellSettings shellSettings, + ICachingEventHandler cachingEvents) { _cacheManager = cacheManager; _cacheStorageProvider = cacheStorageProvider; @@ -67,6 +69,7 @@ namespace Orchard.OutputCache.Filters { _cacheService = cacheService; _signals = signals; _shellSettings = shellSettings; + _cachingEvents = cachingEvents; Logger = NullLogger.Instance; } @@ -616,6 +619,9 @@ namespace Orchard.OutputCache.Filters { } } + //make CacheKey morphable by external modules + _cachingEvents.KeyGenerated(keyBuilder); + return keyBuilder.ToString(); } diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/ICachingEventHandler.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/ICachingEventHandler.cs new file mode 100644 index 000000000..a2dbc640e --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/ICachingEventHandler.cs @@ -0,0 +1,12 @@ +using Orchard.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; + +namespace Orchard.OutputCache { + public interface ICachingEventHandler : IEventHandler { + void KeyGenerated(StringBuilder key); + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj b/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj index a3a7fa74c..9a4520288 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj @@ -103,6 +103,7 @@ +