mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 04:26:02 +03:00
Ability to rename attachments and inline images.
This commit is contained in:
parent
535b063de3
commit
af53fd50ff
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
## 1.6 (2014-1-13)
|
||||||
|
|
||||||
|
Enhancement:
|
||||||
|
- adjust file attachment/inline name (#21 @travelton)
|
||||||
|
|
||||||
|
## 1.5 (2013-12-13)
|
||||||
|
|
||||||
|
Enhancement:
|
||||||
|
- added ability to define non-https endpoint for debugging purposes (#23 @travelton)
|
||||||
|
|
||||||
## 1.4 (2013-10-16)
|
## 1.4 (2013-10-16)
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
@ -22,7 +22,7 @@ composer and the Mailgun SDK.
|
|||||||
curl -sS https://getcomposer.org/installer | php
|
curl -sS https://getcomposer.org/installer | php
|
||||||
|
|
||||||
# Add Mailgun as a dependency
|
# Add Mailgun as a dependency
|
||||||
php composer.phar require mailgun/mailgun-php:~1.5
|
php composer.phar require mailgun/mailgun-php:~1.6
|
||||||
```
|
```
|
||||||
|
|
||||||
**For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).**
|
**For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).**
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "mailgun/mailgun-php",
|
"name": "mailgun/mailgun-php",
|
||||||
"description": "The Mailgun SDK provides methods for all API functions.",
|
"description": "The Mailgun SDK provides methods for all API functions.",
|
||||||
"require": {
|
"require": {
|
||||||
"guzzle/guzzle": "3.7.*"
|
"guzzle/guzzle": "3.8.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "3.7.*"
|
"phpunit/phpunit": "3.7.*"
|
||||||
|
@ -39,12 +39,28 @@ class RestClient{
|
|||||||
}
|
}
|
||||||
if(isset($files["attachment"])){
|
if(isset($files["attachment"])){
|
||||||
foreach($files["attachment"] as $attachment){
|
foreach($files["attachment"] as $attachment){
|
||||||
$request->addPostFile("attachment", $attachment);
|
// Backward compatibility code
|
||||||
|
if (is_array($attachment)){
|
||||||
|
$request->addPostFile("attachment",
|
||||||
|
$attachment['filePath'], null,
|
||||||
|
$attachment['remoteName']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$request->addPostFile("attachment", $attachment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isset($files["inline"])){
|
if(isset($files["inline"])){
|
||||||
foreach($files["inline"] as $attachment){
|
foreach($files["inline"] as $inline){
|
||||||
$request->addPostFile("inline", $attachment);
|
// Backward compatibility code
|
||||||
|
if (is_array($inline)){
|
||||||
|
$request->addPostFile("inline",
|
||||||
|
$inline['filePath'], null,
|
||||||
|
$inline['remoteName']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$request->addPostFile("inline", $inline);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,13 +136,16 @@ class MessageBuilder{
|
|||||||
return $this->message['html'];
|
return $this->message['html'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAttachment($attachmentPath){
|
public function addAttachment($attachmentPath, $attachmentName = null){
|
||||||
if(preg_match("/^@/", $attachmentPath)){
|
if(preg_match("/^@/", $attachmentPath)){
|
||||||
if(isset($this->files["attachment"])){
|
if(isset($this->files["attachment"])){
|
||||||
array_push($this->files["attachment"], $attachmentPath);
|
$attachment = array('filePath' => $attachmentPath,
|
||||||
|
'remoteName' => $attachmentName);
|
||||||
|
array_push($this->files["attachment"], $attachment);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->files["attachment"] = array($attachmentPath);
|
$this->files["attachment"] = array(array('filePath' => $attachmentPath,
|
||||||
|
'remoteName' => $attachmentName));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -151,16 +154,18 @@ class MessageBuilder{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addInlineImage($inlineImagePath){
|
public function addInlineImage($inlineImagePath, $inlineImageName = null){
|
||||||
if(preg_match("/^@/", $inlineImagePath)){
|
if(preg_match("/^@/", $inlineImagePath)){
|
||||||
if(isset($this->files['inline'])){
|
if(isset($this->files['inline'])){
|
||||||
array_push($this->files['inline'] , $inlineImagePath);
|
$inlineAttachment = array('filePath' => $inlineImagePath,
|
||||||
return true;
|
'remoteName' => $inlineImageName);
|
||||||
|
array_push($this->files['inline'] , $inlineAttachment);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->files['inline'] = array($inlineImagePath);
|
$this->files['inline'] = array(array('filePath' => $inlineImagePath,
|
||||||
return true;
|
'remoteName' => $inlineImageName));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw new InvalidParameter(INVALID_PARAMETER_INLINE);
|
throw new InvalidParameter(INVALID_PARAMETER_INLINE);
|
||||||
|
@ -117,14 +117,40 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{
|
|||||||
$message->addAttachment("@../TestAssets/mailgun_icon.png");
|
$message->addAttachment("@../TestAssets/mailgun_icon.png");
|
||||||
$message->addAttachment("@../TestAssets/rackspace_logo.png");
|
$message->addAttachment("@../TestAssets/rackspace_logo.png");
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
|
$this->assertEquals(array(array('filePath' => "@../TestAssets/mailgun_icon.png",
|
||||||
|
'remoteName' => null),
|
||||||
|
array('filePath' => "@../TestAssets/rackspace_logo.png",
|
||||||
|
'remoteName' => null)), $messageObj["attachment"]);
|
||||||
}
|
}
|
||||||
public function testAddInlineImages(){
|
public function testAddInlineImages(){
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
|
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
|
||||||
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
|
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
|
$this->assertEquals(array(array('filePath' => "@../TestAssets/mailgun_icon.png",
|
||||||
|
'remoteName' => null),
|
||||||
|
array('filePath' => "@../TestAssets/rackspace_logo.png",
|
||||||
|
'remoteName' => null)), $messageObj['inline']);
|
||||||
|
}
|
||||||
|
public function testAddAttachmentsPostName(){
|
||||||
|
$message = $this->client->MessageBuilder();
|
||||||
|
$message->addAttachment('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
|
||||||
|
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
||||||
|
$messageObj = $message->getFiles();
|
||||||
|
$this->assertEquals(array(array('filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
|
'remoteName' => 'mg_icon.png'),
|
||||||
|
array('filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
|
'remoteName' => 'rs_logo.png')), $messageObj["attachment"]);
|
||||||
|
}
|
||||||
|
public function testAddInlineImagePostName(){
|
||||||
|
$message = $this->client->MessageBuilder();
|
||||||
|
$message->addInlineImage('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
|
||||||
|
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
||||||
|
$messageObj = $message->getFiles();
|
||||||
|
$this->assertEquals(array(array('filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
|
'remoteName' => 'mg_icon.png'),
|
||||||
|
array('filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
|
'remoteName' => 'rs_logo.png')), $messageObj['inline']);
|
||||||
}
|
}
|
||||||
public function testsetTestMode(){
|
public function testsetTestMode(){
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
|
Loading…
Reference in New Issue
Block a user