Fetched results in imap2 to display in console

2019-08-07 07:10发布

问题:

I have made a script that connects to a imap server and then sends different messages,in order ot get the first mail[i only need the first one]. When I run the script I get no results but when i type the same last command in the terminal I get a result.

Any idea how to fix this?

MY script:

#!/usr/bin/expect
#!/bin/bash
set password 'ent'
spawn telnet host imap2
send "1 login picard enterprise\r"
send "2 list '' '*'\r"
expect "*"

send "3  EXAMINE INBOX\r"
send "4 fetch 1 all\r"

send "5 fetch 1 body[]\r"

As I said before ,when I type 5 fetch 1 body[] in terminal i get some output but the script shows nothing.any ideas?

回答1:

Your script has several syntax errors and I do not think you've made any attempt at researching IMAP syntax at all.

send "1 login picard enterprise\r"

This is correct provided that the login and password don't contain spaces or other odd characters, and that Expect actually sends \r\n when you type \r there.

send "2 list '' '*'\r"

'' is not IMAP, IMAP uses "".

send "3  EXAMINE INBOX\r"

You have one space too many after the 3. Spaces aren't idempotent in IMAP; if the protocol says to use one space you have to use exactly one, neither more nor less.

send "4 fetch 1 all\r"
send "5 fetch 1 body[]\r"

ALL and BODY[] overlap, why do you send both? You could just send 4 FETCH 1 (FLAGS INTERNALDATE BODY[]) and get the same data without repetition.