Compare commits

..

5 Commits

11 changed files with 208 additions and 8 deletions

15
app.go
View File

@@ -44,7 +44,20 @@ func NewApp() *App {
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
Log("Wails startup")
isViewer := false
for _, arg := range os.Args {
if strings.Contains(arg, "--view-image") || strings.Contains(arg, "--view-pdf") {
isViewer = true
break
}
}
if isViewer {
Log("Second instance launch")
} else {
Log("Wails startup")
}
}
func (a *App) GetConfig() *utils.Config {

View File

@@ -2,6 +2,7 @@ package internal
import (
"bytes"
"encoding/base64"
"fmt"
"io"
"net/mail"
@@ -58,10 +59,68 @@ func ReadEmlFile(filePath string) (*EmailData, error) {
body = email.TextBody
}
// Process attachments and detect PEC
// Process attachments list and PEC detection
var attachments []EmailAttachment
var hasDatiCert, hasSmime, hasInnerEmail bool
// Process embedded files (inline images) -> add to body AND add as attachments
for _, ef := range email.EmbeddedFiles {
data, err := io.ReadAll(ef.Data)
if err != nil {
continue
}
// Convert to base64
b64 := base64.StdEncoding.EncodeToString(data)
mimeType := ef.ContentType
if parts := strings.Split(mimeType, ";"); len(parts) > 0 {
mimeType = strings.TrimSpace(parts[0])
}
if mimeType == "" {
mimeType = "application/octet-stream"
}
// Create data URI
dataURI := fmt.Sprintf("data:%s;base64,%s", mimeType, b64)
// Replace cid:reference with data URI in HTML body
// ef.CID is already trimmed of <>
target := "cid:" + ef.CID
body = strings.ReplaceAll(body, target, dataURI)
// ALSO ADD AS ATTACHMENTS for the viewer
filename := ef.CID
if filename == "" {
filename = "embedded_image"
}
// If no extension, try to infer from mimetype
if !strings.Contains(filename, ".") {
ext := "dat"
switch mimeType {
case "image/jpeg":
ext = "jpg"
case "image/png":
ext = "png"
case "image/gif":
ext = "gif"
case "application/pdf":
ext = "pdf"
default:
if parts := strings.Split(mimeType, "/"); len(parts) > 1 {
ext = parts[1]
}
}
filename = fmt.Sprintf("%s.%s", filename, ext)
}
attachments = append(attachments, EmailAttachment{
Filename: filename,
ContentType: mimeType,
Data: data,
})
}
// Process standard attachments
for _, att := range email.Attachments {
data, err := io.ReadAll(att.Data)
if err != nil {

View File

@@ -1,6 +1,6 @@
[EMLy]
SDK_DECODER_SEMVER="1.3.0"
SDK_DECODER_SEMVER="1.3.1"
SDK_DECODER_RELEASE_CHANNEL="beta"
GUI_SEMVER="1.2.4"
GUI_SEMVER="1.3.0"
GUI_RELEASE_CHANNEL="beta"
LANGUAGE="it"

View File

@@ -9,6 +9,7 @@
import { mailState } from "$lib/stores/mail-state.svelte";
import { settingsStore } from "$lib/stores/settings.svelte";
import * as m from "$lib/paraglide/messages";
import { dev } from "$app/environment";
let unregisterEvents = () => {};
let isLoading = $state(false);
@@ -22,11 +23,13 @@
}
$effect(() => {
console.log("Current email changed:", mailState.currentEmail);
if(dev) {
console.log(mailState.currentEmail)
}
console.info("Current email changed:", mailState.currentEmail?.subject);
if(mailState.currentEmail !== null) {
sidebarOpen.set(false);
}
console.log(mailState.currentEmail?.attachments)
})
onDestroy(() => {

View File

@@ -0,0 +1,56 @@
import { FrontendLog } from '$lib/wailsjs/go/main/App';
function safeStringify(obj: any): string {
try {
if (typeof obj === 'object' && obj !== null) {
return JSON.stringify(obj);
}
return String(obj);
} catch (e) {
return '[Circular/Error]';
}
}
export function setupConsoleLogger() {
if ((window as any).__logger_initialized__) return;
(window as any).__logger_initialized__ = true;
const originalLog = console.log;
const originalWarn = console.warn;
const originalError = console.error;
const originalInfo = console.info;
function logToBackend(level: string, args: any[]) {
try {
// Avoid logging if wails runtime is not ready or function is missing
if (typeof FrontendLog !== 'function') return;
const message = args.map(arg => safeStringify(arg)).join(' ');
FrontendLog(level, message).catch(() => {});
} catch (e) {
// ignore
}
}
console.log = (...args) => {
originalLog(...args);
logToBackend("INFO", args);
};
console.warn = (...args) => {
originalWarn(...args);
logToBackend("WARN", args);
};
console.error = (...args) => {
originalError(...args);
logToBackend("ERROR", args);
};
console.info = (...args) => {
originalInfo(...args);
logToBackend("INFO", args);
};
originalLog("Console logger hooked to Wails backend");
}

View File

@@ -6,6 +6,8 @@ import {internal} from '../models';
export function CheckIsDefaultEMLHandler():Promise<boolean>;
export function FrontendLog(arg1:string,arg2:string):Promise<void>;
export function GetConfig():Promise<utils.Config>;
export function GetImageViewerData():Promise<main.ImageViewerData>;

View File

@@ -6,6 +6,10 @@ export function CheckIsDefaultEMLHandler() {
return window['go']['main']['App']['CheckIsDefaultEMLHandler']();
}
export function FrontendLog(arg1, arg2) {
return window['go']['main']['App']['FrontendLog'](arg1, arg2);
}
export function GetConfig() {
return window['go']['main']['App']['GetConfig']();
}

View File

@@ -31,10 +31,12 @@
} from "$lib/wailsjs/runtime/runtime";
import { RefreshCcwDot } from "@lucide/svelte";
import { IsDebuggerRunning, QuitApp } from "$lib/wailsjs/go/main/App";
import { settingsStore } from "$lib/stores/settings.svelte.js";
let versionInfo: utils.Config | null = $state(null);
let isMaximized = $state(false);
let isDebugerOn: boolean = $state(false);
let isDebbugerProtectionOn: boolean = $state(true);
async function syncMaxState() {
isMaximized = await WindowIsMaximised();
@@ -69,7 +71,7 @@
}
onMount(async () => {
if (browser) {
if (browser && isDebbugerProtectionOn) {
detectDebugging();
setInterval(detectDebugging, 1000);
}
@@ -118,6 +120,8 @@
} catch {
stored = null;
}
isDebbugerProtectionOn = settingsStore.settings.enableAttachedDebuggerProtection ? true : false;
$inspect(isDebbugerProtectionOn, "isDebbugerProtectionOn");
applyTheme(stored === "light" ? "light" : "dark");
});

View File

@@ -1,9 +1,11 @@
<script lang="ts">
import { onMount } from 'svelte';
import { setupConsoleLogger } from '$lib/utils/logger-hook';
let { children } = $props();
onMount(() => {
setupConsoleLogger();
const loader = document.getElementById('app-loading');
if (loader) {
loader.style.opacity = '0';

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
@@ -10,7 +11,47 @@ import (
"time"
)
var logger = log.New(os.Stdout, "", 0)
var (
logger = log.New(os.Stdout, "", 0)
logFile *os.File
)
// InitLogger initializes the logger to write to both stdout and a file in AppData
func InitLogger() error {
configDir, err := os.UserConfigDir()
if err != nil {
return err
}
appDir := filepath.Join(configDir, "EMLy")
logsDir := filepath.Join(appDir, "logs")
if err := os.MkdirAll(logsDir, 0755); err != nil {
return err
}
logPath := filepath.Join(logsDir, "app.log")
// Open file in Append mode
file, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
logFile = file
// MultiWriter to write to both stdout and file
multi := io.MultiWriter(os.Stdout, file)
logger = log.New(multi, "", 0)
Log("Logger initialized. Writing to: " + logPath)
return nil
}
// CloseLogger closes the log file
func CloseLogger() {
if logFile != nil {
logFile.Close()
}
}
// Log prints a timestamped, file:line tagged log line.
func Log(args ...any) {
@@ -27,3 +68,14 @@ func Log(args ...any) {
msg := fmt.Sprintln(args...)
logger.Printf("[%s] - [%s] - [%s] - %s", date, tm, loc, strings.TrimRight(msg, "\n"))
}
// FrontendLog allows the frontend to send logs to the backend logger
func (a *App) FrontendLog(level string, message string) {
now := time.Now()
date := now.Format("2006-01-02")
tm := now.Format("15:04:05")
// We don't use runtime.Caller here because it would point to this function
// Instead we tag it as [FRONTEND]
logger.Printf("[%s] - [%s] - [FRONTEND] - [%s] %s", date, tm, level, message)
}

View File

@@ -28,6 +28,11 @@ func (a *App) onSecondInstanceLaunch(secondInstanceData options.SecondInstanceDa
}
func main() {
if err := InitLogger(); err != nil {
log.Println("Error initializing logger:", err)
}
defer CloseLogger()
// Check for custom args
args := os.Args
uniqueId := "emly-app-lock"