Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97582927
PhabricatorMailImplementationPostmarkAdapter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 5, 11:18
Size
2 KB
Mime Type
text/x-php
Expires
Tue, Jan 7, 11:18 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23430855
Attached To
rPH Phabricator
PhabricatorMailImplementationPostmarkAdapter.php
View Options
<?php
final
class
PhabricatorMailImplementationPostmarkAdapter
extends
PhabricatorMailImplementationAdapter
{
const
ADAPTERTYPE
=
'postmark'
;
private
$parameters
=
array
();
public
function
setFrom
(
$email
,
$name
=
''
)
{
$this
->
parameters
[
'From'
]
=
$this
->
renderAddress
(
$email
,
$name
);
return
$this
;
}
public
function
addReplyTo
(
$email
,
$name
=
''
)
{
$this
->
parameters
[
'ReplyTo'
]
=
$this
->
renderAddress
(
$email
,
$name
);
return
$this
;
}
public
function
addTos
(
array
$emails
)
{
foreach
(
$emails
as
$email
)
{
$this
->
parameters
[
'To'
][]
=
$email
;
}
return
$this
;
}
public
function
addCCs
(
array
$emails
)
{
foreach
(
$emails
as
$email
)
{
$this
->
parameters
[
'Cc'
][]
=
$email
;
}
return
$this
;
}
public
function
addAttachment
(
$data
,
$filename
,
$mimetype
)
{
$this
->
parameters
[
'Attachments'
][]
=
array
(
'Name'
=>
$filename
,
'ContentType'
=>
$mimetype
,
'Content'
=>
base64_encode
(
$data
),
);
return
$this
;
}
public
function
addHeader
(
$header_name
,
$header_value
)
{
$this
->
parameters
[
'Headers'
][]
=
array
(
'Name'
=>
$header_name
,
'Value'
=>
$header_value
,
);
return
$this
;
}
public
function
setBody
(
$body
)
{
$this
->
parameters
[
'TextBody'
]
=
$body
;
return
$this
;
}
public
function
setHTMLBody
(
$html_body
)
{
$this
->
parameters
[
'HtmlBody'
]
=
$html_body
;
return
$this
;
}
public
function
setSubject
(
$subject
)
{
$this
->
parameters
[
'Subject'
]
=
$subject
;
return
$this
;
}
public
function
supportsMessageIDHeader
()
{
return
true
;
}
protected
function
validateOptions
(
array
$options
)
{
PhutilTypeSpec
::
checkMap
(
$options
,
array
(
'access-token'
=>
'string'
,
'inbound-addresses'
=>
'list<string>'
,
));
// Make sure this is properly formatted.
PhutilCIDRList
::
newList
(
$options
[
'inbound-addresses'
]);
}
public
function
newDefaultOptions
()
{
return
array
(
'access-token'
=>
null
,
'inbound-addresses'
=>
array
(
// Via Postmark support circa February 2018, see:
//
// https://postmarkapp.com/support/article/800-ips-for-firewalls
//
// "Configuring Outbound Email" should be updated if this changes.
'50.31.156.6/32'
,
),
);
}
public
function
newLegacyOptions
()
{
return
array
();
}
public
function
send
()
{
$access_token
=
$this
->
getOption
(
'access-token'
);
$parameters
=
$this
->
parameters
;
$flatten
=
array
(
'To'
,
'Cc'
,
);
foreach
(
$flatten
as
$key
)
{
if
(
isset
(
$parameters
[
$key
]))
{
$parameters
[
$key
]
=
implode
(
', '
,
$parameters
[
$key
]);
}
}
id
(
new
PhutilPostmarkFuture
())
->
setAccessToken
(
$access_token
)
->
setMethod
(
'email'
,
$parameters
)
->
resolve
();
return
true
;
}
}
Event Timeline
Log In to Comment