Pannous

Pannous Commit Details

Date:2018-04-22 11:43:10 (2 years 7 months ago)
Author:Grégory Soutadé
Branch:master
Commit:467ede103b9457169abbee8e09caf7c3c38ea697
Parents: 20cc437e62741b62e58acfa206c1a9b78b7d2914
Message:Add subscription/unsubscription by mail + effectively remove mails from IMAP mailbox

Changes:
Mfuel/app/classes/model/lists.php (2 diffs)
Mfuel/app/tasks/pannous.php (5 diffs)

File differences

fuel/app/classes/model/lists.php
335335
336336
337337
338
339
340
341
342
343
344
345
346
347
348
349
350
338351
339352
340353
......
391404
392405
393406
394
407
395408
396409
397410
mail($user->email, $subject, $body, implode("\r\n", $target_headers));
}
public function sendUnsubscribeEmail($user)
{
$subject = "Mailing list unsubscription confirmation";
$body = "You have successfuly unsubscribe to " . $this->title . " list\n";
$target_headers = array();
array_push($target_headers, "From: " . $this->email);
array_push($target_headers, "Content-Type: text/plain");
mail($user->email, $subject, $body, implode("\r\n", $target_headers));
}
public function validateToken($user, $token)
{
return ($token === $this->generateSubscribeToken($user));
return $query->execute();
}
public function unsubscribeUser($token)
public function unsubscribeUser($user)
{
return $this->unsubscribe($this->generateSubscribeToken($user));
}
fuel/app/tasks/pannous.php
9696
9797
9898
99
99
100100
101101
102102
......
128128
129129
130130
131
131
132132
133133
134134
135
135
136136
137137
138138
......
168168
169169
170170
171
172
173
174
175
176
177
178
179
180
181
182
183
171184
172185
173186
......
199212
200213
201214
202
203
204
215
216
217
205218
206219
207220
208221
209
210
211
212
222
223
224
225
213226
214227
215228
216
217
218
229
230
231
219232
220233
221234
222235
223236
224237
225
226
238
239
240
241
242
227243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
228277
229278
230279
......
282331
283332
284333
285
334
286335
287336
288337
if (!$readers)
{
\Log::debug("No readers");
return;
return;
}
$raw_headers = imap_fetchheader($mbox, $message_number);
$structure = imap_fetchstructure($mbox, $message_number);
$body = imap_body($mbox, $message_number);
for($i=0; $i<count($headers); $i++)
for($i=0; $i<count($headers); $i++)
{
$headers[$i] = trim($headers[$i]);
}
foreach($readers as $user)
{
\Log::debug("Propagate to " . $user->email);
return null;
}
private function extract_subject($str)
{
$elements = imap_mime_header_decode($str);
$res = "";
foreach($elements as $element)
{
if ($res) $res .= " ";
$res .= $element->text;
}
return $res;
}
public function _run()
{
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);
\Log::error("Unable to extract data (" . $mail->from . ") and (" . $mail->to . ")");
\Log::error("Res (" . $from . ") and (" . $to . ")");
imap_delete ($mbox, $mail->msgno);
continue;
}
$list = \Model_Lists::query()
->where('email', $to)
->related('users')
->related('groups')
->get_one();
->where('email', $to)
->related('users')
->related('groups')
->get_one();
if (!$list)
{
\Log::debug("No list associated");
imap_delete ($mbox, $mail->msgno);
continue;
\Log::debug("No list associated");
imap_delete ($mbox, $mail->msgno);
continue;
}
$has_right = false;
$signature_ok = true;
$user = \Model_Users::query()
->where('email', $from)
->get_one();
->where('email', $from)
->get_one();
$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;
}
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;
}
switch($list->write_mode)
{
case \Model_Lists::$WRITE_WRITERS:
imap_delete ($mbox, $mail->msgno);
}
imap_close($mbox);
imap_close($mbox, CL_EXPUNGE);
}
public static function run()

Archive Download the corresponding diff file

Branches