Skip to content

Commit 31ec581

Browse files
committed
Added attachements to everything but the TUI. Also fixed the editor getting cleared out when changing back to edit from preview.
1 parent 109412d commit 31ec581

File tree

9 files changed

+203
-71
lines changed

9 files changed

+203
-71
lines changed

app.go

+34-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/tls"
66
"errors"
77
"fmt"
8-
"github.com/go-git/go-git/v5"
98
"io"
109
"io/fs"
1110
"io/ioutil"
@@ -14,8 +13,11 @@ import (
1413
"path/filepath"
1514
goruntime "runtime"
1615
"strconv"
16+
"strings"
1717
"time"
1818

19+
"github.com/go-git/go-git/v5"
20+
1921
//"github.com/davecgh/go-spew/spew"
2022

2123
clip "github.com/atotto/clipboard"
@@ -131,7 +133,7 @@ func (b *App) GetHomeDir() string {
131133
}
132134

133135
func (b *App) WriteFile(path string, data string) {
134-
err := os.WriteFile(path, []byte(data), 0666)
136+
err := os.WriteFile(path, []byte(data), 0o666)
135137
if err != nil {
136138
b.err = err.Error()
137139
}
@@ -185,7 +187,7 @@ func (b *App) ReadDir(path string) []FileInfo {
185187

186188
func (b *App) MakeDir(path string) {
187189
b.err = ""
188-
err := os.MkdirAll(path, 0755)
190+
err := os.MkdirAll(path, 0o755)
189191
if err != nil {
190192
b.err = err.Error()
191193
}
@@ -346,6 +348,13 @@ func (b *App) Quit() {
346348
wailsruntime.Quit(b.ctx)
347349
}
348350

351+
func (b *App) GetFiles() []string {
352+
files, _ := wailsruntime.OpenMultipleFilesDialog(b.ctx, wailsruntime.OpenDialogOptions{
353+
Title: "What files to you want to attach?",
354+
})
355+
return files
356+
}
357+
349358
func (b *App) GetOSName() string {
350359
os := goruntime.GOOS
351360
result := ""
@@ -409,16 +418,37 @@ func (b *App) GetGitHubScripts() []GitHubRepos {
409418
return result
410419
}
411420

412-
func (b *App) SendEmail(username string, from string, password string, host string, port string, toList string, msg string, msgText string, subject string) string {
421+
func (b *App) SendEmail(username string, from string, password string, host string, port string, toList string, msg string, msgText string, subject string, attachment string) string {
422+
//
423+
// Create the message.
424+
//
413425
m := mail.NewMessage()
414426
m.SetHeader("From", from)
415427
m.SetHeader("To", toList)
416428
m.SetHeader("Subject", subject)
417429
m.SetBody("text/plain", msgText)
418430
m.AddAlternative("text/html", msg)
431+
432+
//
433+
// Add attachment if any. The attachment string can have multiple one seperated by a coma.
434+
//
435+
if attachment != "" {
436+
parts := strings.Split(attachment, ", ")
437+
for i := 0; i < len(parts); i++ {
438+
m.Attach(parts[i])
439+
}
440+
}
441+
442+
//
443+
// Get the server information.
444+
//
419445
iport, _ := strconv.Atoi(port)
420446
d := mail.NewDialer(host, iport, username, password)
421447
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
448+
449+
//
450+
// Send the email.
451+
//
422452
if err := d.DialAndSend(m); err != nil {
423453
b.err = err.Error()
424454
return b.err

buildcli.go

+20-17
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"github.com/charmbracelet/bubbles/list"
8-
"github.com/charmbracelet/bubbles/textarea"
9-
"github.com/charmbracelet/bubbles/textinput"
10-
tea "github.com/charmbracelet/bubbletea"
11-
"github.com/charmbracelet/lipgloss"
127
"io"
138
"io/ioutil"
149
"net/http"
1510
"os"
1611
"strings"
12+
13+
"github.com/charmbracelet/bubbles/list"
14+
"github.com/charmbracelet/bubbles/textarea"
15+
"github.com/charmbracelet/bubbles/textinput"
16+
tea "github.com/charmbracelet/bubbletea"
17+
"github.com/charmbracelet/lipgloss"
1718
)
1819

1920
// Function: BuildEmail()
@@ -56,12 +57,13 @@ type (
5657
//
5758
// Description: This is the structure for sending an email to the EmailIt program.
5859
type HttpEmailMsg struct {
59-
Account string `json:"account"`
60-
To string `json:"to" binding:"required"`
61-
From string `json:"from" binding:"required"`
62-
Subject string `json:"subject" binding:"required"`
63-
Body string `json:"body" binding:"required"`
64-
ReturnMsg string `json:"returnMsg"`
60+
Account string `json:"account"`
61+
To string `json:"to" binding:"required"`
62+
From string `json:"from" binding:"required"`
63+
Subject string `json:"subject" binding:"required"`
64+
Body string `json:"body" binding:"required"`
65+
ReturnMsg string `json:"returnMsg"`
66+
Attachment string `json:"attachment"`
6567
}
6668

6769
type EmailAccounts struct {
@@ -319,11 +321,12 @@ func (m model) SendMessage() tea.Msg {
319321
fixacct := strings.Trim(m.account.Value(), " ")
320322
fixto := strings.Trim(m.to.Value(), " ")
321323
bodyJson := HttpEmailMsg{
322-
Account: fixacct,
323-
From: "Default",
324-
To: fixto,
325-
Subject: m.subject.Value(),
326-
Body: m.body.Value(),
324+
Account: fixacct,
325+
From: "Default",
326+
To: fixto,
327+
Subject: m.subject.Value(),
328+
Body: m.body.Value(),
329+
Attachment: "",
327330
}
328331
body, err := json.Marshal(bodyJson)
329332
bodyStr := string(body[:])
@@ -394,7 +397,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
394397
m.body.SetWidth(msg.Width - 10)
395398
m.body.SetHeight(msg.Height - 7)
396399
m.list.SetWidth(msg.Width - 10)
397-
//return m, nil
400+
// return m, nil
398401

399402
// We handle errors just like any other message
400403
case errMsg:

frontend/src/Main.svelte

+6-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@
369369
msg.to,
370370
processHTML,
371371
processText,
372-
msg.subject
372+
msg.subject,
373+
msg.attachment
373374
);
374375
} else if (msg.account === "Default") {
375376
//
@@ -386,7 +387,8 @@
386387
msg.to,
387388
processHTML,
388389
processText,
389-
msg.subject
390+
msg.subject,
391+
msg.attachment
390392
);
391393
} else {
392394
//
@@ -405,7 +407,8 @@
405407
msg.to,
406408
processHTML,
407409
processText,
408-
msg.subject
410+
msg.subject,
411+
msg.attachment
409412
);
410413
} else {
411414
result = "Account not found.";

frontend/src/components/CodeMirror.svelte

+3-20
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@
4242
export let width = 0;
4343
export let styling = "";
4444
export let config = {};
45-
export let initFinished = false;
4645
4746
let CodeMirrorEditor = null;
48-
let edState = null;
4947
let edView = null;
5048
let editorFunctions = null;
5149
let currentCursor = null;
@@ -128,9 +126,7 @@
128126
// Since we are setting a whole new document, create new editor
129127
// states and views.
130128
//
131-
if (initFinished) {
132-
CreateEditorState(text);
133-
}
129+
CreateEditorState(text);
134130
}
135131
136132
function CreateEditorState(text) {
@@ -211,19 +207,12 @@
211207
exts.push(highlightActiveLine());
212208
}
213209
214-
//
215-
// Create the editor state.
216-
//
217-
edState = EditorState.create({
218-
doc: text,
219-
extensions: exts,
220-
});
221-
222210
//
223211
// Create the editor View.
224212
//
225213
edView = new EditorView({
226-
state: edState,
214+
doc: text,
215+
extensions: exts,
227216
parent: CodeMirrorEditor,
228217
});
229218
}
@@ -248,7 +237,6 @@
248237
getLine: getLine,
249238
focus: focus,
250239
getEdView: getEdView,
251-
getEdState: getEdState,
252240
isFocused: isFocused,
253241
insertAtCursor: insertAtCursor,
254242
};
@@ -269,7 +257,6 @@
269257
return () => {
270258
// this function runs when the
271259
// component is destroyed
272-
edState = null;
273260
edView = null;
274261
editorFunctions = null;
275262
};
@@ -362,10 +349,6 @@
362349
function getEdView() {
363350
return edView;
364351
}
365-
366-
function getEdState() {
367-
return edState;
368-
}
369352
</script>
370353

371354
<div

0 commit comments

Comments
 (0)