jeudi 5 mai 2016

Design Pattern for handling many different scenarios - (Based On Email Contents)

So, I am working on a project that monitors 5 inboxes. Each inbox gets emails around a specific topic. (Orders, Outbound Shipment Notifications, Sample Requests, Service Invoices, and Inbound Shipment Notifications)

An email hits my server being redirected from a mail alias to a command line script, and sends the email contents to my PHP script.

From there, it saves the data to a DB for now. I'm struggling with the following and the best way to implement it.

I need to :

  • protect against duplicates (perhaps flag them so a user can visually confirm they are identical?)
  • scrape the content of the email so I can use this information to determine HOW to scrape the content
    • (based on the sender and subject, I can reasonably know what to look for.. ie. for ServiceInvoices, sometimes the Inv# is in the email, sometimes it is the name of the file itself)
  • Save the attachments
    • and associate them to the object in the 'received_emails' table
    • create an entity in the db for each attachments in table 'attachments'
  • IF it is a Shipment Notification
    • Find the Order in the system and associate this object with the order

I'm getting really confused because there are so many things that need to be done, but not all things to all emails. I've gotten it down to 5 buckets (inboxes) to simplify that part. But because each of these buckets need to accommodate different formats of emails, I'm finding it hard to take that first step!!

I would love any suggestions, advice, tips, pointers,... you name it. I am willing to try anything here.

Thank you!

Aucun commentaire:

Enregistrer un commentaire