feat: update SDK and GUI versions, add debugger protection settings

- Updated SDK_DECODER_SEMVER to "1.3.0" and GUI_SEMVER to "1.2.4" in config.ini.
- Updated MailViewer component to handle PDF already open error and improved iframe handling.
- Removed deprecated useMsgConverter setting from settings page.
- Added IsDebuggerRunning function to check for attached debuggers and quit the app if detected.
- Enhanced PDF viewer to prevent infinite loading and improved error handling.

Co-Authored-By: Laky-64 <iraci.matteo@gmail.com>
This commit is contained in:
Flavio Fois
2026-02-04 23:25:20 +01:00
parent 0cda0a26fc
commit e7d1850a63
24 changed files with 1053 additions and 709 deletions

View File

@@ -1,6 +1,7 @@
package internal
import (
"bytes"
"fmt"
"io"
"net/mail"
@@ -8,8 +9,6 @@ import (
"strings"
"unicode/utf8"
"emly/backend/utils"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/transform"
)
@@ -39,7 +38,7 @@ func ReadEmlFile(filePath string) (*EmailData, error) {
}
defer file.Close()
email, err := utils.Parse(file)
email, err := Parse(file)
if err != nil {
return nil, fmt.Errorf("failed to parse email: %w", err)
}
@@ -122,3 +121,110 @@ func convertToUTF8(s string) string {
}
return decoded
}
func ReadPecInnerEml(filePath string) (*EmailData, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, fmt.Errorf("failed to open file: %w", err)
}
defer file.Close()
// 1. Parse outer "Envelope"
outerEmail, err := Parse(file)
if err != nil {
return nil, fmt.Errorf("failed to parse outer email: %w", err)
}
// 2. Look for the real content inside postacert.eml
var innerEmailData []byte
foundPec := false
for _, att := range outerEmail.Attachments {
// Standard PEC puts the real message in postacert.eml
// Using case-insensitive check and substring as per example
if strings.Contains(strings.ToLower(att.Filename), "postacert.eml") {
data, err := io.ReadAll(att.Data)
if err != nil {
return nil, fmt.Errorf("failed to read inner email content: %w", err)
}
innerEmailData = data
foundPec = true
break
}
}
if !foundPec {
return nil, fmt.Errorf("not a signed PEC or 'postacert.eml' attachment is missing")
}
// 3. Parse the inner EML content
innerEmail, err := Parse(bytes.NewReader(innerEmailData))
if err != nil {
return nil, fmt.Errorf("failed to parse inner email structure: %w", err)
}
// Helper to format addresses (reused logic pattern from eml_reader.go)
formatAddress := func(addr []*mail.Address) []string {
var result []string
for _, a := range addr {
// convertToUTF8 is defined in eml_reader.go (same package)
result = append(result, convertToUTF8(a.String()))
}
return result
}
// Determine body (prefer HTML)
body := innerEmail.HTMLBody
if body == "" {
body = innerEmail.TextBody
}
// Process attachments of the inner email
var attachments []EmailAttachment
var hasDatiCert, hasSmime, hasInnerPecEmail bool
for _, att := range innerEmail.Attachments {
data, err := io.ReadAll(att.Data)
if err != nil {
continue
}
// Check internal flags for the inner email (recursive PEC check?)
filenameLower := strings.ToLower(att.Filename)
if filenameLower == "daticert.xml" {
hasDatiCert = true
}
if filenameLower == "smime.p7s" {
hasSmime = true
}
if strings.HasSuffix(filenameLower, ".eml") {
hasInnerPecEmail = true
}
attachments = append(attachments, EmailAttachment{
Filename: att.Filename,
ContentType: att.ContentType,
Data: data,
})
}
isPec := hasDatiCert && hasSmime
// Format From
var from string
if len(innerEmail.From) > 0 {
from = innerEmail.From[0].String()
}
return &EmailData{
From: convertToUTF8(from),
To: formatAddress(innerEmail.To),
Cc: formatAddress(innerEmail.Cc),
Bcc: formatAddress(innerEmail.Bcc),
Subject: convertToUTF8(innerEmail.Subject),
Body: convertToUTF8(body),
Attachments: attachments,
IsPec: isPec,
HasInnerEmail: hasInnerPecEmail,
}, nil
}