Code Duplication    Length = 54-54 lines in 2 locations

classes/Email.php 1 location

@@ 50-103 (lines=54) @@
47
    }
48
  }
49
50
  public static function makeEnvelope(){
51
    $uid = md5(uniqid(time()));
52
    $head = $body = [];
53
54
    if ($this->from)     $head[] = 'From: ' . $this->from;
55
    if ($this->replyTo)  $head[] = 'Reply-To: ' . $this->replyTo;
56
57
    $head[] = 'MIME-Version: 1.0';
58
    $head[] = "Content-Type: multipart/mixed; boundary=\"".$uid."\"";
59
60
    $body[] = "--$uid";
61
    $body[] = "Content-type: text/html; charset=UTF-8";
62
    $body[] = "Content-Transfer-Encoding: quoted-printable";
63
    $body[] = '';
64
    $body[] = quoted_printable_encode($this->message);
65
    $body[] = '';
66
67
68
    foreach ($this->attachments as $file) {
69
      if (is_string($file)) {
70
        $name = basename($file);
71
        $data = file_get_contents($file);
72
      } else {
73
        $name = $file['name'];
74
        $data = $file['content'];
75
      }
76
77
      $body[] = "--$uid";
78
      $body[] = "Content-type: application/octet-stream; name=\"".$name."\"";
79
      $body[] = "Content-Transfer-Encoding: base64";
80
      $body[] = "Content-Disposition: attachment; filename=\"".$name."\"";
81
      $body[] = '';
82
      $body[] = chunk_split(base64_encode($data));
83
      $body[] = '';
84
    }
85
86
    $body[] = "--$uid--";
87
88
    $success = true;
89
    $head    = implode("\r\n",$head);
90
    $body    = implode("\r\n",$body);
91
92
    foreach ($this->recipients as $to) {
93
      $current_success = mail(
94
           $to,
95
           $this->subject,
96
           $body,
97
           $head
98
      );
99
      \Event::trigger('core.email.send', $to, $this->from, $this->subject, $body, $success);
100
      $success = $success && $current_success;
101
    }
102
    return $success;
103
  }
104
105
  protected static function send(array $options){
106
    $mail = static::agent();

classes/Email/Native.php 1 location

@@ 48-101 (lines=54) @@
45
    $this->attachments[] = $file;
46
  }
47
48
  public function send(){
49
    $uid = md5(uniqid(time()));
50
    $head = $body = [];
51
52
    if($this->from)     $head[] = 'From: ' . $this->from;
53
    if($this->replyTo)  $head[] = 'Reply-To: ' . $this->replyTo;
54
55
    $head[] = 'MIME-Version: 1.0';
56
    $head[] = "Content-Type: multipart/mixed; boundary=\"".$uid."\"";
57
58
    $body[] = "--$uid";
59
    $body[] = "Content-type: text/html; charset=UTF-8";
60
    $body[] = "Content-Transfer-Encoding: quoted-printable";
61
    $body[] = '';
62
    $body[] = quoted_printable_encode($this->message);
63
    $body[] = '';
64
65
66
    foreach ($this->attachments as $file) {
67
      if (is_string($file)) {
68
        $name = basename($file);
69
        $data = file_get_contents($file);
70
      } else {
71
        $name = $file['name'];
72
        $data = $file['content'];
73
      }
74
75
      $body[] = "--$uid";
76
      $body[] = "Content-type: application/octet-stream; name=\"".$name."\"";
77
      $body[] = "Content-Transfer-Encoding: base64";
78
      $body[] = "Content-Disposition: attachment; filename=\"".$name."\"";
79
      $body[] = '';
80
      $body[] = chunk_split(base64_encode($data));
81
      $body[] = '';
82
    }
83
84
    $body[] = "--$uid--";
85
86
    $success = true;
87
    $head    = implode("\r\n",$head);
88
    $body    = implode("\r\n",$body);
89
90
    foreach ($this->recipients as $to) {
91
      $current_success = mail(
92
           $to,
93
           $this->subject,
94
           $body,
95
           $head
96
      );
97
      \Event::trigger('core.email.send',$to,$this->from,$this->subject,$body,$success);
98
      $success = $success && $current_success;
99
    }
100
    return $success;
101
  }
102
103
}
104