##// END OF EJS Templates
mail: add parseaddrlist() function for parsing many addresses at once...
Marti Raudsepp -
r9948:e5b44a79 default
parent child Browse files
Show More
@@ -160,11 +160,7 b' def headencode(ui, s, charsets=None, dis'
160 return str(email.Header.Header(s, cs))
160 return str(email.Header.Header(s, cs))
161 return s
161 return s
162
162
163 def addressencode(ui, address, charsets=None, display=False):
163 def _addressencode(ui, name, addr, charsets=None):
164 '''Turns address into RFC-2047 compliant header.'''
165 if display or not address:
166 return address or ''
167 name, addr = email.Utils.parseaddr(address)
168 name = headencode(ui, name, charsets)
164 name = headencode(ui, name, charsets)
169 try:
165 try:
170 acc, dom = addr.split('@')
166 acc, dom = addr.split('@')
@@ -181,6 +177,26 b' def addressencode(ui, address, charsets='
181 raise util.Abort(_('invalid local address: %s') % addr)
177 raise util.Abort(_('invalid local address: %s') % addr)
182 return email.Utils.formataddr((name, addr))
178 return email.Utils.formataddr((name, addr))
183
179
180 def addressencode(ui, address, charsets=None, display=False):
181 '''Turns address into RFC-2047 compliant header.'''
182 if display or not address:
183 return address or ''
184 name, addr = email.Utils.parseaddr(address)
185 return _addressencode(ui, name, addr, charsets)
186
187 def addrlistencode(ui, addrs, charsets=None, display=False):
188 '''Turns a list of addresses into a list of RFC-2047 compliant headers.
189 A single element of input list may contain multiple addresses, but output
190 always has one address per item'''
191 if display:
192 return [a.strip() for a in addrs if a.strip()]
193
194 result = []
195 for name, addr in email.Utils.getaddresses(addrs):
196 if name or addr:
197 result.append(_addressencode(ui, name, addr, charsets))
198 return result
199
184 def mimeencode(ui, s, charsets=None, display=False):
200 def mimeencode(ui, s, charsets=None, display=False):
185 '''creates mime text object, encodes it if needed, and sets
201 '''creates mime text object, encodes it if needed, and sets
186 charset and transfer-encoding accordingly.'''
202 charset and transfer-encoding accordingly.'''
General Comments 0
You need to be logged in to leave comments. Login now