Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101309874
PonderMail.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
Fri, Feb 7, 16:16
Size
3 KB
Mime Type
text/x-php
Expires
Sun, Feb 9, 16:16 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
24131419
Attached To
rPH Phabricator
PonderMail.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract
class
PonderMail
{
protected
$to
=
array
();
protected
$actorHandle
;
protected
$question
;
protected
$target
;
protected
$isFirstMailAboutQuestion
;
// protected $replyHandler;
protected
$parentMessageID
;
protected
function
renderSubject
()
{
$question
=
$this
->
getQuestion
();
$title
=
$question
->
getTitle
();
$id
=
$question
->
getID
();
return
"Q{$id}: {$title}"
;
}
abstract
protected
function
renderVaryPrefix
();
abstract
protected
function
renderBody
();
public
function
setActorHandle
(
$actor_handle
)
{
$this
->
actorHandle
=
$actor_handle
;
return
$this
;
}
public
function
getActorHandle
()
{
return
$this
->
actorHandle
;
}
protected
function
getActorName
()
{
return
$this
->
actorHandle
->
getRealName
();
}
protected
function
getSubjectPrefix
()
{
return
"[Ponder]"
;
}
public
function
setToPHIDs
(
array
$to
)
{
$this
->
to
=
$to
;
return
$this
;
}
protected
function
getToPHIDs
()
{
return
$this
->
to
;
}
public
function
setQuestion
(
$question
)
{
$this
->
question
=
$question
;
return
$this
;
}
public
function
getQuestion
()
{
return
$this
->
question
;
}
public
function
setTarget
(
$target
)
{
$this
->
target
=
$target
;
return
$this
;
}
public
function
getTarget
()
{
return
$this
->
target
;
}
protected
function
getThreadID
()
{
$phid
=
$this
->
getQuestion
()->
getPHID
();
return
"ponder-ques-{$phid}"
;
}
protected
function
getThreadTopic
()
{
$id
=
$this
->
getQuestion
()->
getID
();
$title
=
$this
->
getQuestion
()->
getTitle
();
return
"Q{$id}: {$title}"
;
}
public
function
send
()
{
$email_to
=
array_filter
(
array_unique
(
$this
->
to
));
$question
=
$this
->
getQuestion
();
$target
=
$this
->
getTarget
();
$uri
=
PhabricatorEnv
::
getURI
(
'/Q'
.
$question
->
getID
());
$thread_id
=
$this
->
getThreadID
();
$handles
=
id
(
new
PhabricatorObjectHandleData
(
$email_to
))
->
loadHandles
();
$reply_handler
=
new
PonderReplyHandler
();
$reply_handler
->
setMailReceiver
(
$question
);
$body
=
new
PhabricatorMetaMTAMailBody
();
$body
->
addRawSection
(
$this
->
renderBody
());
$body
->
addTextSection
(
pht
(
'QUESTION DETAIL'
),
$uri
);
$template
=
id
(
new
PhabricatorMetaMTAMail
())
->
setSubject
(
$this
->
getThreadTopic
())
->
setSubjectPrefix
(
$this
->
getSubjectPrefix
())
->
setVarySubjectPrefix
(
$this
->
renderVaryPrefix
())
->
setFrom
(
$target
->
getAuthorPHID
())
->
setParentMessageID
(
$this
->
parentMessageID
)
->
addHeader
(
'Thread-Topic'
,
$this
->
getThreadTopic
())
->
setThreadID
(
$this
->
getThreadID
(),
false
)
->
setRelatedPHID
(
$question
->
getPHID
())
->
setIsBulk
(
true
)
->
setBody
(
$body
->
render
());
$mails
=
$reply_handler
->
multiplexMail
(
$template
,
array_select_keys
(
$handles
,
$email_to
),
array
());
foreach
(
$mails
as
$mail
)
{
$mail
->
saveAndSend
();
}
}
protected
function
formatText
(
$text
)
{
$text
=
explode
(
"
\n
"
,
rtrim
(
$text
));
foreach
(
$text
as
&
$line
)
{
$line
=
rtrim
(
' '
.
$line
);
}
unset
(
$line
);
return
implode
(
"
\n
"
,
$text
);
}
}
Event Timeline
Log In to Comment