Skip to content

Commit

Permalink
0.9.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hessandrew committed May 1, 2023
1 parent f432a02 commit a3519ce
Show file tree
Hide file tree
Showing 29 changed files with 142 additions and 5 deletions.
59 changes: 56 additions & 3 deletions src/clawPDF.Core/Actions/EMailClientAction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
using System;
using System.Text.RegularExpressions;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using clawSoft.clawPDF.Core.Jobs;
using clawSoft.clawPDF.Mail;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using NLog;
using System.Collections.Generic;
using PdfToSvg;
using Org.BouncyCastle.Cms;
using System.Linq;

namespace clawSoft.clawPDF.Core.Actions
{
Expand Down Expand Up @@ -36,9 +44,27 @@ public ActionResult ProcessJob(IJob job)

if (job.Profile.EmailClient.AddSignature) message.Body += _signatureText;

foreach (var recipient in job.Profile.EmailClient.Recipients.Replace(',', ';').Split(';'))
if (!string.IsNullOrWhiteSpace(recipient))
message.To.Add(recipient.Trim());
if (!job.Profile.EmailClient.Autodetect)
{
foreach (var recipient in job.Profile.EmailClient.Recipients.Replace(',', ';').Split(';'))
if (!string.IsNullOrWhiteSpace(recipient))
message.To.Add(recipient.Trim());
}
else
{
foreach (var file in job.OutputFiles)
{
if (file.Contains(".pdf"))
{
List<string> emails = ExtractEmailsFromPdf(file);
List<string> distinctemails = emails.Distinct().ToList();
foreach (string email in distinctemails)
{
message.To.Add(email.Trim());
}
}
}
}

foreach (var file in job.OutputFiles) message.Attachments.Add(new Attachment(file));

Expand Down Expand Up @@ -70,6 +96,33 @@ public ActionResult ProcessJob(IJob job)
}
}

public static List<string> ExtractEmailsFromPdf(string pdfPath)
{
var emails = new List<string>();

using (PdfReader reader = new PdfReader(pdfPath))
{
using (iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(reader))
{
var pageCount = pdfDocument.GetNumberOfPages();
var regexPattern = new Regex(@"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b");

for (int i = 1; i <= pageCount; i++)
{
var pageContent = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(i), new SimpleTextExtractionStrategy());
var matches = regexPattern.Matches(pageContent);

foreach (Match match in matches)
{
emails.Add(match.Value);
}
}
}
}

return emails;
}

public static bool CheckEmailClientInstalled()
{
var emailClientFactory = new EmailClientFactory();
Expand Down
18 changes: 18 additions & 0 deletions src/clawPDF.Settings/EmailClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public EmailClient()
/// </summary>
public string Recipients { get; set; }

/// <summary>
/// Automatic detection of email(s) in the PDF document
/// </summary>
public bool Autodetect { get; set; }

/// <summary>
/// Subject line of the E-mail
/// </summary>
Expand Down Expand Up @@ -94,6 +99,15 @@ public void ReadValues(Data data, string path)
Recipients = "";
}

try
{
Autodetect = bool.Parse(data.GetValue(@"" + path + @"Autodetect"));
}
catch
{
Autodetect = true;
}

try
{
Subject = Data.UnescapeString(data.GetValue(@"" + path + @"Subject"));
Expand All @@ -110,6 +124,7 @@ public void StoreValues(Data data, string path)
data.SetValue(@"" + path + @"Content", Data.EscapeString(Content));
data.SetValue(@"" + path + @"Enabled", Enabled.ToString());
data.SetValue(@"" + path + @"Recipients", Data.EscapeString(Recipients));
data.SetValue(@"" + path + @"Autodetect", Autodetect.ToString());
data.SetValue(@"" + path + @"Subject", Data.EscapeString(Subject));
}

Expand All @@ -121,6 +136,7 @@ public EmailClient Copy()
copy.Content = Content;
copy.Enabled = Enabled;
copy.Recipients = Recipients;
copy.Autodetect = Autodetect;
copy.Subject = Subject;

