예제 #1
0
//Dial dials a connection to the IMAP server
//If skipCerti is true then it will not check for the validity of the Certificate of the IMAP server,
//good only if IMAP server is using self signed certi.
func Dial(server *IMAPServer, skipCerti bool) (c *imap.Client, err error) {

	addr := fmt.Sprintf("%s:%d", server.Host, server.Port)
	if skipCerti {
		config := &tls.Config{
			InsecureSkipVerify: true,
			ServerName:         server.Host,
		}
		c, err = imap.DialTLS(addr, config)
	} else {
		c, err = imap.DialTLS(addr, nil)
	}
	return
}
예제 #2
0
func getImapClient(server string) *chatSyncClient {
	log.Printf("Connecting to IMAP server %v...", server)
	client, err := imap.DialTLS(server, nil)
	checkError(err)

	return &chatSyncClient{client, nil, make(chan uint32)}
}
예제 #3
0
파일: imap.go 프로젝트: sqs/go-synco
func Dial(server *IMAPServer) (c *imap.Client) {
	var err error
	addr := fmt.Sprintf("%s:%d", server.Host, server.Port)
	c, err = imap.DialTLS(addr, nil)
	if err != nil {
		panic(err)
	}
	return c
}
예제 #4
0
파일: server.go 프로젝트: justjake/mail
// esablish an IMAP connection over TLS
func (s *Server) dialTLS() (*imap.Client, error) {
	// establish new connection
	c, err := imap.DialTLS(s.Hostname, TLSConfig)
	if err != nil {
		return nil, err
	}

	s.client = c

	return c, nil
}
예제 #5
0
파일: demo2.go 프로젝트: kaihendry/go-imap
func Dial(addr string) (c *imap.Client) {
	var err error
	if strings.HasSuffix(addr, ":993") {
		c, err = imap.DialTLS(addr, nil)
	} else {
		c, err = imap.Dial(addr)
	}
	if err != nil {
		panic(err)
	}
	return c
}
예제 #6
0
func GetConnection(info InboxInfo, readOnly bool) (*imap.Client, error) {
	conn, err := imap.DialTLS(info.Host, new(tls.Config))
	if err != nil {
		return nil, err
	}

	_, err = conn.Login(info.User, info.Pw)
	if err != nil {
		return nil, err
	}

	_, err = imap.Wait(conn.Select("INBOX", readOnly))
	if err != nil {
		return nil, err
	}

	return conn, nil
}
예제 #7
0
// newIMAPClient will initiate a new IMAP connection with the given creds.
func newIMAPClient(host, username, password, mailbox string) (*imap.Client, error) {
	client, err := imap.DialTLS(host, new(tls.Config))
	if err != nil {
		return client, err
	}

	_, err = client.Login(username, password)
	if err != nil {
		return client, err
	}

	_, err = imap.Wait(client.Select(mailbox, false))
	if err != nil {
		return client, err
	}

	return client, nil
}
예제 #8
0
파일: imap.go 프로젝트: htr/imapfeeder
func imapConnect(addr, user, pass string) (*ImapSession, error) {
	c, err := imap.DialTLS(addr, nil)

	if err != nil {
		return nil, err
	}

	_, err = c.Login(user, pass)

	if err != nil {
		return nil, err
	}

	imapSession := &ImapSession{client: c}

	if c.Caps["X-GM-EXT-1"] {
		imapSession.isGmail = true
	}

	return imapSession, nil
}
예제 #9
0
파일: mailbox.go 프로젝트: sampsyo/madmin
func (conn *Connection) connect(host string) error {
	var err error
	conn.client, err = imap.DialTLS("imap.gmail.com", nil)
	return err
}
예제 #10
0
func connectNet(user string) {
	netTimeout := time.Second * 30
	cl, err := imap.DialTLS("imap.gmail.com", nil)
	if err != nil {
		log.Println(err)
		time.Sleep(netTimeout)
		return
	}
	defer cl.Logout(-1)
	log.Println("server says hello:", cl.Data[0].Info)
	cl.Data = nil
	log.Println("logging in")
	if cl.State() == imap.Login {
		_, err = cl.Login(user+"@gmail.com", "PASSHERE")
		if err != nil {
			log.Println(err)
			time.Sleep(netTimeout)
			return
		}
	}
	log.Println("logged in")
	log.Println("selecting INBOX")
	_, err = cl.Select("INBOX", false)
	if err != nil {
		log.Println(err)
		time.Sleep(netTimeout)
		return
	}
	log.Println("selected INBOX")
	set, _ := imap.NewSeqSet("")
searchLoop:
	for {
		var successCounter int
		conTimeout := 5
		log.Println("searching INBOX")
		cmd, err := imap.Wait(cl.Search("SUBJECT \"Confirm your email\""))
		if err != nil {
			log.Println(err)
			break searchLoop
		}
		searchResults := cmd.Data[0].SearchResults()
		if searchResults == nil {
			log.Println("no email[s] found")
			time.Sleep(time.Second * 5)
			break searchLoop
		} else {
			log.Println("found", len(searchResults), "emails to spoof, results:", searchResults)
			set.AddNum(searchResults...)
		}
		var rsp *imap.Response
		link := regexp.MustCompile(`https:=\r\n\/\/invites.oneplus.net\/confirm\/[0-9A-Z]*.`)
		var UIDCounter int
		log.Println("beginning spoof confirmation loop")
		cmd, err = cl.Fetch(set, "RFC822")
		if err != nil {
			log.Println(err)
			break searchLoop
		}
		setDone, _ := imap.NewSeqSet("")
	getMailLoop:
		for cmd.InProgress() {
			cl.Recv(-1)
			for _, rsp = range cmd.Data {
				message := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822"])
				if msg, err := mail.ReadMessage(bytes.NewReader(message)); msg != nil {
					log.Println("current conTimeout", conTimeout)
					body, err := ioutil.ReadAll(msg.Body)
					if err != nil {
						log.Println(err)
						break searchLoop
					}
					linkRawM := link.FindSubmatch(body)
					var linkRaw []byte
					if len(linkRawM) > 0 {
						linkRaw = linkRawM[0]
					} else {
						log.Println("found nolink mail")
						continue getMailLoop
					}
					log.Println(string(linkRaw))
					url, err := url.Parse(string(linkRaw[:6]) + string(linkRaw[9:]))
					if err != nil {
						log.Println(err)
						break searchLoop
					}
					log.Println(url)
					req := confirmURL.ReplaceAll(reqTemplate, []byte(url.Path)[:len(url.Path)-1])
					for {
						log.Println("attempting to spoof confirmation for", searchResults[UIDCounter])
						c, err := tls.Dial("tcp", url.Host+":443", nil)
						if err != nil {
							log.Println(err)
							break searchLoop
						}
						_, err = c.Write(req)
						if err != nil {
							log.Println(err)
							break searchLoop
						}
						resp, err := http.ReadResponse(bufio.NewReader(c), nil)
						if err != nil {
							log.Println(err)
							break searchLoop
						}
						if resp.StatusCode == 302 {
							redirectReg := regexp.MustCompile(`https:\/\/oneplus\.net\/invites\?kid=[0-9A-Z]*`)
							redirectURL, err := resp.Location()
							if err != nil {
								log.Println(err)
								break searchLoop
							}
							log.Println(resp.Location())
							if redirectReg.MatchString(redirectURL.String()) {
								log.Println("successfully spoofed confirmation for", searchResults[UIDCounter])
								setDone.AddNum(searchResults[UIDCounter])
								UIDCounter++
								if successCounter == 10 {
									conTimeout--
									successCounter = 0
								}
								break
							} else {
								log.Println("server trying to migitate spoofing")
								conTimeout++
								successCounter = 0
							}
						} else {
							log.Println("gg rip hamsters")
							conTimeout++
							successCounter = 0
						}
						time.Sleep(time.Second * time.Duration(conTimeout))
					}
				} else {
					log.Println(err)
				}
			}
			time.Sleep(time.Second * time.Duration(conTimeout))
			cmd.Data = nil
		}
		log.Println("deleting mail", setDone)
		_, err = imap.Wait(cl.Store(setDone, "+FLAGS", "\\DELETED"))
		if err != nil {
			log.Println(err)
			break searchLoop
		}
		_, err = imap.Wait(cl.Expunge(nil))
		if err != nil {
			log.Println(err)
			break searchLoop
		}
	}
}
예제 #11
0
func main() {
	flag.Parse()
	email, password := getCredentials()

	quit := make(chan os.Signal)
	signal.Notify(quit, os.Interrupt, os.Kill)
	go func() {
		<-quit
		os.Exit(0)
	}()

	connect := func(server string) (c *imap.Client, err error) {
		c, err = imap.DialTLS(server, &tls.Config{})
		if err != nil {
			return
		}

		_, err = c.Auth(imap.PlainAuth(email, password, ""))
		if err != nil {
			return
		}

		log.Println("Successfully authed")

		cmd, err := c.Select(*mailbox, true)
		if err != nil {
			log.Println("Error selecting mailbox: ", err)
			return
		}
		_, err = cmd.Result(imap.OK)
		if err != nil {
			return
		}

		log.Println("Successfully selected ", *mailbox)

		_, err = c.Idle()
		if err != nil {
			return
		}

		log.Println("Starting idle...")
		c.Data = nil

		return
	}

loop:
	for {
		if err := cmd(); err != nil {
			log.Printf("Error running sync on new loop: %s\n", err)
			continue
		}

		c, err := connect("imap.gmail.com")
		if err != nil {
			continue
		}

		wait := true
		for wait {
			err = c.Recv(15 * time.Minute)
			switch err {
			case nil:
				fallthrough
			case io.EOF:
				// We received content from server -- sync mails
				wait = false
			case imap.ErrTimeout:
				// after the timeout, wakeup the connection
				if _, err := c.IdleTerm(); err != nil {
					log.Println("Error finishing idle:: ", err)
					continue loop
				}
				if _, err := imap.Wait(c.Noop()); err != nil {
					log.Println("Error nooping: ", err)
					continue loop
				}
				log.Println("Keeping it alive !")
				if _, err := c.Idle(); err != nil {
					log.Println("Error re-idling: ", err)
					continue loop
				}
			default:
				log.Println("Error while receiving content: ", err)
				continue loop
			}
		}

		for _, rsp := range c.Data {
			if rsp.Label == "EXISTS" {
				log.Println("New message, running sync...")
				if err := cmd(); err != nil {
					log.Printf("Error running sync: %s\n", err)
				}
				log.Println("Ran sync")
			}
		}

		c.Data = nil
	}
}
예제 #12
0
파일: readmail.go 프로젝트: llvtt/gomail
func main() {
	// Source: https://godoc.org/code.google.com/p/go-imap/go1/imap#example-Client
	// Note: most of error handling code is omitted for brevity
	//

	// Connect to the server
	c, _ = imap.DialTLS(IMAP_SERVER, nil)

	// Remember to log out and close the connection when finished
	defer c.Logout(30 * time.Second)

	// Print server greeting (first response in the unilateral server data queue)
	fmt.Println("Server says hello:", c.Data[0].Info)
	c.Data = nil

	// Enable encryption, if supported by the server
	if c.Caps["STARTTLS"] {
		c.StartTLS(nil)
	}

	// Authenticate
	if c.State() == imap.Login {
		c.Login(USERNAME, PASSWORD)
	}

	// List all top-level mailboxes, wait for the command to finish
	cmd, _ = imap.Wait(c.List("", "%"))

	// Print mailbox information
	fmt.Println("\nTop-level mailboxes:")
	for _, rsp = range cmd.Data {
		fmt.Println("|--", rsp.MailboxInfo())
	}

	// Check for new unilateral server data responses
	for _, rsp = range c.Data {
		fmt.Println("Server data:", rsp)
	}
	c.Data = nil

	// Open a mailbox (synchronous command - no need for imap.Wait)
	c.Select("INBOX", true)
	fmt.Print("\nMailbox status:\n", c.Mailbox)

	// Fetch the headers of the 10 most recent messages
	set, _ := imap.NewSeqSet("")
	if c.Mailbox.Messages >= 10 {
		set.AddRange(c.Mailbox.Messages-19, c.Mailbox.Messages)
	} else {
		set.Add("1:*")
	}
	cmd, _ = imap.Wait(c.Fetch(set, HEADER_PART_NAME))

	messages := make([]*imap.MessageInfo, 0, 0)
	for _, rsp = range cmd.Data {
		// May not be necessary to check for nil here.
		if msg := rsp.MessageInfo(); msg != nil {
			messages = append(messages, msg)
		}
	}
	listMessages(messages)

	// // Process responses while the command is running
	// fmt.Println("\nMost recent messages:")
	// for cmd.InProgress() {
	// 	// Wait for the next response (no timeout)
	// 	c.Recv(-1)

	// 	// Process command data
	// 	for _, rsp = range cmd.Data {
	// 		header := imap.AsBytes(rsp.MessageInfo().Attrs[HEADER_PART_NAME])
	// 		if msg, _ := mail.ReadMessage(bytes.NewReader(header)); msg != nil {
	// 			fmt.Println("|--", msg.Header.Get("Subject"))
	// 		}
	// 	}
	// 	cmd.Data = nil

	// 	// Process unilateral server data
	// 	for _, rsp = range c.Data {
	// 		fmt.Println("Server data:", rsp)
	// 	}
	// 	c.Data = nil
	// }

	// // Check command completion status
	// if rsp, err := cmd.Result(imap.OK); err != nil {
	// 	if err == imap.ErrAborted {
	// 		fmt.Println("Fetch command aborted")
	// 	} else {
	// 		fmt.Println("Fetch error:", rsp.Info)
	// 	}
	// }

	//	render()
}