diff --git a/App.config b/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj new file mode 100644 index 0000000..3ae428d --- /dev/null +++ b/AwesomeEmailExtractor.csproj @@ -0,0 +1,84 @@ + + + + + Debug + AnyCPU + {FE70A2F9-D831-462E-8705-B14623544F1C} + WinExe + AwesomeEmailExtractor + AwesomeEmailExtractor + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/AwesomeEmailExtractor.sln b/AwesomeEmailExtractor.sln new file mode 100644 index 0000000..8dacd76 --- /dev/null +++ b/AwesomeEmailExtractor.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32421.90 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AwesomeEmailExtractor", "AwesomeEmailExtractor.csproj", "{FE70A2F9-D831-462E-8705-B14623544F1C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FE70A2F9-D831-462E-8705-B14623544F1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE70A2F9-D831-462E-8705-B14623544F1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE70A2F9-D831-462E-8705-B14623544F1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE70A2F9-D831-462E-8705-B14623544F1C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FC73771A-0ACD-4A6D-8C37-DD61308BF996} + EndGlobalSection +EndGlobal diff --git a/ExtactEmailsAlgorithm.cs b/ExtactEmailsAlgorithm.cs new file mode 100644 index 0000000..4509198 --- /dev/null +++ b/ExtactEmailsAlgorithm.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Text.RegularExpressions; + +namespace AwesomeEmailExtractor +{ + internal class ExtactEmailsAlgorithm + { + public static int Extract(string inputText, out List uniqueEmails) + { + // Регулярное выражение для поиска почтовых адресов + string pattern = @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"; + + // Находим каждый почтовый адрес в тексте + var matches = Regex.Matches(inputText, pattern, RegexOptions.IgnoreCase); + + // Получаем количество найденных адресов + int countMatches = matches.Count; + + // Получаем уникальные почтовые адреса + uniqueEmails = matches.Cast().Select(m => m.Value).Distinct().ToList(); + + return countMatches; + } + } +} diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs new file mode 100644 index 0000000..8ce0ef9 --- /dev/null +++ b/MainForm.Designer.cs @@ -0,0 +1,171 @@ +namespace AwesomeEmailExtractor +{ + partial class MainForm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.uniqueListBox = new System.Windows.Forms.ListBox(); + this.sourceRichTextBox = new System.Windows.Forms.RichTextBox(); + this.executeButton = new System.Windows.Forms.Button(); + this.resultCountLabel = new System.Windows.Forms.Label(); + this.resultStatusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.resultStatusStrip.SuspendLayout(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // uniqueListBox + // + this.uniqueListBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.uniqueListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.uniqueListBox.FormattingEnabled = true; + this.uniqueListBox.ItemHeight = 20; + this.uniqueListBox.Items.AddRange(new object[] { + "alice@example.com", + "bob@example.com"}); + this.uniqueListBox.Location = new System.Drawing.Point(424, 32); + this.uniqueListBox.Name = "uniqueListBox"; + this.uniqueListBox.Size = new System.Drawing.Size(225, 304); + this.uniqueListBox.TabIndex = 0; + // + // sourceRichTextBox + // + this.sourceRichTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.sourceRichTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.sourceRichTextBox.Location = new System.Drawing.Point(12, 32); + this.sourceRichTextBox.Name = "sourceRichTextBox"; + this.sourceRichTextBox.Size = new System.Drawing.Size(406, 288); + this.sourceRichTextBox.TabIndex = 1; + this.sourceRichTextBox.Text = "Алиса (alice@example.com) послылает Бобу (bob@example.com) сообщение.\nАдрес bob@e" + + "xample.com Алиса нашла на сайте example.com"; + // + // executeButton + // + this.executeButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.executeButton.Location = new System.Drawing.Point(12, 350); + this.executeButton.Name = "executeButton"; + this.executeButton.Size = new System.Drawing.Size(406, 24); + this.executeButton.TabIndex = 2; + this.executeButton.Text = "Выполнить"; + this.executeButton.UseVisualStyleBackColor = true; + this.executeButton.Click += new System.EventHandler(this.executeButton_Click); + // + // resultCountLabel + // + this.resultCountLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.resultCountLabel.AutoSize = true; + this.resultCountLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.resultCountLabel.Location = new System.Drawing.Point(12, 323); + this.resultCountLabel.Name = "resultCountLabel"; + this.resultCountLabel.Size = new System.Drawing.Size(303, 24); + this.resultCountLabel.TabIndex = 3; + this.resultCountLabel.Text = "Количество e-mail-ов в тексте: 3"; + // + // resultStatusStrip + // + this.resultStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabel}); + this.resultStatusStrip.Location = new System.Drawing.Point(0, 377); + this.resultStatusStrip.Name = "resultStatusStrip"; + this.resultStatusStrip.Size = new System.Drawing.Size(661, 22); + this.resultStatusStrip.TabIndex = 4; + // + // toolStripStatusLabel + // + this.toolStripStatusLabel.Name = "toolStripStatusLabel"; + this.toolStripStatusLabel.Size = new System.Drawing.Size(42, 17); + this.toolStripStatusLabel.Text = "Успех!"; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileToolStripMenuItem, + this.helpToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(661, 24); + this.menuStrip1.TabIndex = 5; + this.menuStrip1.Text = "menuStrip1"; + // + // fileToolStripMenuItem + // + this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + this.fileToolStripMenuItem.Size = new System.Drawing.Size(48, 20); + this.fileToolStripMenuItem.Text = "Файл"; + // + // helpToolStripMenuItem + // + this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; + this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); + this.helpToolStripMenuItem.Text = "Справка"; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(661, 399); + this.Controls.Add(this.uniqueListBox); + this.Controls.Add(this.executeButton); + this.Controls.Add(this.resultStatusStrip); + this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.resultCountLabel); + this.Controls.Add(this.sourceRichTextBox); + this.MainMenuStrip = this.menuStrip1; + this.MinimumSize = new System.Drawing.Size(642, 438); + this.Name = "MainForm"; + this.Text = "Main Form"; + this.resultStatusStrip.ResumeLayout(false); + this.resultStatusStrip.PerformLayout(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox uniqueListBox; + private System.Windows.Forms.RichTextBox sourceRichTextBox; + private System.Windows.Forms.Button executeButton; + private System.Windows.Forms.Label resultCountLabel; + private System.Windows.Forms.StatusStrip resultStatusStrip; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel; + } +} + diff --git a/MainForm.cs b/MainForm.cs new file mode 100644 index 0000000..c66334d --- /dev/null +++ b/MainForm.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + private void executeButton_Click(object sender, EventArgs e) + { + // Чистим предыдущий результат + toolStripStatusLabel.Text = ""; + resultCountLabel.Text = ""; + uniqueListBox.DataSource = null; + + // Объявляем список уникальных e-mail-ов + List uniqueEmails = new List(); + + // Получаем исходный текст из sourceRichTextBox + string sourceText = sourceRichTextBox.Text; + + // Вызываем метод для извлечения e-mail-ов + int count = ExtactEmailsAlgorithm.Extract(sourceText, out uniqueEmails); + + // Выводим результат + toolStripStatusLabel.Text = "Успех!"; + resultCountLabel.Text = $"Количество e-mail-ов в тексте: {count}"; + uniqueListBox.DataSource = uniqueEmails; + } + } +} diff --git a/MainForm.resx b/MainForm.resx new file mode 100644 index 0000000..f9962f8 --- /dev/null +++ b/MainForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 133, 17 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..a06ccf4 --- /dev/null +++ b/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + internal static class Program + { + /// + /// Главная точка входа для приложения. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..76a0cd2 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанных со сборкой. +[assembly: AssemblyTitle("AwesomeEmailExtractor")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AwesomeEmailExtractor")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, следует установить атрибут ComVisible в TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("fe70a2f9-d831-462e-8705-b14623544f1c")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +// Можно задать все значения или принять номера сборки и редакции по умолчанию +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.1")] +[assembly: AssemblyFileVersion("0.1")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..882a29a --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программным средством. +// Версия среды выполнения: 4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если +// код создан повторно. +// +//------------------------------------------------------------------------------ + +namespace AwesomeEmailExtractor.Properties +{ + + + /// + /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. + /// + // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder + // класс с помощью таких средств, как ResGen или Visual Studio. + // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen + // с параметром /str или заново постройте свой VS-проект. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AwesomeEmailExtractor.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Переопределяет свойство CurrentUICulture текущего потока для всех + /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3bb49f5 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AwesomeEmailExtractor.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + +