Code Duplication    Length = 81-82 lines in 2 locations

htdocs/class/mail/phpmailer/class.phpmaileroauth.php 1 location

@@ 107-188 (lines=82) @@
104
        $hosts = explode(';', $this->Host);
105
        $lastexception = null;
106
107
        foreach ($hosts as $hostentry) {
108
            $hostinfo = array();
109
            if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
110
                // Not a valid host entry
111
                continue;
112
            }
113
            // $hostinfo[2]: optional ssl or tls prefix
114
            // $hostinfo[3]: the hostname
115
            // $hostinfo[4]: optional port number
116
            // The host string prefix can temporarily override the current setting for SMTPSecure
117
            // If it's not specified, the default value is used
118
            $prefix = '';
119
            $secure = $this->SMTPSecure;
120
            $tls = ($this->SMTPSecure == 'tls');
121
            if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
122
                $prefix = 'ssl://';
123
                $tls = false; // Can't have SSL and TLS at the same time
124
                $secure = 'ssl';
125
            } elseif ($hostinfo[2] == 'tls') {
126
                $tls = true;
127
                // tls doesn't use a prefix
128
                $secure = 'tls';
129
            }
130
            //Do we need the OpenSSL extension?
131
            $sslext = defined('OPENSSL_ALGO_SHA1');
132
            if ('tls' === $secure or 'ssl' === $secure) {
133
                //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
134
                if (!$sslext) {
135
                    throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
136
                }
137
            }
138
            $host = $hostinfo[3];
139
            $port = $this->Port;
140
            $tport = (integer)$hostinfo[4];
141
            if ($tport > 0 and $tport < 65536) {
142
                $port = $tport;
143
            }
144
            if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
145
                try {
146
                    if ($this->Helo) {
147
                        $hello = $this->Helo;
148
                    } else {
149
                        $hello = $this->serverHostname();
150
                    }
151
                    $this->smtp->hello($hello);
152
                    //Automatically enable TLS encryption if:
153
                    // * it's not disabled
154
                    // * we have openssl extension
155
                    // * we are not already using SSL
156
                    // * the server offers STARTTLS
157
                    if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
158
                        $tls = true;
159
                    }
160
                    if ($tls) {
161
                        if (!$this->smtp->startTLS()) {
162
                            throw new phpmailerException($this->lang('connect_host'));
163
                        }
164
                        // We must resend HELO after tls negotiation
165
                        $this->smtp->hello($hello);
166
                    }
167
                    if ($this->SMTPAuth) {
168
                        if (!$this->smtp->authenticate(
169
                            $this->Username,
170
                            $this->Password,
171
                            $this->AuthType,
172
                            $this->Realm,
173
                            $this->Workstation,
174
                            $this->oauth
175
                        )
176
                        ) {
177
                            throw new phpmailerException($this->lang('authenticate'));
178
                        }
179
                    }
180
                    return true;
181
                } catch (phpmailerException $exc) {
182
                    $lastexception = $exc;
183
                    $this->edebug($exc->getMessage());
184
                    // We must have connected, but then failed TLS or Auth, so close connection nicely
185
                    $this->smtp->quit();
186
                }
187
            }
188
        }
189
        // If we get here, all connection attempts have failed, so close connection hard
190
        $this->smtp->close();
191
        // As we've caught all exceptions, just report whatever the last one was

htdocs/class/mail/phpmailer/class.phpmailer.php 1 location

@@ 1623-1703 (lines=81) @@
1620
        $hosts = explode(';', $this->Host);
1621
        $lastexception = null;
1622
1623
        foreach ($hosts as $hostentry) {
1624
            $hostinfo = array();
1625
            if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
1626
                // Not a valid host entry
1627
                continue;
1628
            }
1629
            // $hostinfo[2]: optional ssl or tls prefix
1630
            // $hostinfo[3]: the hostname
1631
            // $hostinfo[4]: optional port number
1632
            // The host string prefix can temporarily override the current setting for SMTPSecure
1633
            // If it's not specified, the default value is used
1634
            $prefix = '';
1635
            $secure = $this->SMTPSecure;
1636
            $tls = ($this->SMTPSecure == 'tls');
1637
            if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
1638
                $prefix = 'ssl://';
1639
                $tls = false; // Can't have SSL and TLS at the same time
1640
                $secure = 'ssl';
1641
            } elseif ($hostinfo[2] == 'tls') {
1642
                $tls = true;
1643
                // tls doesn't use a prefix
1644
                $secure = 'tls';
1645
            }
1646
            //Do we need the OpenSSL extension?
1647
            $sslext = defined('OPENSSL_ALGO_SHA1');
1648
            if ('tls' === $secure or 'ssl' === $secure) {
1649
                //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
1650
                if (!$sslext) {
1651
                    throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
1652
                }
1653
            }
1654
            $host = $hostinfo[3];
1655
            $port = $this->Port;
1656
            $tport = (integer)$hostinfo[4];
1657
            if ($tport > 0 and $tport < 65536) {
1658
                $port = $tport;
1659
            }
1660
            if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
1661
                try {
1662
                    if ($this->Helo) {
1663
                        $hello = $this->Helo;
1664
                    } else {
1665
                        $hello = $this->serverHostname();
1666
                    }
1667
                    $this->smtp->hello($hello);
1668
                    //Automatically enable TLS encryption if:
1669
                    // * it's not disabled
1670
                    // * we have openssl extension
1671
                    // * we are not already using SSL
1672
                    // * the server offers STARTTLS
1673
                    if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
1674
                        $tls = true;
1675
                    }
1676
                    if ($tls) {
1677
                        if (!$this->smtp->startTLS()) {
1678
                            throw new phpmailerException($this->lang('connect_host'));
1679
                        }
1680
                        // We must resend EHLO after TLS negotiation
1681
                        $this->smtp->hello($hello);
1682
                    }
1683
                    if ($this->SMTPAuth) {
1684
                        if (!$this->smtp->authenticate(
1685
                            $this->Username,
1686
                            $this->Password,
1687
                            $this->AuthType,
1688
                            $this->Realm,
1689
                            $this->Workstation
1690
                        )
1691
                        ) {
1692
                            throw new phpmailerException($this->lang('authenticate'));
1693
                        }
1694
                    }
1695
                    return true;
1696
                } catch (phpmailerException $exc) {
1697
                    $lastexception = $exc;
1698
                    $this->edebug($exc->getMessage());
1699
                    // We must have connected, but then failed TLS or Auth, so close connection nicely
1700
                    $this->smtp->quit();
1701
                }
1702
            }
1703
        }
1704
        // If we get here, all connection attempts have failed, so close connection hard
1705
        $this->smtp->close();
1706
        // As we've caught all exceptions, just report whatever the last one was