Jump to content

IMAP mailbox functions in Flourish


Pete
 Share

Recommended Posts

I had need (or rather the desire) of a decent class to read and manipulate an IMAP mailbox and do some other functions, and whilst you can do this with PHP's built-in IMAP library it's impossible to do something as simple as fetch the last 10 emails for example - bizarrely you can only go for other filters such as unread, or a date range etc. There are also other things that I thought should be far easier than they were so I started looking for alternative solutions.

I went trawling through Google results until I found, or rather rediscovered, Flourish: http://flourishlib.com/ . It seems to have an excellent mail class to do everything I want and more and what is even better is that on the jQuery-like advanced download page you can click on the class you want (in my case fMailbox) and it selects other dependent classes. It comes out a bit weighty with those other classes at over 129kb compressed, but to be honest the features I'm going to code with it are only for staff users on a website so I'm not too bothered about a little bit of overhead.

Anyway, it's not something that's competition to ProcessWire, as Flourish is a library and not a CMS or specific framweork, but I thought it was worth mentioning because it looks quite handy in specific situations such as this where you want to code something that would be fairly complicated if done from scratch and you don't want to reinvent the wheel. It's also something I've searched for dozens of times before without actually successfully finding a satisfactory solution that looked well-coded or that didn't make the page it was used on slow to a crawl.

I'll let you know how I get on with it anyway if you're interested :)

Link to comment
Share on other sites

Oh, and I should probably say that if anyone has found or used a more compact email class/library for reading mailboxes and emails then please share as it's one of these niche situations that comes up every so often.

Link to comment
Share on other sites

Good link Pete, Thanks for posting this. I have visited Flourish site few times and gotta say that project has been growing a lot. Huge amount of classes there! I have never had need to read emails from php, but glad to know that it will be pretty simple task if I have to.

Link to comment
Share on other sites

Ah well it was all plain sailing until I had to create a wrapper so that it didn't interfere with Processwire and also I had to change the class as it retrieved emails oldest to newest with no option of doing newest to oldest (which you would think would be the default).

I submitted some code changes over on their site and I'll post my little wrapper script here in case anyone needs to use Flourish and PW together in future - no point anyone else scratching their heads as much as I was yesterday, though I'm sure someone with better OO PHP skills would have worked it out quicker.

Still, I now have the latest 10 emails pulled into my PW admin page and can click on the titles to open up the contents in a modal window so I'm happy despite the learning curve :)

The idea of all of this is it's for my gaming site and we have several editors who post news to the site and the emails are from publishers who send news to our press email account so it'a just a neat way of having everything in one place. I'm also intending to pull in information submitted through the site's contact form, so eventually the site admin page will be a hub of useful information for editors to dig into and update the site with.

Link to comment
Share on other sites

I'm thinking of perhaps taking it one step further and if someone emails us with news - a games developer for example - it could take the contents of the email and set up an unpublished page in our news section at the click of a button that then we can edit and publish.

These are all very fancy things that we don't really need, but sometimes it's nice to see what you can do with software :)

Off topic - we could probably do with a form for general coding talk when you're back ryan - no rush

Link to comment
Share on other sites

Just for info, attached is what I came up with. First screenshot shows the PW admin page with the last 10 press emails on the right and the second screenshot shows the first email in the list open in a modal window (the 1 of 10 and Next links at the bottom are both part of the modal script I used - it'll basically load the next email in the list as I set those links to be part of a group).

The modal window uses a slightly modified version of Shadowbox - purely because I'm used to it and know all the config options. If I was feeling less lazy I could just have easily took some time to use the modal script used by PW.

Also, I renamed the Pages page to Home (again, just personal preference) and put a header at the top of the page list and the email list.

I'll almost certainly be tweaking the admin style at some point as I'd really like to spend a bit of time making it feel like the rest of the site - not that I've got anything against the pink mind you! Again, no particular reason for re-theming the admin area, just thought it would be good to get to know the CSS and the template.

Anyway, for now I've got to put aside these nice distractions and get on with copying the site content over this weekend. It's going to take me a while so best get started! :)

EDIT: Sorry, you'll have to scroll to the bottom of the attached images and scroll right to view them properly. Not sure why attached images get inserted into the forums this way...

post-1356-132614278391_thumb.gif

post-1356-132614278432_thumb.jpg

Link to comment
Share on other sites

Very nice looking stuff Pete, congrats! I can clearly see the benefits - and I don't think that making news editing as easy as possible as "fancy" stuff. That will have good impact for making editors time more worth it. Which probably means more and better content for your site.

I think what pw-admin needs is module that allows to add widgets to dashboard (hmm.. needs dashboard page too :)). Ok, it is easy enough to build own admin and just put the code you want in there, but that isn't very modular way of doing that. There could be nice little analytics widget, latest comments widget, last edited pages, latest emails etc...

Link to comment
Share on other sites

Good points there - for me, I just renamed the Pages page to Home as it made more sense to me (used to seeing the tree on the admin homepage in MODx), but you're right that it's a little tricky to add things the way it is as there's only one template file you can edit.

It's not hard to check if we're viewing the Pages page and running code if we are but gets a little messy after a while.

Not directly related, but as I was adding content to a section yesterday I was looking through the PW source code to change the site tree so pagination kicks in at 30 pages rather than 50 and I've got to give credit to ryan's code commenting which told me I can just to it in the module settings - awesome stuff as I didn't realise modules had settings (not really looked into them in detail) and probably would have hacked it otherwise. Hooray for good code commenting ;)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...