[PLUGINS] +set de base
[lhc/web/www.git] / www / plugins / abomailmans / inc / abomailmans.php
1 <?php
2
3 /*
4 * Abomailmans
5 * MaZiaR - NetAktiv
6 * tech@netaktiv.com
7 * Printemps 2007 - 2012
8 * Inspire de Spip-Listes
9 * $Id: abomailmans.php 59911 2012-03-29 10:00:37Z root $
10 */
11
12 if (!defined("_ECRIRE_INC_VERSION")) return;
13
14 // a utiliser dans le form de son choix ...
15 function abomailman_traiter_abonnement($id_liste,$abonnement){
16 $liste_data = sql_fetsel("*","spip_abomailmans","id_abomailman = $id_liste");
17 $sujet=null;
18 $dowhat=null;
19 $titre=$liste_data['titre'];
20 //Si on a les 2 emails
21 if($liste_data['email_subscribe'] AND $liste_data['email_unsubscribe']){
22 spip_log("Liste defini par mails","abomailmans");
23 $liste_email = !empty($abonnement)?$liste_data['email_subscribe']:$liste_data['email_unsubscribe'];
24 }else{
25 //sinon comme avant
26 // 1er cas : c'est une liste MAILMAN ? join et leave etrange !!!
27 //ne serait-ce pas plutot subscribe et unsubscribe ?
28 if($liste_data['email_sympa'] == '') {
29 spip_log("Liste -join ou -leave","abomailmans");
30 $liste_email = explode ("@", $liste_data['email']);
31 // abonnement ou desabonement : on rajoute -join ou -leave dans l'email de la liste
32 $dowhat = !empty($abonnement)?"-join@":"-leave@";
33 $liste_email = $liste_email[0]."$dowhat".$liste_email[1];
34 }
35 // 2eme cas : c'est une liste SYMPA (presence de deux @ à suivre)
36 else {
37 spip_log("Liste sympa","abomailmans");
38 $proprio_email = $liste_data['email_sympa'];
39 $sujet = empty($abonnement)? 'UNSUBSCRIBE ' : 'SUBSCRIBE ';
40 $sujet .= $liste_data['email'].' ';
41 $sujet .= empty($desabonnement) ? $nom : '';
42 $liste_email = $liste_data['titre'];
43 }
44 }
45 $sujet=isset($sujet)?$sujet:$liste_email;
46 $quoifait=!empty($abonnement)?_T("abomailmans:veut_s_abonner"):_T("abomailmans:veut_se_desabonner");
47 $body="$quoifait"."\n ".$titre."(".$liste_data['email'].") \n "._T("abomailmans:envoi_vers")." $liste_email";
48
49
50 return array($titre,$proprio_email,$liste_email, $sujet, $body,$headers);
51 }
52
53
54 //* Envoi de mail via facteur
55 function abomailman_mail($nom, $email, $to_email,$liste_email, $sujet="", $body="", $html="", $headers="") {
56 // si $to_mail est plein, c'est Sympa, s'il est vide c'est Mailman et il faut alors utiliser $liste_email
57 if (!$to_email)
58 $to_email = $liste_email;
59
60 // Pas beau mais faudrait reprendre le code plus en profondeur
61 // et rajouter une liste de choix du robot en page de config
62 // Modifier le destinataire d’envoi dans le cas ezmlm pour que
63 // les inscriptions fonctionnent si facteur utilise l’envoi via
64 // la fonction mail() de php. En effet dans ce cas, le header return-path
65 // n’est pas renseigné. Or c’est ce header qui est utilisé par le robot
66 // pour répondre et non le champ from... Il faut modifier le destinataire
67 // comme ceci maliste-subscribe-lemail=ledomaine.tld@monsite.tld
68 if (defined('_ABOMAILMAN_ROBOT_EZMLM') && preg_match("/subscribe/",$to_email)) {
69 $souscripteur = str_replace("@" , "=" , $email ) ;
70 $to_email = str_replace("@" , "-".$souscripteur."@" , $to_email ) ;
71 }
72
73 $envoyer_mail = charger_fonction('envoyer_mail','inc/');
74 if($envoyer_mail($to_email, $sujet, $body, $email, $headers))
75 $retour=true;
76 else
77 $retour=false;
78
79 spip_log("abomailman_mail nom $nom, email $email, to_email $to_email, liste_email $liste_email, sujet $sujet, body $body, html $html, headers $headers, retour envoyer_mail : $retour","abomailmans");
80 return $retour ;
81 }
82
83
84 ?>