From 8769ce899fd5384e811caab23969f69aaaff93f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com> Date: Sun, 19 Apr 2020 19:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E4=BF=A1=E5=8F=AF=E4=BB=A5=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=85=A8=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imaptool.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/imaptool.go b/imaptool.go index 898509f..839d682 100644 --- a/imaptool.go +++ b/imaptool.go @@ -98,15 +98,21 @@ func main() { log.Printf("%s的邮件个数:%d \r\n", currentFolder, mbox.Messages) // 获取最新的信 - log.Println("读取最新的几封信:") + log.Println("读取最新的几封信(all全部):") inLine = readLineFromInput() - maxNum, _ := strconv.Atoi(inLine) + var maxNum uint32 + if inLine=="all"{ + maxNum=mbox.Messages + }else { + tempNum, _ := strconv.Atoi(inLine) + maxNum=uint32(tempNum) + } from := uint32(1) to := mbox.Messages - if mbox.Messages >= uint32(maxNum) { + if mbox.Messages >= maxNum { // 我们在这使用无符号整型, 这是再获取from的id - from = mbox.Messages - uint32(maxNum) + 1 + from = mbox.Messages - maxNum + 1 } else { log.Fatal("超出了邮件封数!") } @@ -121,7 +127,8 @@ func main() { log.Printf("最新的 %d 封信:", maxNum) for msg := range messages { - log.Println("* " + msg.Envelope.Subject) + log.Printf("* %d:%s\n" ,to,msg.Envelope.Subject) + to-- } if err := <-done; err != nil {