Skip to content

Instantly share code, notes, and snippets.

@HalCanary
Last active May 24, 2023 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HalCanary/1117632a295157249a2b0fc2e91b7958 to your computer and use it in GitHub Desktop.
Save HalCanary/1117632a295157249a2b0fc2e91b7958 to your computer and use it in GitHub Desktop.
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