· 5 years ago · Jul 18, 2020, 03:42 AM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace _27._08._2019.CSharp
8{
9 class Program
10 {
11 class Email
12 {
13 public String Subject { get; private set; }
14 public String Sender { get; private set; }
15 public String Body { get; private set; }
16 public Email(String subject, String sender, String body)
17 {
18 this.Subject = subject; this.Sender = sender; this.Body = body;
19 }
20 }
21
22 interface IFilter
23 {
24 List<String> CreateNewEmailList(List<Email> email);
25 List<String> CreateSendersList(List<Email> email);
26 }
27
28 class SpamFilter : IFilter
29 {
30 private List<String> spamKeywords = new List<string>();
31 public void AddSpamKeyword(String spamKeyword)
32 {
33 spamKeywords.Add(spamKeyword);
34 }
35
36 public List<String> CreateNewEmailList(List<Email> email)
37 {
38 List<string> newEmailList = new List<string>();
39 for (int i = 0; i < email.Count(); i++)
40 {
41 for (int j = 0; j < spamKeywords.Count(); i++)
42 {
43 if (email[i].Subject.Contains(":)") || email[i].Body.Contains(spamKeywords[j]))
44 {
45 newEmailList.Add(email[i].Body); //misli li se samo na spam sadrzaj ili na spam mail u globalu?
46 }
47 }
48 }
49 return newEmailList;
50 }
51
52 public List<String> CreateSendersList(List<Email> email)
53 {
54 List<String> sendersList = new List<string>();
55 for (int i = 0; i < email.Count(); i++)
56 {
57 for (int j = 0; j < spamKeywords.Count(); i++)
58 {
59 if (email[i].Subject.Contains(":)") || email[i].Body.Contains(spamKeywords[j]))
60 {
61 sendersList.Add(email[i].Sender);
62 }
63 }
64 }
65 return sendersList;
66 }
67 }
68
69 int EndsWithDomain(List<Email> email)
70 {
71 int counter = 0;
72 for(int i = 0; i < email.Count(); i++)
73 {
74 if (email[i].Sender.Contains("gmail.com"))
75 {
76 counter++;
77 }
78 }
79 return counter;
80 }
81
82 static void Main(string[] args)
83 {
84 List<Email> discountOffers = mailClient.FetchNewMessages();
85 int totalEmails = discountOffers.Count();
86 EndsWithDomain(discountOffers);
87 int newTotal = discountOffers.Count();
88 Console.WriteLine("Udio emailova koji je dosao s domene gmail.com je ", (newTotal/totalEmails)*100 , " %.");
89
90 }
91 }
92}