return copy;
Expand All @@ -135,6 +151,7 @@ public override bool Equals(object o)
if (!Content.Equals(v.Content)) return false;
if (!Enabled.Equals(v.Enabled)) return false;
if (!Recipients.Equals(v.Recipients)) return false;
if (!Autodetect.Equals(v.Autodetect)) return false;
if (!Subject.Equals(v.Subject)) return false;

return true;
Expand All @@ -148,6 +165,7 @@ public override string ToString()
sb.AppendLine("Content=" + Content);
sb.AppendLine("Enabled=" + Enabled);
sb.AppendLine("Recipients=" + Recipients);
sb.AppendLine("Autodetect=" + Autodetect);
sb.AppendLine("Subject=" + Subject);

return sb.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<Label>
<TextBlock Name="RecipientsText">Recipients:</TextBlock>
</Label>
<CheckBox Name="EmailAutoDetect"
IsChecked="{Binding CurrentProfile.EmailClient.Autodetect}" Checked="EmailAutoDetect_Checked" Unchecked="EmailAutoDetect_Unchecked">
Automatic recognition
</CheckBox>
<TextBox Name="RecipientsTextBox" Text="{Binding CurrentProfile.EmailClient.Recipients}" Height="24" Foreground="{StaticResource ControlDefaultForeground}" Background="{StaticResource ContainerBackground}" />
<Label>
<TextBlock Name="MultipleRecipientsHintText" Margin="0 -3 0 0" TextWrapping="Wrap">Multiple recipients are separated by commas</TextBlock>
Expand Down
12 changes: 12 additions & 0 deletions src/clawPDF/Views/ActionControls/EmailClientActionControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public EmailClientActionControl()
"Description",
"Opens a new e-mail in the default client. There you can add receipients, text and other information and then send the mail to your contacts.");
TranslationHelper.Instance.TranslatorInstance.Translate(this);

// if (CurrentProfile.EmailClient.Autodetect) RecipientsTextBox.IsEnabled = false;
}

public override bool IsActionEnabled
Expand Down Expand Up @@ -99,5 +101,15 @@ private void EditEmailTextButton_OnClick(object sender, RoutedEventArgs e)
EmailClientSettings.AddSignature = setEmailTextForm.AddSignature;
}
}

private void EmailAutoDetect_Checked(object sender, RoutedEventArgs e)
{
RecipientsTextBox.IsEnabled = false;
}

private void EmailAutoDetect_Unchecked(object sender, RoutedEventArgs e)
{
RecipientsTextBox.IsEnabled = true;
}
}
}
1 change: 1 addition & 0 deletions src/clawPDF/languages/Catalan (Catalan).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Verifica el client de correu
EditEmailButtonText.Text=Edita el text del missatge
MultipleRecipientsHintText.Text=Múltiples destinataris separats per comes
RecipientsText.Text=Destinataris:
EmailAutoDetect.Content=Reconeixement automàtic

[EmailClientActionSettings]
CheckMailClient=Verifica el client de correu.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Catalan (Valencian).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Verifica el client de correu
EditEmailButtonText.Text=Edita el text del missatge
MultipleRecipientsHintText.Text=Múltiples destinataris separats per comes
RecipientsText.Text=Destinataris:
EmailAutoDetect.Content=Reconeixement automàtic

[EmailClientActionSettings]
CheckMailClient=Verifica el client de correu.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Chinese (Simplified).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=检查电子邮件客户端
EditEmailButtonText.Text=编辑电子邮件文字
MultipleRecipientsHintText.Text=以逗号分隔多个收件人
RecipientsText.Text=收件人:
EmailAutoDetect.Content=自动识别

[EmailClientActionSettings]
CheckMailClient=检查电子邮件客户端
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Chinese (Traditional).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=檢查電子郵件用戶端
EditEmailButtonText.Text=編輯電子郵件文字
MultipleRecipientsHintText.Text=以逗號分隔多個收件人
RecipientsText.Text=收件人:
EmailAutoDetect.Content=自動識別

[EmailClientActionSettings]
CheckMailClient=檢查電子郵件用戶端
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Corsican (France).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Verificà l'eMail
EditEmailButtonText.Text=Mudificà u Testu di l'eMail
MultipleRecipientsHintText.Text=I destinatarii diversi sò staccati da virgule
RecipientsText.Text=Destinatarii :
EmailAutoDetect.Content=Ricunniscenza automatica

