1
|
|
|
<?php
|
|
|
|
|
2
|
|
|
/**
|
3
|
|
|
* Sends e-mails from queue
|
4
|
|
|
*
|
5
|
|
|
* Important:
|
6
|
|
|
* Dreamhost only allows 150 mails pr. hour to be sent
|
7
|
|
|
*
|
8
|
|
|
* @author Lars Olesen <[email protected]>
|
9
|
|
|
*/
|
10
|
|
|
|
11
|
|
|
require_once 'common.php';
|
12
|
|
|
require_once 'Intraface/Mail.php';
|
13
|
|
|
require_once 'swift_required.php';
|
14
|
|
|
|
15
|
|
|
$bucket = new bucket_Container(new Intraface_Factory());
|
16
|
|
|
|
17
|
|
|
$db = $bucket->get('mdb2');
|
18
|
|
|
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
|
19
|
|
|
$result = $db->query("SELECT DISTINCT(public_key), name FROM intranet INNER JOIN email ON intranet.id = email.intranet_id WHERE email.status = 2");
|
20
|
|
|
|
21
|
|
|
$mailer = $bucket->get('swift_mailer');
|
22
|
|
|
|
23
|
|
|
while ($row = $result->fetchRow()) {
|
|
|
|
|
24
|
|
|
|
25
|
|
|
echo "Sending for intranet ".$row['name'].": ";
|
26
|
|
|
|
27
|
|
|
$auth_adapter = new Intraface_Auth_PublicKeyLogin($db, md5(uniqid()), $row['public_key']);
|
28
|
|
|
$weblogin = $auth_adapter->auth();
|
29
|
|
|
|
30
|
|
|
if (!$weblogin) {
|
31
|
|
|
throw new Exception('Access to the intranet denied. The private key is probably wrong.');
|
32
|
|
|
}
|
33
|
|
|
|
34
|
|
|
$kernel = new Intraface_Kernel();
|
35
|
|
|
$kernel->intranet = new Intraface_Intranet($weblogin->getActiveIntranetId());
|
36
|
|
|
$kernel->setting = new Intraface_Setting($kernel->intranet->get('id'));
|
37
|
|
|
|
38
|
|
|
$kernel->useShared('email');
|
39
|
|
|
|
40
|
|
|
if (!$kernel->intranet->hasModuleAccess('contact')) {
|
41
|
|
|
continue;
|
42
|
|
|
}
|
43
|
|
|
|
44
|
|
|
$gateway = new Intraface_shared_email_EmailGateway($kernel);
|
45
|
|
|
$mails = $gateway->getEmailsToSend();
|
46
|
|
|
|
47
|
|
|
echo count($mails);
|
48
|
|
|
|
49
|
|
|
foreach ($gateway->getEmailsToSend() as $email) {
|
50
|
|
|
$to = $email->getTo();
|
51
|
|
|
if ($to == false) {
|
52
|
|
|
echo "Mail: ".$email->getSubject()." to ".$email->getTo()." has invalid to address\n";
|
53
|
|
|
continue;
|
54
|
|
|
}
|
55
|
|
|
|
56
|
|
|
$message = $bucket->get('swift_message');
|
57
|
|
|
$message
|
58
|
|
|
->setSubject($email->getSubject())
|
59
|
|
|
->setFrom($email->getFrom())
|
60
|
|
|
->setTo($to)
|
61
|
|
|
->setBody($email->getBody());
|
62
|
|
|
|
63
|
|
|
$attachments = $email->getAttachments();
|
64
|
|
|
if (is_array($attachments) AND count($attachments) > 0) {
|
|
|
|
|
65
|
|
|
$kernel->useModule('filemanager', true);
|
66
|
|
|
foreach ($attachments AS $file) {
|
|
|
|
|
67
|
|
|
$filehandler = new FileHandler($kernel, $file['id']);
|
68
|
|
|
|
69
|
|
|
// lille hack med at s�tte uploadpath p�
|
70
|
|
|
$attachment = Swift_Attachment::fromPath($filehandler->getUploadPath() . $filehandler->get('server_file_name'), $filehandler->get('file_type'))->setFilename($file['filename']);
|
71
|
|
|
$message->attach($attachment);
|
72
|
|
|
}
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
if ($mailer->send($message)) {
|
76
|
|
|
$email->setIsSent();
|
77
|
|
|
}
|
78
|
|
|
}
|
79
|
|
|
|
80
|
|
|
echo "\n";
|
81
|
|
|
}
|
82
|
|
|
|
83
|
|
|
$logger = new ErrorHandler_Observer_File(ERROR_LOG);
|
84
|
|
|
$logger->update(array(
|
85
|
|
|
'date' => date('r'),
|
86
|
|
|
'type' => 'CronJob',
|
87
|
|
|
'message' => 'Cronjob run successfully!',
|
88
|
|
|
'file' => __FILE__,
|
89
|
|
|
'line' => __LINE__)); |