1: <?php
2: /**
3: * Announce releases on the mailing lists.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Release
9: * @author Mike Hardy
10: * @author Jan Schneider <jan@horde.org>
11: * @author Gunnar Wrobel <wrobel@pardus.de>
12: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
13: * @link http://www.horde.org/libraries/Horde_Release
14: */
15:
16: /**
17: * Announce releases on the mailing lists.
18: *
19: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Horde
25: * @package Release
26: * @author Mike Hardy
27: * @author Jan Schneider <jan@horde.org>
28: * @author Gunnar Wrobel <wrobel@pardus.de>
29: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
30: * @link http://www.horde.org/libraries/Horde_Release
31: */
32: class Horde_Release_MailingList
33: {
34: /**
35: * Component name.
36: *
37: * @param string
38: */
39: private $_component;
40:
41: /**
42: * Component release name.
43: *
44: * @param string
45: */
46: private $_name;
47:
48: /**
49: * Branch name.
50: *
51: * @param string
52: */
53: private $_branch;
54:
55: /**
56: * Message sender.
57: *
58: * @param string
59: */
60: private $_from;
61:
62: /**
63: * The mailing list to send to.
64: *
65: * @param string
66: */
67: private $_list;
68:
69: /**
70: * The version to be released.
71: *
72: * @param string
73: */
74: private $_version;
75:
76: /**
77: * The list of focus tags.
78: *
79: * @param array
80: */
81: private $_tag_list;
82:
83: /**
84: * The message body.
85: *
86: * @param string
87: */
88: private $_body;
89:
90: /**
91: * Constructor.
92: *
93: * @param string $component The component name.
94: * @param string $name The component release name.
95: * @param string $branch The component branch (H3, H4, ...).
96: * @param string $from The mail address of the person sending the
97: * announcement.
98: * @param string $list The mailing list the announcement should be
99: * sent to.
100: * @param string $version The version to be released.
101: * @param array $tag_list Release focus.
102: */
103: public function __construct(
104: $component, $name, $branch, $from, $list, $version, $tag_list
105: )
106: {
107: $this->_component = $component;
108: $this->_name = $name;
109: $this->_branch = $branch;
110: $this->_from = $from;
111: $this->_list = $list;
112: $this->_version = $version;
113: $this->_tag_list = $tag_list;
114: $this->_body = '';
115: }
116:
117: /**
118: * Retrieve the message headers for the announcement mail.
119: *
120: * @return array A set of message headers.
121: */
122: public function getHeaders()
123: {
124: $ml = (!empty($this->_list)) ? $this->_list : $this->_component;
125: if (substr($ml, 0, 6) == 'horde-') {
126: $ml = 'horde';
127: }
128:
129: $to = "announce@lists.horde.org, vendor@lists.horde.org, $ml@lists.horde.org";
130: if (!$this->_isLatest()) {
131: $to .= ', i18n@lists.horde.org';
132: }
133:
134: $subject = $this->_name;
135: if (!empty($this->_branch)) {
136: $subject .= ' ' . $this->_branch . ' (' . $this->_version . ')';
137: } else {
138: $subject .= ' ' . $this->_version;
139: }
140: if ($this->_isLatest()) {
141: $subject .= ' (final)';
142: }
143: if (in_array(Horde_Release::FOCUS_MAJORSECURITY, $this->_tag_list)) {
144: $subject = '[SECURITY] ' . $subject;
145: }
146:
147: return array(
148: 'From' => $this->_from,
149: 'To' => $to,
150: 'Subject' => $subject
151: );
152: }
153:
154: /**
155: * Append text to the message body.
156: *
157: * @param string $text The text to be appended.
158: *
159: * @return NULL
160: */
161: public function append($text)
162: {
163: $this->_body .= $text;
164: }
165:
166: /**
167: * Return the complete message body.
168: *
169: * @return string The message body.
170: */
171: public function getBody()
172: {
173: return $this->_body;
174: }
175:
176: /**
177: * Return the Horde_Mime_Mail message.
178: *
179: * @return Horde_Mime_Mail The message.
180: */
181: public function getMail()
182: {
183: return new Horde_Mime_Mail(
184: array_merge($this->getHeaders(), array('body' => $this->getBody()))
185: );
186: }
187:
188: /**
189: * Check if this is a final release.
190: *
191: * @return boolean True if this is no prerelease version.
192: */
193: private function _isLatest()
194: {
195: if (preg_match('/([.\d]+)\-(.*)/', $this->_version, $matches)
196: && !preg_match('/^pl\d/', $matches[2])) {
197: return false;
198: }
199: return true;
200: }
201: }