Skip to content

Commit 10ebe0c

Browse files
feat: Add email command for report-based email generation and introduce new phishing report files with screenshots.
1 parent ae01bc5 commit 10ebe0c

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

cmd/email.go

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ package cmd
55

66
import (
77
"fmt"
8+
"os"
9+
"path/filepath"
10+
"sort"
11+
"strings"
812

913
"github.com/charmbracelet/log"
1014
"github.com/spf13/cobra"
@@ -247,8 +251,57 @@ func getReportDirectory(reportDir string) (string, error) {
247251
// User specified a directory
248252
return reportDir, nil
249253
}
254+
cwd, err := os.Getwd()
255+
if err != nil {
256+
log.Error("Failed to get current working directory: %v", err)
257+
return "", err
258+
}
259+
entries, err := os.ReadDir(cwd)
260+
if err != nil {
261+
log.Error("Failed to read current working directory: %v", err)
262+
return "", err
263+
}
264+
var reportDirs []string
265+
for _, entry := range entries {
266+
if entry.IsDir() && strings.HasPrefix(entry.Name(), "report-") {
267+
hasFile, err := hasAnyFile(entry.Name())
268+
if err != nil {
269+
log.Error("Failed to check if directory is empty: %v", err)
270+
return "", err
271+
}
272+
if hasFile {
273+
reportDirs = append(reportDirs, entry.Name())
274+
}
275+
}
276+
}
277+
if len(reportDirs) > 0 {
278+
sort.Strings(reportDirs)
279+
latestDir := reportDirs[len(reportDirs)-1]
280+
return latestDir, nil
281+
}
282+
log.Error("No report directory found")
283+
return "", fmt.Errorf("no report directory found")
284+
}
285+
286+
func hasAnyFile(dirPath string) (bool, error) {
287+
var fileFound bool
288+
289+
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
290+
if err != nil {
291+
return err
292+
}
293+
294+
if !info.IsDir() {
295+
fileFound = true
296+
return filepath.SkipDir
297+
}
298+
299+
return nil
300+
})
301+
302+
if err == filepath.SkipDir {
303+
err = nil
304+
}
250305

251-
// TODO: Implement automatic detection of latest report-* directory
252-
// For now, return a placeholder
253-
return "report-latest", fmt.Errorf("automatic report directory detection not yet implemented")
306+
return fileFound, err
254307
}

0 commit comments

Comments
 (0)