Skip to content

Commit b563286

Browse files
committed
Messaging: removed wrapping 'Attachment' class. Using System.Net.Mail.Attachment directly instead.
1 parent f32ac7a commit b563286

6 files changed

Lines changed: 16 additions & 221 deletions

File tree

src/Libraries/SmartStore.Core/Email/Attachment.cs

Lines changed: 0 additions & 183 deletions
This file was deleted.

src/Libraries/SmartStore.Core/Email/DefaultEmailSender.cs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5-
using net = System.Net.Mail;
5+
using System.Net.Mail;
66
using System.Net.Mime;
77
using System.Net;
88
using System.IO;
@@ -23,9 +23,9 @@ public DefaultEmailSender()
2323
/// </summary>
2424
/// <param name="original">SmartStore.Email.Message</param>
2525
/// <returns>System.Net.Mail.Message</returns>
26-
protected virtual net.MailMessage BuildMailMessage(EmailMessage original)
26+
protected virtual MailMessage BuildMailMessage(EmailMessage original)
2727
{
28-
net.MailMessage msg = new net.MailMessage();
28+
MailMessage msg = new MailMessage();
2929

3030
if (String.IsNullOrEmpty(original.Subject))
3131
{
@@ -37,15 +37,15 @@ protected virtual net.MailMessage BuildMailMessage(EmailMessage original)
3737

3838
if (original.AltText.HasValue())
3939
{
40-
msg.AlternateViews.Add(net.AlternateView.CreateAlternateViewFromString(original.AltText, new ContentType("text/html")));
41-
msg.AlternateViews.Add(net.AlternateView.CreateAlternateViewFromString(original.Body, new ContentType("text/plain")));
40+
msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(original.AltText, new ContentType("text/html")));
41+
msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(original.Body, new ContentType("text/plain")));
4242
}
4343
else
4444
{
4545
msg.Body = original.Body;
4646
}
4747

48-
msg.DeliveryNotificationOptions = net.DeliveryNotificationOptions.None;
48+
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.None;
4949

5050
msg.From = original.From.ToMailAddress();
5151

@@ -54,30 +54,9 @@ protected virtual net.MailMessage BuildMailMessage(EmailMessage original)
5454
msg.Bcc.AddRange(original.Bcc.Where(x => x.Address.HasValue()).Select(x => x.ToMailAddress()));
5555
msg.ReplyToList.AddRange(original.ReplyTo.Where(x => x.Address.HasValue()).Select(x => x.ToMailAddress()));
5656

57-
foreach (Attachment attachment in original.Attachments)
57+
foreach (var attachment in original.Attachments)
5858
{
59-
byte[] byteData;
60-
61-
if (attachment.ContentTransferEncoding == TransferEncoding.Base64)
62-
{
63-
using (var sr = new StreamReader(attachment.Stream))
64-
{
65-
byteData = Convert.FromBase64String(sr.ReadToEnd());
66-
}
67-
}
68-
else
69-
{
70-
byteData = attachment.Stream.ToByteArray();
71-
}
72-
73-
MemoryStream s = new MemoryStream(byteData);
74-
net.Attachment att = new net.Attachment(s, attachment.Name, attachment.ContentType.MediaType);
75-
76-
att.ContentType.MediaType = attachment.MediaType;
77-
att.TransferEncoding = attachment.ContentTransferEncoding;
78-
att.ContentDisposition.DispositionType = attachment.ContentDisposition.DispositionType;
79-
80-
msg.Attachments.Add(att);
59+
msg.Attachments.Add(attachment);
8160
}
8261

8362
if (original.Headers != null)

src/Libraries/SmartStore.Core/SmartStore.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@
224224
<Compile Include="Domain\Stores\StoreMapping.cs" />
225225
<Compile Include="Domain\Themes\ThemeSettings.cs" />
226226
<Compile Include="Domain\Themes\ThemeVariable.cs" />
227-
<Compile Include="Email\Attachment.cs" />
228227
<Compile Include="Email\DefaultEmailSender.cs" />
229228
<Compile Include="Email\EmailAddress.cs" />
230229
<Compile Include="Email\EmailException.cs" />

src/Libraries/SmartStore.Services/Messages/IQueuedEmailService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public partial interface IQueuedEmailService
5353
/// <param name="pageSize">Page size</param>
5454
/// <param name="sendManually">A value indicating whether to load manually send emails</param>
5555
/// <returns>Email item collection</returns>
56-
IPagedList<QueuedEmail> SearchEmails(string fromEmail,
57-
string toEmail, DateTime? startTime, DateTime? endTime,
58-
bool loadNotSentItemsOnly, int maxSendTries,
56+
IPagedList<QueuedEmail> SearchEmails(
57+
string fromEmail, string toEmail,
58+
DateTime? startTime, DateTime? endTime,
59+
bool loadUnsentItemsOnly, int maxSendTries,
5960
bool loadNewest, int pageIndex, int pageSize,
6061
bool? sendManually = null);
6162

src/Libraries/SmartStore.Services/Messages/QueuedEmailService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ where queuedEmailIds.Contains(qe.Id)
133133
/// <param name="toEmail">To Email</param>
134134
/// <param name="startTime">The start time</param>
135135
/// <param name="endTime">The end time</param>
136-
/// <param name="loadNotSentItemsOnly">A value indicating whether to load only not sent emails</param>
136+
/// <param name="loadUnsentItemsOnly">A value indicating whether to load only not sent emails</param>
137137
/// <param name="maxSendTries">Maximum send tries</param>
138138
/// <param name="loadNewest">A value indicating whether we should sort queued email descending; otherwise, ascending.</param>
139139
/// <param name="pageIndex">Page index</param>
@@ -142,7 +142,7 @@ where queuedEmailIds.Contains(qe.Id)
142142
/// <returns>Email item list</returns>
143143
public virtual IPagedList<QueuedEmail> SearchEmails(string fromEmail,
144144
string toEmail, DateTime? startTime, DateTime? endTime,
145-
bool loadNotSentItemsOnly, int maxSendTries,
145+
bool loadUnsentItemsOnly, int maxSendTries,
146146
bool loadNewest, int pageIndex, int pageSize,
147147
bool? sendManually = null)
148148
{
@@ -163,7 +163,7 @@ public virtual IPagedList<QueuedEmail> SearchEmails(string fromEmail,
163163
if (endTime.HasValue)
164164
query = query.Where(qe => qe.CreatedOnUtc <= endTime);
165165

166-
if (loadNotSentItemsOnly)
166+
if (loadUnsentItemsOnly)
167167
query = query.Where(qe => !qe.SentOnUtc.HasValue);
168168

169169
if (sendManually.HasValue)

src/Libraries/SmartStore.Services/Messages/QueuedMessagesSendTask.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ public partial class QueuedMessagesSendTask : ITask
99
{
1010
private readonly IQueuedEmailService _queuedEmailService;
1111

12-
public QueuedMessagesSendTask(
13-
IQueuedEmailService queuedEmailService)
12+
public QueuedMessagesSendTask(IQueuedEmailService queuedEmailService)
1413
{
1514
_queuedEmailService = queuedEmailService;
1615
}

0 commit comments

Comments
 (0)