Skip to content

Commit ce30255

Browse files
committed
handle_mail: Look up the Pony ID from the RT ID if needed
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent d24e9df commit ce30255

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

handle_mail.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,26 @@ def handle_mail():
3131
toname, to = parseaddr(unicode(make_header(decode_header(message["delivered-to"]))))
3232
m = ID_PATTERN.search(to)
3333
if m is None:
34-
return
35-
id = int(m.group(1))
34+
t = None
35+
else:
36+
t = queue.Ticket.get(int(m.group(1)))
3637

3738
byname, by = parseaddr(unicode(make_header(decode_header(message["from"]))))
3839
by = by.lower()
3940
if by.endswith(u"@mit.edu"):
4041
by = by[: -len(u"@mit.edu")]
4142

42-
t = queue.Ticket.get(id)
43-
4443
RTID_PATTERN = re.compile(r"\[help.mit.edu\s+\#(\d+)\]")
4544
subject = unicode(make_header(decode_header(message["subject"])))
4645
m = RTID_PATTERN.search(subject)
4746
if m:
48-
if t.rtid is None:
49-
by = u"rt"
50-
t.rtid = int(m.group(1))
47+
rtid = int(m.group(1))
48+
if t is None:
49+
t = queue.Ticket.query.filter_by(rtid=rtid).one()
50+
else:
51+
if t.rtid is None:
52+
by = u"rt"
53+
t.rtid = rtid
5154

5255
newstate = t.state
5356
# TODO: blanche accounts-internal

scriptspony/model/queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Ticket(DeclarativeBase):
2626
path = Column(Unicode(255))
2727
# "open" or "moira" or "dns" or "resolved"
2828
state = Column(Unicode(32))
29-
rtid = Column(Integer)
29+
rtid = Column(Integer, index=True, unique=True)
3030
# Purpose
3131
purpose = Column(UnicodeText())
3232

0 commit comments

Comments
 (0)