Skip to content

Commit

Permalink
Merge pull request #4 from nikhil1raghav/fix-timeout
Browse files Browse the repository at this point in the history
Fixed timeout issue while sending bigger files
  • Loading branch information
nikhil1raghav authored Sep 6, 2022
2 parents 2752cd8 + fc89c83 commit 052dd0a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ kindle-send --linkfile <path-to-url-file>

### Additional options

Default timeout for mail is 2 minutes, if you get timeout error while sending bigger files. Please increase the timeout using `--mail-timeout <number of seconds>` option



Specify the title for the document using `--title` option.

Specify a different configuration file using `--config` option. Configuration is stored in home directory as `KindleConfig.json`. You can directly edit it if you want.
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type config struct {
Server string `json:"server"`
Port int `json:"port"`
}

const DefaultTimeout = 120
var instance *config

func isGmail(mail string) bool {
Expand Down
6 changes: 5 additions & 1 deletion mail/mailer.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package mail

import (
"fmt"
"github.com/nikhil1raghav/kindle-send/util"
"os"
"time"

config "github.com/nikhil1raghav/kindle-send/config"

gomail "gopkg.in/mail.v2"
)

func Send(files []string) {
func Send(files []string, timeout int) {
cfg := config.GetInstance()
msg := gomail.NewMessage()
msg.SetHeader("From", cfg.Sender)
Expand All @@ -34,6 +36,8 @@ func Send(files []string) {
}

dialer := gomail.NewDialer(cfg.Server, cfg.Port, cfg.Sender, cfg.Password)
dialer.Timeout=time.Duration(timeout)*time.Second
fmt.Println("Dialer timeout ", dialer.Timeout)

util.CyanBold.Println("Sending mail")
if err := dialer.DialAndSend(msg); err != nil {
Expand Down
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ func extractLinks(filename string) (links []string) {
}
return
}
func flagPassed(name string) bool{
visited:=false
flag.Visit(func(f *flag.Flag) {
if f.Name==name{
visited=true
}
})
return visited
}
func main() {
DefaultConfig, err := config.DefaultConfigPath()
if err != nil {
Expand All @@ -38,6 +47,7 @@ func main() {
title := flag.String("title", "", "Title of the epub (optional)")
linkfile := flag.String("linkfile", "", "Path to a text file containing multiple links separated by newline")
filePath := flag.String("file", "", "Mail a file to kindle, use kindle-send as a simple mailer")
mailTimeout :=flag.Int("mail-timeout",30, "Timeout for sending mail int Seconds" )

flag.Parse()
passed := 0
Expand All @@ -48,6 +58,7 @@ func main() {
flag.PrintDefaults()
}


urls := make([]string, 0)
if len(*pageUrl) != 0 {
urls = append(urls, *pageUrl)
Expand All @@ -74,9 +85,12 @@ func main() {
filesToSend = append(filesToSend, book)
}
}

if len(filesToSend) != 0 {
mail.Send(filesToSend)
timeout:=config.DefaultTimeout
if flagPassed("mail-timeout"){
timeout=*mailTimeout
}
mail.Send(filesToSend, timeout)
}

}

0 comments on commit 052dd0a

Please sign in to comment.