Forum Moderators: coopster

Message Too Old, No Replies

IAMP connection without IMAP module: Is fsockopen my savior?

Starting with the basics: I just want to read my email in my PHP script.

         

JAB Creations

6:14 pm on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a lot of stuff in PHP and most of what I keep reading is about sending email...but I want to read the email on my server!

I know that the mail is dumped as tiny files in a directory deeper then my public_html root folder (and I do have FTP access to it). I did some reading and I am convinced that using imap is the way to go for webmail versus pop (as I don't know much about them).

So I found out about imap_open however I was receiving the error message Call to undefined function imap_open() and upon further investigation discovered that the module is not installed on my live server.

I was also messing around with RoundCube (per someone's suggestion) and it claims to successfully connect to my server's imap service. Just to confirm it I slightly modified the credentials intentionally and it claims to not be able to connect. However using Advanced Find & Replace to see if the imap_open function existed in the script it found no instances (using *.* as the file type mask).

This meant that somehow RoundCube was connecting successfully to my server's imap service without using the imap_open function. When I posted intentionally bad credentials I received an error message about fsockopen. I can only presume that imap is only one type of "connection?" that passes through this socket?

What is most important for me initially is to know if I'm going in the correct direction to be able to eventually attain a list of emails on my server so that I can program PHP to allow me to read my own email. Sending mail isn't the issue for me. I'm also not interested in super complex code, classes, and such. I'm interested in learning the core parts and then optimizing my code. ;)

Also what else might I need to be concerned about or that people new to fsockopen commonly make mistakes with?

- John

JAB Creations

6:51 pm on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a successful connection with the following code...
$fp = @fsockopen("localhost", 993, $mail, $pass, 5);
if($fp) echo "<p>success</p>";
else echo "<p>failure: ".$errstr.'</p>';

...I'm not sure what to use however to actually interact with the mail after I've connected to the server?

Effectively: how do I figure what my "hands" are and how to use them?

- John

eelixduppy

8:15 pm on Jul 24, 2008 (gmt 0)



The best way to study open-source projects is to read the code. :)

What you are looking for is contained within the

lib/imap.inc
file as part of the RoundCube distribution. Take a peek and it should get you moving along.

JAB Creations

8:47 pm on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1.) Very good suggestion!

2.) *looks at the file size* Holy cow 67KB?! Don't get me wrong...I don't want to offload the work on to someone else but could you give me a slight hint if at all possible please? This was written by a guy on a whole different level than where I'm at right now! I just wrote my first extensive MySQL script that spans almost 500 lines...but this...geez! o.0

I only see two instances of fsockopen but I'm having a very difficult time figuring out what connects to what (I guess my working version of classes in PHP is very different from this guys!) Is this->a_class in example?

- John

eelixduppy

4:58 pm on Jul 26, 2008 (gmt 0)



I don't have the source in front of me right now, but from what I saw a few days ago it looked like they wrote their own reading function defined in that file. I'd take a look there to see exactly how they are reading the contents from there.

>> module is not installed on my live server

I'm assuming that you got this all worked out since you last posted here? Anyway, if you are serious about writing your own IMAP applications, I would suggest enabling this module on your server for the future.

>> Is this->a_class in example?

Not sure what you mean by this.

JAB Creations

6:07 pm on Jul 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My host woke up (5pm in the afternoon) and installed the module...so this issue is resolved for me. So I'm now able to work with the IMAP module thank goodness.

- John