5

I'm new to IMAP functions in PHP and I am tasked to build some ticketing site.
I get the basic email fetching part but I kinda stumbled on the "Threaded Conversation View" hurdle.

I need to be able to present the emails (both sent and received) in a threaded conversation view much like a smartphone's SMS facility.

Most of the algorithms I found all just dealt with threaded inbox excluding the sent items. It would be nice if ya'll can help me with this.

My final target result would be, initially, an array of "UNREAD" mails grouped per subject each containing a trail of exchanged emails belonging to that subject.

Something like this:

array
(
  [0] => array
         (
           [0] => array
                  (
                    'date' => 'some date',
                    'sender' => 'some sender',
                    'message' => 'yes i am',
                    'subject' => 'Re: Fubar',
                    'status' => 'unread'
                  ),
           [1] => array
                  (
                    'date' => 'some date',
                    'sender' => 'some sender',
                    'message' => 'are you from america?',
                    'subject' => 'Re: Fubar',
                    'status' => 'read'
           [2] => array
                  (
                    'date' => 'some date',
                    'sender' => 'some sender',
                    'message' => 'hello',
                    'subject' => 'Re: Fubar',
                    'status' => 'read'
           [3] => array
                  (
                    'date' => 'some date',
                    'sender' => 'some sender',
                    'message' => 'hi',
                    'subject' => 'Fubar',
                    'status' => 'read'
         ),
  [1] => array
         (
           [0] => array
                  (
                    'date' => 'some date',
                    'sender' => 'some sender',
                    'message' => 'hell yeah!',
                    'subject' => 'Re: Skills',
                    'status' => 'unread'
                  ),
           [1] => array
                  (
                    'date' => 'some date',
                    'sender' => 'some sender',
                    'message' => 'are you good enough?',
                    'subject' => 'Skills',
                    'status' => 'read'
)
hakre
  • 193,403
  • 52
  • 435
  • 836
VeeBee
  • 847
  • 4
  • 13
  • 30
  • 1
    What have you tried so far and what didn't work out for you? With what in concrete do you need help? Which resources have you studied so far? The question in it's current form is a bit broad to be answered as the problem you talk about can have multiple solutions and your question does not contain enough information how you want to solve the problem. As far as IMAP is concerned, it's not clear for example if you set parent message IDs when an answer is created. – hakre Aug 06 '13 at 08:51
  • Also *"smartphone's SMS facility"* - My smarphone just has a list of all SMS, there are no threads. So I'd say this is not what you're looking for, probably draw a sketch that shows what you're looking for or some ascii art/scheme works better here. – hakre Aug 06 '13 at 08:52

1 Answers1

2

Perhaps imap_thread() is what you are after?

You'd have to loop through the results, and build your example array using imap_headerinfo(). As long as the mailbox you are querying against is kept trim, it ought to run fairly quickly.

hakre
  • 193,403
  • 52
  • 435
  • 836
Travis Hegner
  • 2,465
  • 1
  • 12
  • 11