Fetched results in imap2 to display in console
Asked Answered
N

1

1

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?

Naturism answered 14/1, 2015 at 14:13 Comment(2)
I've always used longer tags in IMAP (A001 login ... instead of 1 login ...) to allow script to wait for command completion. Could you try send "A005 FETCH 1 BODY[]\r\n" expect "A005"Allcot
You can call this cheating but if you really want IMAP access in except you can use the imap4 package for Tcl (expect scripts are just Tcl code): docs.activestate.com/activetcl/8.4/tcllib/imap4/…. You will need to install Tcllib if you don't have it already installed but as a bonus you could also get better security by using TLS (see the top of the page I've linked to).Isaiasisak
I
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.

Inalienable answered 14/1, 2015 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.