Last active
May 24, 2023 14:29
-
-
Save HalCanary/1117632a295157249a2b0fc2e91b7958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"exec" | |
"fmt" | |
"os" | |
"strings" | |
) | |
func ConvertToEbook(src, dst, title, authors, comments string) error { | |
const chapterTitleDetection = "//*[name()='h1' or name()='h2' or name()='h3']" | |
convert := exec.Command("ebook-convert", | |
src, dst, "--chapter", chapterTitleDetection, | |
"--title", title, "--authors", authors, "--comments", comments) | |
convert.Stdout, convert.Stderr = os.Stdout, os.Stderr | |
return convert.Run() | |
} | |
func MuttSendFile(dstEmail, filePath string) error { | |
st, err := os.Stat(filePath) | |
if err != nil { | |
return err | |
} | |
subject := fmt.Sprintf("[%d bytes] %s", st.Size(), filePath) | |
mutt := exec.Command("mutt", "-a", filePath, "-s", subject, "--", dstEmail) | |
mutt.Stdin = strings.NewReader("(file attached)") | |
mutt.Stdout, mutt.Stderr = os.Stdout, os.Stderr | |
return mutt.Run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment