219 |
216 |
220 |
217 |
221 def _mbox(mbox, sender, recipients, msg): |
218 def _mbox(mbox, sender, recipients, msg): |
222 '''write mails to mbox''' |
219 '''write mails to mbox''' |
223 # TODO: use python mbox library for proper locking |
220 # TODO: use python mbox library for proper locking |
224 with open(mbox, b'ab+') as fp: |
221 with open(mbox, 'ab+') as fp: |
225 # Should be time.asctime(), but Windows prints 2-characters day |
222 # Should be time.asctime(), but Windows prints 2-characters day |
226 # of month instead of one. Make them print the same thing. |
223 # of month instead of one. Make them print the same thing. |
227 date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime()) |
224 date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime()) |
228 fp.write( |
225 fp.write( |
229 b'From %s %s\n' |
226 b'From %s %s\n' |
235 |
232 |
236 def connect(ui, mbox=None): |
233 def connect(ui, mbox=None): |
237 """make a mail connection. return a function to send mail. |
234 """make a mail connection. return a function to send mail. |
238 call as sendmail(sender, list-of-recipients, msg).""" |
235 call as sendmail(sender, list-of-recipients, msg).""" |
239 if mbox: |
236 if mbox: |
240 open(mbox, b'wb').close() |
237 open(mbox, 'wb').close() |
241 return lambda s, r, m: _mbox(mbox, s, r, m) |
238 return lambda s, r, m: _mbox(mbox, s, r, m) |
242 if ui.config(b'email', b'method') == b'smtp': |
239 if ui.config(b'email', b'method') == b'smtp': |
243 return _smtp(ui) |
240 return _smtp(ui) |
244 return lambda s, r, m: _sendmail(ui, s, r, m) |
241 return lambda s, r, m: _sendmail(ui, s, r, m) |
245 |
242 |