Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94203953
PasteReplyHandler.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
Wed, Dec 4, 17:22
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Dec 6, 17:22 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22757135
Attached To
rPH Phabricator
PasteReplyHandler.php
View Options
<?php
/**
* @group paste
*/
final
class
PasteReplyHandler
extends
PhabricatorMailReplyHandler
{
public
function
validateMailReceiver
(
$mail_receiver
)
{
if
(!(
$mail_receiver
instanceof
PhabricatorPaste
))
{
throw
new
Exception
(
'Mail receiver is not a PhabricatorPaste.'
);
}
}
public
function
getPrivateReplyHandlerEmailAddress
(
PhabricatorObjectHandle
$handle
)
{
return
$this
->
getDefaultPrivateReplyHandlerEmailAddress
(
$handle
,
'P'
);
}
public
function
getPublicReplyHandlerEmailAddress
()
{
return
$this
->
getDefaultPublicReplyHandlerEmailAddress
(
'P'
);
}
public
function
getReplyHandlerInstructions
()
{
if
(
$this
->
supportsReplies
())
{
return
pht
(
'Reply to comment or !unsubscribe.'
);
}
else
{
return
null
;
}
}
protected
function
receiveEmail
(
PhabricatorMetaMTAReceivedMail
$mail
)
{
$actor
=
$this
->
getActor
();
$paste
=
$this
->
getMailReceiver
();
$body
=
$mail
->
getCleanTextBody
();
$body
=
trim
(
$body
);
$body
=
$this
->
enhanceBodyWithAttachments
(
$body
,
$mail
->
getAttachments
());
$content_source
=
PhabricatorContentSource
::
newForSource
(
PhabricatorContentSource
::
SOURCE_EMAIL
,
array
(
'id'
=>
$mail
->
getID
(),
));
$lines
=
explode
(
"
\n
"
,
trim
(
$body
));
$first_line
=
head
(
$lines
);
$xactions
=
array
();
$command
=
null
;
$matches
=
null
;
if
(
preg_match
(
'/^!(
\w
+)/'
,
$first_line
,
$matches
))
{
$lines
=
array_slice
(
$lines
,
1
);
$body
=
implode
(
"
\n
"
,
$lines
);
$body
=
trim
(
$body
);
$command
=
$matches
[
1
];
}
switch
(
$command
)
{
case
'unsubscribe'
:
$xaction
=
id
(
new
PhabricatorPasteTransaction
())
->
setTransactionType
(
PhabricatorTransactions
::
TYPE_SUBSCRIBERS
)
->
setNewValue
(
array
(
'-'
=>
array
(
$actor
->
getPHID
())));
$xactions
[]
=
$xaction
;
break
;
}
$xactions
[]
=
id
(
new
PhabricatorPasteTransaction
())
->
setTransactionType
(
PhabricatorTransactions
::
TYPE_COMMENT
)
->
attachComment
(
id
(
new
PhabricatorPasteTransactionComment
())
->
setContent
(
$body
));
$editor
=
id
(
new
PhabricatorPasteEditor
())
->
setActor
(
$actor
)
->
setContentSource
(
$content_source
)
->
setContinueOnNoEffect
(
true
)
->
setIsPreview
(
false
);
try
{
$xactions
=
$editor
->
applyTransactions
(
$paste
,
$xactions
);
}
catch
(
PhabricatorApplicationTransactionNoEffectException
$ex
)
{
// just do nothing, though unclear why you're sending a blank email
return
true
;
}
$head_xaction
=
head
(
$xactions
);
return
$head_xaction
->
getID
();
}
}
Event Timeline
Log In to Comment