Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class scraper_model extends CI_Model{
- function scrapeEmails($emails)
- {
- $this->load->model('job_model');
- $this->load->model('email_model');
- //check if there is an array of emails if not return no emails
- if($emails == NULL)
- {
- return "No emails";
- }
- else
- {
- //if there is an array of emails then check how many parts each has
- foreach($emails as $email)
- {
- //if email has 3 parts and
- if($email['structure']->parts >= 2)
- {
- foreach($email['structure']->parts as $partofpart)
- {
- //1 of those parts is type 3== pdf
- if($partofpart->type == 3)
- {
- //check if encoding is 3
- if($partofpart->encoding == 3)
- {
- //and finally check the dispostion is of attachment
- if($partofpart->disposition == "ATTACHMENT")
- {
- // if its base64 then decode the attachment
- $attachment = base64_decode($partofpart);
- var_dump($attachment);
- mkdir(APPPATH . "attachmentzs/");
- //then save the attachment with attachment name
- //file_put_contents(APPPATH . "attachments/". $partofpart->dparameters[0]->value, $attachment);
- }
- }
- if($partofpart->encoding == 4)
- {
- //quoted printable
- }
- }
- }
- }else if($email['structure']->parts <= 1)
- {
- // if the email has two or less parts its a normal html /plain email so use pregmatch to pull the information, the formatting of the email is important.
- $to;
- $date;
- $time;
- $ordernumber;
- $servicerequired;
- $serviceresponse;
- $servicelimit;
- $address;
- $contact;
- $telephone;
- $workdetails;
- $bodytext = $email['body'];
- //parsed quoted printable text
- $parsedtext = quoted_printable_decode($bodytext);
- //match the to: date: ordernumber fields etc using preg_match regular expressions
- preg_match("/To:\s+(.*)/", $parsedtext, $to);
- preg_match("/Date:\s+(.*)/", $parsedtext, $date);
- preg_match("/Order.Number:\s+(.*)/", $parsedtext, $ordernumber);
- preg_match("/Service.Required:\s+(.*)/", $parsedtext, $servicerequired);
- preg_match("/Service.Response:\s+(.*)/", $parsedtext, $serviceresponse);
- preg_match("/Service.Limit:\s+(.*)/", $parsedtext, $servicelimit);
- preg_match("/^(\w+[\w\s]+)(?!:)$/m", $parsedtext, $address);
- preg_match("/Contact:\s+(.*)/", $parsedtext, $contact);
- preg_match("/Telephone:\s+(.*)/", $parsedtext, $telephone);
- preg_match("/Work.Details:\s+(.*)/", $parsedtext, $workdetails);
- $query = $this->job_model->addNewJob($to[1], $ordernumber[1], $servicerequired[1], $serviceresponse[1], $servicelimit[1], $address[1], $contact[1], $telephone[1], $workdetails[1]);
- //if query returns false then no job was added
- if($query == false)
- {
- echo "Job not added";
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement