Fetched results in imap2 to display in console

北战南征 提交于 2020-01-05 07:45:21

问题


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.



来源:https://stackoverflow.com/questions/27944984/fetched-results-in-imap2-to-display-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!