Pannous

Pannous Commit Details

Date:2018-10-07 12:33:36 (2 years 1 month ago)
Author:Grégory Soutadé
Branch:master
Commit:61eef813e2a8c2fbb747d2edd0247dea21b56540
Parents: 2c14a3b04d31d62b2b3835f426cdfe372423a885
Message:Rewrite task core management

Changes:
Mfuel/app/classes/controller/basetemplate.php (1 diff)
Mfuel/app/classes/controller/basetemplatehybrid.php (1 diff)
Mfuel/app/tasks/pannous.php (5 diffs)

File differences

fuel/app/classes/controller/basetemplate.php
2727
2828
2929
30
30
3131
3232
3333
{
parent::before();
$this->title = "PHP ANNoucenemnt System";
$this->title = "PHP ANNouncement System";
$this->template->title = $this->title;
$this->template->header = View::forge('templates/base_header');
$this->template->content = "";
fuel/app/classes/controller/basetemplatehybrid.php
2727
2828
2929
30
30
3131
3232
3333
{
parent::before();
$this->title = "PHP ANNoucenemnt System";
$this->title = "PHP ANNouncement System";
$this->template->title = $this->title;
$this->template->header = View::forge('templates/base_header');
$this->template->content = "";
fuel/app/tasks/pannous.php
183183
184184
185185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209186
187
188
210189
211190
212191
......
214193
215194
216195
217
218
219
220
196
197
198
221199
222200
223201
......
228206
229207
230208
231
232
233
209
210
234211
235212
236213
......
244221
245222
246223
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
267243
268
269
270
271
272
273
274
275
276
277
244
245
246
247
248
249
250
251
252
278253
279254
280255
281
256
282257
283258
284
259
285260
286261
287262
288263
289
264
290265
291266
292
267
293268
294269
295270
296271
297
272
298273
299274
300275
301276
302
277
303278
304279
305
280
306281
307282
308283
......
327302
328303
329304
330
331
332
333
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
334341
335342
336343
return $res;
}
public function _run()
{
$mbox = imap_open(\Config::get('pannous.mail_server'),
\Config::get('pannous.mail_username'),
\Config::get('pannous.mail_password'));
if ($mbox == FALSE)
die("Unable to open " . \Config::get('pannous.mail_server') . " " . imap_last_error());
$mbox_status = imap_check($mbox);
if ($mbox == FALSE)
die("Unable to status mailbox " . imap_last_error());
if (!$mbox_status->Nmsgs)
{
imap_close($mbox);
return 0;
}
$mailList = imap_fetch_overview($mbox, "1:".$mbox_status->Nmsgs);
foreach ($mailList as $mail) {
private function manage_mail($mail)
{
\Log::debug("New mail for mailing " . $mail->to);
$from = $this->extract_mail($mail->from);
if (!$from || !$to)
{
\Log::error("Unable to extract data (" . $mail->from . ") and (" . $mail->to . ")");
\Log::error("Res (" . $from . ") and (" . $to . ")");
imap_delete ($mbox, $mail->msgno);
continue;
\Log::error("Unable to extract data (" . $mail->from . ") and (" . $mail->to . ")");
\Log::error("Res (" . $from . ") and (" . $to . ")");
return;
}
$list = \Model_Lists::query()
if (!$list)
{
\Log::debug("No list associated");
imap_delete ($mbox, $mail->msgno);
continue;
\Log::debug("No list associated");
return;
}
$has_right = false;
$subject = $this->extract_subject($mail->subject);
if (!strcasecmp($subject, "subscribe"))
{
if (!$user)
{
$user = Model_Users::create_user(
$from,
"", /* force password generation */
$from,
Model_Users::$ROLE_USER
);
}
/* Already reader ? */
if (!$list->isReader($user))
{
\Log::info("Mail subscribe " . $user->email . " for " . $list->email);
$list->sendConfirmationEmail($user);
$list->addReader($user);
}
imap_delete ($mbox, $mail->msgno);
continue;
}
{
if (!$user)
{
$user = \Model_Users::create_user(
$from,
"", /* force password generation */
$from,
\Model_Users::$ROLE_USER
);
}
/* Already reader ? */
if (!$list->isReader($user))
{
\Log::info("Mail subscribe " . $user->email . " for " . $list->email);
$list->sendConfirmationEmail($user);
$list->addReader($user);
}
return;
}
else if (!strcasecmp($subject, "unsubscribe"))
{
if ($user && $list->isReader($user))
{
\Log::info("Mail unsubscribe " . $user->email . " for " . $list->email);
$list->unsubscribeUser($user);
}
$list->sendUnsubscribeEmail($user);
imap_delete ($mbox, $mail->msgno);
continue;
}
{
if ($user && $list->isReader($user))
{
\Log::info("Mail unsubscribe " . $user->email . " for " . $list->email);
$list->unsubscribeUser($user);
}
$list->sendUnsubscribeEmail($user);
return;
}
switch($list->write_mode)
{
case \Model_Lists::$WRITE_WRITERS:
case \Model_Lists::$WRITE_WRITERS:
$has_right = $user && $user->valid && $list->isWriter($user);
break;
case \Model_Lists::$WRITE_SIGNED_WRITERS:
case \Model_Lists::$WRITE_SIGNED_WRITERS:
$has_right = $user && $user->valid && $list->isWriter($user);
if ($has_right)
$signature_ok = $this->checkMailSignature($mbox, $mail->msgno, $mail, $user);
break;
case \Model_Lists::$WRITE_READERS:
case \Model_Lists::$WRITE_READERS:
$has_right = $user && $user->valid && $list->isReader($user);
break;
case \Model_Lists::$WRITE_SIGNED_READERS:
case \Model_Lists::$WRITE_SIGNED_READERS:
$has_right = $user && $user->valid && $list->isReader($user);
if ($has_right)
$signature_ok = $this->checkMailSignature($mbox, $mail->msgno, $mail, $user);
break;
case \Model_Lists::$WRITE_VALID_SIGNED_USER:
case \Model_Lists::$WRITE_VALID_SIGNED_USER:
$has_right = $user && $user->valid;
if ($has_right)
$signature_ok = $this->checkMailSignature($mbox, $mail->msgno, $mail, $user);
break;
case \Model_Lists::$WRITE_VALID_USER:
case \Model_Lists::$WRITE_VALID_USER:
$has_right = $user && $user->valid;
break;
case \Model_Lists::$WRITE_EVERYONE:
case \Model_Lists::$WRITE_EVERYONE:
$has_right = true;
break;
}
}
/* No user */
else
{
\Log::debug("User " . $mail->from . " not referenced for this mailing list");
}
imap_delete ($mbox, $mail->msgno);
{
\Log::debug("User " . $mail->from . " not referenced for this mailing list");
}
}
public function _run()
{
$mbox = imap_open(\Config::get('pannous.mail_server'),
\Config::get('pannous.mail_username'),
\Config::get('pannous.mail_password'));
if ($mbox == FALSE)
die("Unable to open " . \Config::get('pannous.mail_server') . " " . imap_last_error());
$mbox_status = imap_check($mbox);
if ($mbox == FALSE)
die("Unable to status mailbox " . imap_last_error());
if (!$mbox_status->Nmsgs)
{
imap_close($mbox);
return 0;
}
$mailList = imap_fetch_overview($mbox, "1:".$mbox_status->Nmsgs);
foreach ($mailList as $mail) {
try {
$this->manage_mail($mail);
}
catch (\Exception $e) {
\Log::error($e->getMessage());
}
finally {
imap_delete ($mbox, $mail->msgno);
}
}
imap_close($mbox, CL_EXPUNGE);

Archive Download the corresponding diff file

Branches