[EmailClientActionSettings]
CheckMailClient=Verificazione di l'appiecazione di messaghjeria
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Czech.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Zkontroluj mailového klienta
EditEmailButtonText.Text=Uprav text emailu
MultipleRecipientsHintText.Text=Vícero příjemců se odděluje středníkem
RecipientsText.Text=Příjemci:
EmailAutoDetect.Content=Automatické rozpoznávání

[EmailClientActionSettings]
CheckMailClient=Zkontrolovat e-mailového klienta.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Danish.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Tjek e-mail-klient
EditEmailButtonText.Text=Rediger e-mail
MultipleRecipientsHintText.Text=Flere modtagere adskilles med kommaer
RecipientsText.Text=Modtagere:
EmailAutoDetect.Content=Automatisk genkendelse
[EmailClientActionSettings]
CheckMailClient=Tjek e-mail-klient
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Dutch.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Controleer e-mailprogramma
EditEmailButtonText.Text=Bewerk e-mail-bericht
MultipleRecipientsHintText.Text=Ontvangers worden met een komma gescheiden
RecipientsText.Text=Ontvangers:
EmailAutoDetect.Content=Automatische herkenning

[EmailClientActionSettings]
CheckMailClient=Controleer mailprogramma.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/English.ini
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ CheckMailClientButtonText.Text=Check E-Mail Client
EditEmailButtonText.Text=Edit E-Mail Text
MultipleRecipientsHintText.Text=Multiple recipients are separated by commas
RecipientsText.Text=Recipients:
EmailAutoDetect.Content=Automatic recognition

[EmailClientActionSettings]
CheckMailClient=Check e-mail client
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Estonian.ini
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ CheckMailClientButtonText.Text=Määra e-maili klient
EditEmailButtonText.Text=Muuda e-maili teksti
MultipleRecipientsHintText.Text=Mitu saajat tuleb eraldada komaga
RecipientsText.Text=Saajad:
EmailAutoDetect.Content=Automaatne äratundmine

[EmailClientActionSettings]
CheckMailClient=Otsin e-maili klienti
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Finnish.ini
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ CheckMailClientButtonText.Text=Tarkasta sähköpostisovellus
EditEmailButtonText.Text=Muokkaa sanomaa
MultipleRecipientsHintText.Text=Erota vastaanottajat toisistaan pilkuilla
RecipientsText.Text=Vastaanottajat:
EmailAutoDetect.Content=Automaattinen tunnistus

[EmailClientActionSettings]
CheckMailClient=Tarkasta sähköpostisovellus
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/French.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Vérifier le courriel
EditEmailButtonText.Text=Modifier le texte
MultipleRecipientsHintText.Text=Séparer les destinataires par des virgules
RecipientsText.Text=Destinataires :
EmailAutoDetect.Content=Reconnaissance automatique
[EmailClientActionSettings]
CheckMailClient=Vérifiez votre logiciel de messagerie.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Gaelic (Scotland).ini
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ CheckMailClientButtonText.Text=Thoir sùil air cliant a' phuist-d
EditEmailButtonText.Text=Deasaich teacsa a' phuist-d
MultipleRecipientsHintText.Text=Cuir cromagan eadar na h-ainmean ma tha thu airson a chur gu iomadh duine
RecipientsText.Text=Faightearan:
EmailAutoDetect.Content=Aithneachadh fèin-ghluasadach
[EmailClientActionSettings]
CheckMailClient=Thoir sùil air a' phrògram a chleachdas tu airson post-d.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/German.ini
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ CheckMailClientButtonText.Text=E-Mail-Client testen
EditEmailButtonText.Text=Nachricht bearbeiten
MultipleRecipientsHintText.Text=Mehrere Empfänger werden durch Kommas getrennt
RecipientsText.Text=Empfänger:
EmailAutoDetect.Content=Automatische Erkennung

