Skip to content

Instantly share code, notes, and snippets.

@msaladna
Created August 9, 2019 17:21
Show Gist options
  • Select an option

  • Save msaladna/4c8a355de05d99980a1dafaa5b8d2ea4 to your computer and use it in GitHub Desktop.

Select an option

Save msaladna/4c8a355de05d99980a1dafaa5b8d2ea4 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models\MailConfig;
class Mozilla extends \App\Models\MailConfig {
public static function handle() {
$host = $_SERVER['HTTP_HOST'];
$mail_domain = str_replace('autoconfig.', '', $host);
if (isset($_GET['domain'])) {
$mail_domain = $_GET['domain'];
}
$server = self::lookup($mail_domain);
$protocols = array(
'imaps',
'pop3s',
'smtp/tls',
);
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<clientConfig version="1.1">
<emailProvider id="<?php echo $mail_domain ?>">
<domain><?php echo $server ?></domain>
<displayName><?php echo $server ?> Mail</displayName>
<displayShortName><?php echo $server ?></displayShortName>
<?php foreach($protocols as $protocol): ?>
<?php switch($protocol):
case 'imap':
?>
<incomingServer type="imap">
<hostname><?php echo $server ?></hostname>
<port>143</port>
<socketType>plain</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>
<?php
break;
case 'imaps':
?>
<incomingServer type="imap">
<hostname><?php echo $server ?></hostname>
<port>993</port>
<socketType>SSL</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>
<?php
break;
case 'pop3':
?>
<incomingServer type="pop3">
<hostname><?php echo $server ?></hostname>
<port>110</port>
<socketType>plain</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>
<?php
break;
case 'pop3s':
?>
<incomingServer type="pop3">
<hostname><?php echo $server ?></hostname>
<port>995</port>
<socketType>SSL</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>
<?php
break;
case 'smtp/tls':
?>
<outgoingServer type="smtp">
<hostname><?php echo $server ?></hostname>
<port>587</port>
<socketType>STARTTLS</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</outgoingServer>
<?php
break;
case 'smtp':
?>
<outgoingServer type="smtp">
<hostname><?php echo $server ?></hostname>
<port>587</port>
<socketType>plain</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</outgoingServer>
<?php
break;
?>
<?php endswitch ?>
<?php endforeach ?>
</emailProvider>
<webMail>
<!-- Webpage where the user has to log in manually by entering username
and password himself.
HTTPS required. -->
<loginPage url="https://<?=$server?>/webmail" />
</webMail>
</clientConfig>
<?php
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment