-
Notifications
You must be signed in to change notification settings - Fork 1
/
CommentViewBox.ascx.cs
637 lines (548 loc) · 26.6 KB
/
CommentViewBox.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#region Copyright (c) 2003, newtelligence AG. All rights reserved.
/*
// Copyright (c) 2003, newtelligence AG. (http://www.newtelligence.com)
// Original BlogX Source Code: Copyright (c) 2003, Chris Anderson (http://simplegeek.com)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// (1) Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// (2) Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// (3) Neither the name of the newtelligence AG nor the names of its contributors may be used
// to endorse or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -------------------------------------------------------------------------
//
// Original BlogX source code (c) 2003 by Chris Anderson (http://simplegeek.com)
//
// newtelligence is a registered trademark of newtelligence Aktiengesellschaft.
//
// For portions of this software, the some additional copyright notices may apply
// which can either be found in the license.txt file included in the source distribution
// or following this notice.
//
*/
#endregion
using System;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Collections;
using newtelligence.DasBlog.Runtime;
using newtelligence.DasBlog.Web.Core;
using DotNetOpenId.RelyingParty;
using DotNetOpenId.Extensions.AttributeExchange;
using System.Collections.Generic;
using DotNetOpenId.Extensions.SimpleRegistration;
namespace newtelligence.DasBlog.Web
{
/// <summary>
/// Summary description for CommentView.
/// </summary>
public partial class CommentViewBox : System.Web.UI.UserControl
{
protected System.Web.UI.HtmlControls.HtmlForm CommentView;
// approval comments controls
// gravatar Message
protected System.Resources.ResourceManager resmgr;
public CommentViewBox()
{
}
protected void openid_identifier_LoggedIn(object sender, OpenIdEventArgs e) {
SharedBasePage requestPage = Page as SharedBasePage;
// only allow users to login using openid when we actually allow it
if (requestPage.SiteConfig.AllowOpenIdComments == true) {
ClaimsResponse fetch = e.Response.GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
string nick = e.Response.ClaimedIdentifier;
string homepage;
if (e.Response.ClaimedIdentifier.ToString().StartsWith("http"))
{
homepage = e.Response.ClaimedIdentifier;
}
else
{
homepage = "http://xri.net/" + e.Response.ClaimedIdentifier;
}
string email = "none@none.com";
if (fetch != null) {
nick = string.IsNullOrEmpty(fetch.Nickname) ? fetch.FullName : fetch.Nickname;
email = fetch.Email;
}
string comment = Request.QueryString["dasblog.comment"];
string entryId = Request.QueryString["dasblog.entryid"];
if (String.IsNullOrEmpty(comment) == false &&
String.IsNullOrEmpty(entryId) == false) {
AddNewComment(nick, email, homepage, comment, entryId, /* openid */ true);
}
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
SharedBasePage requestPage = Page as SharedBasePage;
// if you are commenting on your own blog, no need for Captha
if (SiteSecurity.IsValidContributor())
{
CaptchaControl1.Enabled = CaptchaControl1.Visible = false;
}
else
{
CaptchaControl1.Enabled = CaptchaControl1.Visible = requestPage.SiteConfig.EnableCaptcha;
}
resmgr = ApplicationResourceTable.Get();
if (!IsPostBack)
{
if (requestPage.WeblogEntryId.Length == 0)
{
requestPage.Redirect(SiteUtilities.GetStartPageUrl(requestPage.SiteConfig));
}
ViewState["entryId"] = requestPage.WeblogEntryId;
if (Request.Cookies["name"] != null)
{
string nameStr = HttpUtility.UrlDecode(Request.Cookies["name"].Value, Encoding.UTF8);
//truncate at 32 chars to avoid abuse...
name.Text = nameStr.Substring(0, Math.Min(32, nameStr.Length));
}
if (Request.Cookies["email"] != null)
{
email.Text = HttpUtility.UrlDecode(Request.Cookies["email"].Value, Encoding.UTF8);
}
if (Request.Cookies["homepage"] != null)
{
homepage.Text = HttpUtility.UrlDecode(Request.Cookies["homepage"].Value, Encoding.UTF8);
}
if (Request.Cookies["openid"] != null)
{
openid_identifier.Text = HttpUtility.UrlDecode(Request.Cookies["openid"].Value, Encoding.UTF8);
}
}
DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cvCaptcha.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.cvCaptcha_ServerValidate);
this.PreRender += new System.EventHandler(this.CommentView_PreRender);
}
#endregion
bool potentialSpamSubmitted = false;
protected void CommentView_PreRender(object sender, System.EventArgs e)
{
SharedBasePage requestPage = Page as SharedBasePage;
string entryId = (string)ViewState["entryId"];
bool obfuscateEmail = requestPage.SiteConfig.ObfuscateEmail;
Entry entry = requestPage.DataService.GetEntry(entryId);
if (entry != null)
{
//Modified 10-3-03 HPierson
//Render the day template with just the single entry, rather than the item template
//Modified 12-8-03 HPierson
//Using entry.CreatedLocalTime causes a bug when dasBlog is not configured to be in
//the same time zone as the server. Instead, we use the configured WindowsTimeZone
//to calculate the dasBlog configured local time for the entry
requestPage.WeblogEntries.Add(entry);
if (requestPage.SiteConfig.AdjustDisplayTimeZone)
{
newtelligence.DasBlog.Util.WindowsTimeZone wtz = requestPage.SiteConfig.GetConfiguredTimeZone();
requestPage.ProcessDayTemplate(wtz.ToLocalTime(entry.CreatedUtc), commentViewContent);
}
else
{
requestPage.ProcessDayTemplate(entry.CreatedUtc, commentViewContent);
}
HtmlAnchor commentStart = new HtmlAnchor();
commentStart.Name = "commentstart";
commentViewContent.Controls.Add(commentStart);
// Show all public comments, or all contents if you can approve them
// This way all non-public comments remain hidden, when you no longer require approval.
bool allComments = SiteSecurity.IsValidContributor();
foreach (Comment c in requestPage.DataService.GetCommentsFor(entryId, allComments))
{
SingleCommentView view = (SingleCommentView)LoadControl("SingleCommentView.ascx");
view.Comment = c;
view.ObfuscateEmail = obfuscateEmail;
commentViewContent.Controls.Add(view);
}
commentsClosed.Visible = false;
commentViewTable.Visible = true;
// only show the openid option when allowed in the config
openIdTable.Visible = requestPage.SiteConfig.AllowOpenIdComments;
commentsGravatarEnabled.Visible = requestPage.SiteConfig.CommentsAllowGravatar;
// show the comments require approval warning when moderating, or suspected spam,
// maybe users won't post multiple comments when their comment won't show immediately
commentsModerated.Visible = (requestPage.SiteConfig.CommentsRequireApproval || potentialSpamSubmitted);
if (potentialSpamSubmitted)
{
labelCommentsModerated.Text = resmgr.GetString("text_comment_potential_spam");
}
// display no/some html
labelCommentHtml.Visible = requestPage.SiteConfig.CommentsAllowHtml && (requestPage.SiteConfig.AllowedTags.AllowedTagsCount > 0);
labelComment.Visible = !labelCommentHtml.Visible;
labelCommentHtml.Text = String.Format(resmgr.GetString("text_comment_content_html"), requestPage.SiteConfig.AllowedTags.ToString());
if (SiteUtilities.AreCommentsAllowed(entry, requestPage.SiteConfig) == false)
{
commentsClosed.Visible = true;
commentViewTable.Visible = false;
openIdTable.Visible = false;
// if comments are not allow, there is no need to show the approval warning
commentsModerated.Visible = false;
}
if (Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "coCommentScript") == false && requestPage.SiteConfig.EnableCoComment == true)
{
string coCommentScript = String.Format(@"
<script type=""text/javascript"">
var blogTool = ""DasBlog"";
var blogURL = ""{0}"";
var blogTitle = ""{1}"";
var postURL = ""{2}"";
var postTitle = ""{3}"";
var commentAuthorFieldName = ""{4}"";
var commentAuthorLoggedIn = false;
var commentFormID = ""mainForm"";
var commentTextFieldName = ""{5}"";
var commentButtonName = ""{6}"";
</script>
<script id=""cocomment-fetchlet""
src=""http://www.cocomment.com/js/enabler.js"" type=""text/javascript""> // this activates coComment </script>
",
requestPage.SiteConfig.Root,
Server.HtmlEncode(requestPage.SiteConfig.Title),
Request.Url.ToString(),
Server.HtmlEncode(entry.Title),
this.name.ClientID,
this.comment.UniqueID,
this.add.ClientID
);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "coComment", coCommentScript);
}
}
}
private string FixUrl(string url)
{
if (false == String.IsNullOrEmpty(url))
{
if (url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
return url;
}
else
{
return "http://" + url;
}
}
else
{
return url;
}
}
protected void add_Click(object sender, System.EventArgs e)
{
SharedBasePage requestPage = Page as SharedBasePage;
if (String.IsNullOrEmpty(openid_identifier.Text) == false && openid_identifier.Text != "Click to Sign In")
{
try
{
IAuthenticationRequest req = openid_identifier.CreateRequest();
req.AddCallbackArguments("dasblog.comment", comment.Text);
req.AddCallbackArguments("dasblog.entryid", ViewState["entryId"].ToString().ToUpper());
SaveCookies();
openid_identifier.LogOn();
return; // the redirect prevents this line from executing anyway.
}
catch (UriFormatException ue) //They've entered something that's not a URI!
{
requestPage.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, "ERROR: " + openid_identifier.Text + " is not a valid URL. " + ue.Message, ""));
}
}
//Why isn't Page.Valiate("Normal") working? It returns false. Hm.
if (name.Text.Trim() != String.Empty)
{
SaveCookies();
AddNewComment(name.Text, email.Text, homepage.Text, comment.Text, ViewState["entryId"].ToString().ToUpper(), /* openid */ false);
}
}
private void SaveCookies()
{
if (rememberMe.Checked)
{
string path = HttpRuntime.AppDomainAppVirtualPath;
// We encode the name so High Latin folks like René Drießel don't break
// the Http Input Validation stuff and get their name remembered correctly.
// http://sourceforge.net/tracker/index.php?func=detail&aid=1158454&group_id=127624&atid=709018
HttpCookie cookieName = new HttpCookie("name", HttpUtility.UrlEncode(name.Text, Encoding.UTF8));
cookieName.Path = path;
Response.Cookies.Add(cookieName);
HttpCookie cookieEmail = new HttpCookie("email", HttpUtility.UrlEncode(email.Text, Encoding.UTF8));
cookieEmail.Path = path;
Response.Cookies.Add(cookieEmail);
HttpCookie cookieHomepage = new HttpCookie("homepage", HttpUtility.UrlEncode(homepage.Text, Encoding.UTF8));
cookieHomepage.Path = path;
Response.Cookies.Add(cookieHomepage);
HttpCookie cookieOpenId = new HttpCookie("openid", HttpUtility.UrlEncode(openid_identifier.Text, Encoding.UTF8));
cookieOpenId.Path = path;
Response.Cookies.Add(cookieOpenId);
Response.Cookies["name"].Expires = DateTime.MaxValue;
Response.Cookies["email"].Expires = DateTime.MaxValue;
Response.Cookies["homepage"].Expires = DateTime.MaxValue;
Response.Cookies["openid"].Expires = DateTime.MaxValue;
}
}
public void AddNewComment(string name, string email, string homepage, string comment, string entryId, bool openid)
{
SharedBasePage requestPage = Page as SharedBasePage;
// if we allow tags, use the allowed tags, otherwise use an empty array
ValidTagCollection allowedTags = (requestPage.SiteConfig.CommentsAllowHtml ? requestPage.SiteConfig.AllowedTags : new ValidTagCollection(null));
Entry entry = requestPage.DataService.GetEntry(entryId);
if ((entry != null) && SiteUtilities.AreCommentsAllowed(entry, requestPage.SiteConfig))
{
Comment c = new Comment();
c.Initialize();
c.OpenId = openid;
c.Author = HttpUtility.HtmlEncode(name);
c.AuthorEmail = HttpUtility.HtmlEncode(email);
c.AuthorHomepage = FixUrl(homepage);
c.AuthorIPAddress = Request.UserHostAddress;
c.AuthorUserAgent = Request.UserAgent;
c.Referer = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : String.Empty;
// clean the code from html tags
c.TargetEntryId = entryId;
c.TargetTitle = entry.Title;
if (requestPage.SiteConfig.CommentsRequireApproval == true &&
(requestPage.SiteConfig.SmtpServer == null || requestPage.SiteConfig.SmtpServer.Length == 0))
{
requestPage.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, "ERROR: Comment Moderation is turned on, but you haven't configured an SMTP Server for sending mail!", ""));
}
// if comments require moderation, they are not public.
// except when the commenter is a contributor
if (SiteSecurity.IsValidContributor() )
{
c.IsPublic = true;
}
else
{
// bypass spam when the comment is authenticated by openid en openid doesn't require approval
if (requestPage.SiteConfig.EnableSpamBlockingService && (requestPage.SiteConfig.BypassSpamOpenIdComment && openid) == false)
{
// make sure to send the unfiltered comment for analysis by external service
c.Content = comment;
bool externalServiceSucceeded = false;
try
{
if (requestPage.SiteConfig.SpamBlockingService.IsSpam(c))
{
potentialSpamSubmitted = true;
if (!requestPage.SiteConfig.EnableSpamModeration)
{
// abort saving the comment
requestPage.LoggingService.AddEvent(new EventDataItem(EventCodes.CommentBlocked, String.Format("Blocking suspected spam from {0} {1} [{2}].", c.Author, c.AuthorEmail, c.AuthorIPAddress), SiteUtilities.GetPermaLinkUrl(entryId)));
clearCommentInput();
return;
}
c.SpamState = SpamState.Spam;
c.IsPublic = false;
}
else
{
c.SpamState = SpamState.NotSpam;
c.IsPublic = true;
}
externalServiceSucceeded = true;
}
catch (Exception ex)
{
requestPage.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, String.Format("The external spam blocking service failed for comment {0}. Original exception: {1}", c.EntryId, ex), SiteUtilities.GetPermaLinkUrl(entryId)));
}
if (!externalServiceSucceeded)
{
// If the external service fails, we will hide the comment, but not delete it,
// even if moderation is disabled.
c.SpamState = SpamState.NotChecked;
if (doesFeedbackHaveSpamPotential(c))
{
potentialSpamSubmitted = true;
c.IsPublic = false;
}
else
{
c.IsPublic = true;
}
}
}
else
{
c.IsPublic = true;
}
// If comment moderation enabled, hide all comments regardless of the what the external spam service says
if (requestPage.SiteConfig.CommentsRequireApproval)
{
c.IsPublic = false;
}
}
// FilterHtml html encodes anything we don't like
string filteredText = SiteUtilities.FilterHtml(comment, allowedTags);
c.Content = filteredText;
if (requestPage.SiteConfig.SendCommentsByEmail &&
requestPage.SiteConfig.SmtpServer != null &&
requestPage.SiteConfig.SmtpServer.Length > 0)
{
SendMailInfo defaultMailInfo = ComposeMail(c);
requestPage.DataService.AddComment(c, defaultMailInfo);
requestPage.DataService.RunActions(ComposeMailForUsers(entry, c));
string commentShort = c.Content.Replace("\n", "");
if (commentShort.Length > 50)
{
commentShort = commentShort.Substring(0, 50) + "...";
}
requestPage.LoggingService.AddEvent(
new EventDataItem(
EventCodes.CommentAdded, commentShort, SiteUtilities.GetCommentViewUrl(entryId)));
}
else
{
requestPage.DataService.AddComment(c);
}
clearCommentInput();
// break the caching
requestPage.DataCache.Remove("BlogCoreData");
Session.Remove("pendingComment");
Session.Remove("pendingEntryId");
//Send the user to the comment they JUST posted.
if (!potentialSpamSubmitted)
{
Response.Redirect(SiteUtilities.GetCommentViewUrl(c.TargetEntryId) + "#" + c.EntryId);
}
}
}
/// <summary>
/// Performs simple analysis to make a best guess at the feedback's spam potential
/// </summary>
/// <param name="feedback">The feedback to check for spam</param>
/// <returns></returns>
private bool doesFeedbackHaveSpamPotential(IFeedback feedback)
{
//TODO: Add more rules as we see fit. For now, we will use the simple rule: if it contains hyperlinks, it might be spam.
return (SiteUtilities.FindHyperLinks(feedback.Content).Count > 0);
}
private void clearCommentInput()
{
name.Text = "";
email.Text = "";
homepage.Text = "";
comment.Text = "";
}
private object[] ComposeMailForUsers(Entry entry, Comment c)
{
ArrayList actions = new ArrayList();
foreach (User user in SiteSecurity.GetSecurity().Users)
{
if (user.EmailAddress == null || user.EmailAddress.Length == 0)
continue;
if (user.NotifyOnAllComment || (user.NotifyOnOwnComment && entry.Author.ToUpper() == user.Name.ToUpper()))
{
SendMailInfo sendMailInfo = ComposeMail(c);
sendMailInfo.Message.To.Add(user.EmailAddress);
actions.Add(sendMailInfo);
}
}
return (object[])actions.ToArray(typeof(object));
}
private SendMailInfo ComposeMail(Comment c)
{
SharedBasePage requestPage = Page as SharedBasePage;
MailMessage emailMessage = new MailMessage();
if (requestPage.SiteConfig.NotificationEMailAddress != null &&
requestPage.SiteConfig.NotificationEMailAddress.Length > 0)
{
emailMessage.To.Add(requestPage.SiteConfig.NotificationEMailAddress);
}
else
{
emailMessage.To.Add(requestPage.SiteConfig.Contact);
}
emailMessage.Sender = new MailAddress(requestPage.SiteConfig.Contact);
emailMessage.Subject = String.Format("Weblog comment by '{0}' from '{1}' on '{2}'", c.Author, c.AuthorHomepage, c.TargetTitle);
if (requestPage.SiteConfig.CommentsRequireApproval)
{
emailMessage.Body = String.Format("{0}\r\nComments page: {1}\r\n\r\nApprove comment: {2}\r\n\r\nDelete Comment: {3}",
HttpUtility.HtmlDecode(c.Content),
SiteUtilities.GetCommentViewUrl(c.TargetEntryId),
SiteUtilities.GetCommentApproveUrl(c.TargetEntryId, c.EntryId),
SiteUtilities.GetCommentDeleteUrl(c.TargetEntryId, c.EntryId));
}
else
{
emailMessage.Body = String.Format("{0}\r\nComments page: {1}\r\n\r\nDelete Comment: {2}",
HttpUtility.HtmlDecode(c.Content),
SiteUtilities.GetCommentViewUrl(c.TargetEntryId),
SiteUtilities.GetCommentDeleteUrl(c.TargetEntryId, c.EntryId));
if (c.SpamState == SpamState.Spam)
{
emailMessage.Body += "\r\nNot Spam: " + SiteUtilities.GetCommentApproveUrl(c.TargetEntryId, c.EntryId);
}
}
if (requestPage.SiteConfig.EnableSpamBlockingService && (c.SpamState != SpamState.Spam))
{
emailMessage.Body += "\r\n\r\nReport as SPAM: "
+ SiteUtilities.GetCommentReportUrl(requestPage.SiteConfig, c.TargetEntryId, c.EntryId)
+ "\r\n (Reporting SPAM will also delete the comment.)";
}
emailMessage.Body += "\r\n\r\n" + ApplicationResourceTable.GetSpamStateDescription(c.SpamState);
emailMessage.IsBodyHtml = false;
emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
if (c.AuthorEmail != null && c.AuthorEmail.Length > 0)
{
emailMessage.From = new MailAddress(c.AuthorEmail);
}
else
{
emailMessage.From = new MailAddress(requestPage.SiteConfig.Contact);
}
emailMessage.Headers.Add("Sender", requestPage.SiteConfig.Contact);
// add the X-Originating-IP header
string hostname = Dns.GetHostName();
IPHostEntry ipHostEntry = Dns.GetHostEntry(hostname);
if (ipHostEntry.AddressList.Length > 0)
{
emailMessage.Headers.Add("X-Originating-IP", ipHostEntry.AddressList[0].ToString());
}
SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, requestPage.SiteConfig.SmtpServer,
requestPage.SiteConfig.EnableSmtpAuthentication, requestPage.SiteConfig.UseSSLForSMTP, requestPage.SiteConfig.SmtpUserName,
requestPage.SiteConfig.SmtpPassword, requestPage.SiteConfig.SmtpPort);
return sendMailInfo;
}
private void cvCaptcha_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
SharedBasePage requestPage = Page as SharedBasePage;
if (CaptchaControl1.Enabled && requestPage.SiteConfig.EnableCaptcha)
{
args.IsValid = CaptchaControl1.UserValidated;
}
}
}
}