[EmailClientActionSettings]
CheckMailClient=E-Mail-Client testen
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Hungarian.ini
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ CheckMailClientButtonText.Text=Levelezőprogram tesztelése
EditEmailButtonText.Text=Üzenet szövegének szerkesztése
MultipleRecipientsHintText.Text=Több címzett esetén vesszővel választhatja el őket egymástól
RecipientsText.Text=Címzettek:
EmailAutoDetect.Content=Automatikus felismerés

[EmailClientActionSettings]
CheckMailClient=Levelezőprogram tesztelése
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Italian.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Controlla client email
EditEmailButtonText.Text=Modifica testo email
MultipleRecipientsHintText.Text=Destinatari multipli separati da virgola
RecipientsText.Text=Destinatari:
EmailAutoDetect.Content=Riconoscimento automatico
[EmailClientActionSettings]
CheckMailClient=Controlla client email
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Lithuanian.ini
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ CheckMailClientButtonText.Text=Tikrinti el. pašto klientą
EditEmailButtonText.Text=Redaguoti el. pašto tekstą
MultipleRecipientsHintText.Text=Keli gavėjai atskirti kableliais
RecipientsText.Text=Gavėjai:
EmailAutoDetect.Content=Automatinis atpažinimas

[EmailClientActionSettings]
CheckMailClient=Patikrinti el. pašto klientą.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Norwegian, Bokmal (Norway).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Sjekk e-mail-klient
EditEmailButtonText.Text=Rediger e-mail
MultipleRecipientsHintText.Text=Flere mottakere adskilles med kommaer
RecipientsText.Text=Mottakere:
EmailAutoDetect.Content=Automatisk gjenkjenning
[EmailClientActionSettings]
CheckMailClient=Sjekk e-mail-klient
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Polish.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Wybierz klienta poczty e-mail
EditEmailButtonText.Text=Edytuj tekst e-mail
MultipleRecipientsHintText.Text=Wielu odbiorców oddzielonych przecinkami
RecipientsText.Text=Odbiorcy:
EmailAutoDetect.Content=Automatyczne rozpoznawanie

[EmailClientActionSettings]
CheckMailClient=Wybierz klienta poczty e-mail
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Portuguese (Brazil).ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Verificar Cliente de E-Mail
EditEmailButtonText.Text=Editar Texto do E-mail
MultipleRecipientsHintText.Text=Vários destinatários separados por vírgulas
RecipientsText.Text=Destinatários:
EmailAutoDetect.Content=Reconhecimento automático

[EmailClientActionSettings]
CheckMailClient=Verificar cliente de e-mail.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Russian.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Проверить клиента электро
EditEmailButtonText.Text=Редактировать текст сообщения электронной почты
MultipleRecipientsHintText.Text=Несколько получателей через запятую
RecipientsText.Text=Получатели:
EmailAutoDetect.Content=Автоматическое распознавание

[EmailClientActionSettings]
CheckMailClient=Проверить почтовый клиент
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Slovenian.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Preveri e-poštni odjemalec
EditEmailButtonText.Text=Uredi besedilo e-pošte
MultipleRecipientsHintText.Text=Več prejemnikov ločite z vejicami.
RecipientsText.Text=Prejemniki:
EmailAutoDetect.Content=Samodejno prepoznavanje

[EmailClientActionSettings]
CheckMailClient=Preveri odjemalca e-pošte
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Spanish.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Verificar cliente de correo
EditEmailButtonText.Text=Editar texto del mensaje
MultipleRecipientsHintText.Text=Múltiples destinatarios separados por comas
RecipientsText.Text=Destinatarios:
EmailAutoDetect.Content=Reconocimiento automático

[EmailClientActionSettings]
CheckMailClient=Verificar el cliente de correo.
Expand Down
1 change: 1 addition & 0 deletions src/clawPDF/languages/Swedish.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ CheckMailClientButtonText.Text=Kontrollera e-mailklienten
EditEmailButtonText.Text=Redigera e-mailtexten
MultipleRecipientsHintText.Text=Flera mottagare åtskiljs med kommatecken
RecipientsText.Text=Mottagare:
EmailAutoDetect.Content=Automatisk igenkänning

[EmailClientActionSettings]
CheckMailClient=Kontrollera e-mailklienten
Expand Down
Loading

0 comments on commit a3519ce

Please sign in to comment.