Merge lp:~jonas-drange/account-polld/gmail-missing-notifications into lp:~ubuntu-push-hackers/account-polld/trunk

Proposed by Jonas G. Drange
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 159
Merged at revision: 149
Proposed branch: lp:~jonas-drange/account-polld/gmail-missing-notifications
Merge into: lp:~ubuntu-push-hackers/account-polld/trunk
Diff against target: 175 lines (+58/-54)
2 files modified
cmd/account-polld/main.go (+15/-42)
plugins/gmail/gmail.go (+43/-12)
To merge this branch: bzr merge lp:~jonas-drange/account-polld/gmail-missing-notifications
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+280711@code.launchpad.net

Commit message

- Force parsing of email address even if it violates RFC 5322.
- Encode icon file paths since unity-notifications require it.
- Summarize notification bubbles when > 10 in a batch, but never summarize in the indicator.

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

Given the level of insanity of this codepath, this does not seem worse than what we have :-)

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

tested, works well!

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :

My 'approve' stands.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/account-polld/main.go'
2--- cmd/account-polld/main.go 2015-11-03 13:40:45 +0000
3+++ cmd/account-polld/main.go 2015-12-21 11:51:14 +0000
4@@ -44,8 +44,8 @@
5 const (
6 SERVICETYPE_WEBAPPS = "webapps"
7
8- SERVICENAME_GMAIL = "com.ubuntu.developer.webapps.webapp-gmail_webapp-gmail"
9- SERVICENAME_TWITTER = "com.ubuntu.developer.webapps.webapp-twitter_webapp-twitter"
10+ SERVICENAME_GMAIL = "com.ubuntu.developer.webapps.webapp-gmail_webapp-gmail"
11+ SERVICENAME_TWITTER = "com.ubuntu.developer.webapps.webapp-twitter_webapp-twitter"
12 )
13
14 const (
15@@ -169,50 +169,23 @@
16 func postOffice(bus *dbus.Connection, postWatch chan *PostWatch) {
17 for post := range postWatch {
18 obj := bus.Object(POSTAL_SERVICE, pushObjectPath(post.appId))
19- pers, err := obj.Call(POSTAL_INTERFACE, "ListPersistent", post.appId)
20- if err != nil {
21- log.Println("Could not list previous messages:", err)
22- continue
23- }
24- var tags []string
25- tagmap := make(map[string]int)
26- if err := pers.Args(&tags); err != nil {
27- log.Println("Could not get tags:", err)
28- continue
29- }
30- log.Printf("Previous messages: %#v\n", tags)
31- for _, tag := range tags {
32- tagmap[tag]++
33- }
34
35 for _, batch := range post.batches {
36- // add individual notifications upto the batch limit
37- // (minus currently presented notifications). If
38- // overflowed and no overflow present, present that.
39- var notifs []*plugins.PushMessage
40- add := batch.Limit - tagmap[batch.Tag]
41- if add > 0 {
42- // there are less notifications presented than
43- // the limit; we can show some
44- if len(batch.Messages) < add {
45- notifs = batch.Messages
46- } else {
47- notifs = batch.Messages[:add]
48- }
49- }
50+
51+ notifs := batch.Messages
52+ overflowing := len(notifs) > batch.Limit
53+
54 for _, n := range notifs {
55- n.Notification.Tag = batch.Tag
56+ // We're overflowing, so no popups.
57+ // See LP: #1527171
58+ if overflowing {
59+ n.Notification.Card.Popup = false
60+ }
61 }
62- ofTag := batch.Tag + "-overflow"
63- if len(notifs) < len(batch.Messages) {
64- // overflow
65- n := batch.OverflowHandler(batch.Messages[len(notifs):])
66- n.Notification.Tag = ofTag
67- if tagmap[ofTag] != 0 {
68- // sneakily, don't replace the overflow card,
69- // but do play the sound & etc
70- n.Notification.Card = nil
71- }
72+
73+ if overflowing {
74+ n := batch.OverflowHandler(notifs)
75+ n.Notification.Card.Persist = false
76 notifs = append(notifs, n)
77 }
78
79
80=== modified file 'plugins/gmail/gmail.go'
81--- plugins/gmail/gmail.go 2015-03-27 11:40:37 +0000
82+++ plugins/gmail/gmail.go 2015-12-21 11:51:14 +0000
83@@ -23,7 +23,9 @@
84 "net/mail"
85 "net/url"
86 "os"
87+ "regexp"
88 "sort"
89+ "strings"
90 "time"
91
92 "log"
93@@ -37,8 +39,10 @@
94 const (
95 APP_ID = "com.ubuntu.developer.webapps.webapp-gmail_webapp-gmail"
96 gmailDispatchUrl = "https://mail.google.com/mail/mu/mp/#cv/priority/^smartlabel_%s/%s"
97- // this means 3 individual messages + 1 bundled notification.
98- individualNotificationsLimit = 2
99+ // If there's more than 10 emails in one batch, we don't show 10 notification
100+ // bubbles, but instead show one summary. We always show all notifications in the
101+ // indicator.
102+ individualNotificationsLimit = 10
103 pluginName = "gmail"
104 )
105
106@@ -52,6 +56,9 @@
107 // trackDelta defines how old messages can be before removed from tracking
108 var trackDelta = time.Duration(time.Hour * 24 * 7)
109
110+// regexp for identifying non-ascii characters
111+var nonAsciiChars, _ = regexp.Compile("[^\x00-\x7F]")
112+
113 type GmailPlugin struct {
114 // reportedIds holds the messages that have already been notified. This
115 // approach is taken against timestamps as it avoids needing to call
116@@ -154,12 +161,34 @@
117 from := hdr[hdrFROM]
118 var avatarPath string
119
120- if emailAddress, err := mail.ParseAddress(hdr[hdrFROM]); err == nil {
121- if emailAddress.Name != "" {
122- from = emailAddress.Name
123- avatarPath = qtcontact.GetAvatar(emailAddress.Address)
124- }
125- }
126+ emailAddress, err := mail.ParseAddress(from)
127+ if err != nil {
128+ // If the email address contains non-ascii characters, we get an
129+ // error so we're going to try again, this time mangling the name
130+ // by removing all non-ascii characters. We only care about the email
131+ // address here anyway.
132+ // XXX: We can't check the error message due to [1]: the error
133+ // message is different in go < 1.3 and > 1.5.
134+ // [1] https://github.com/golang/go/issues/12492
135+ mangledAddr := nonAsciiChars.ReplaceAllString(from, "")
136+ mangledEmail, _ := mail.ParseAddress(mangledAddr)
137+ if err != nil {
138+ emailAddress = mangledEmail
139+ }
140+ } else {
141+ from = emailAddress.Name
142+ }
143+
144+ if emailAddress != nil {
145+ avatarPath = qtcontact.GetAvatar(emailAddress.Address)
146+ // If icon path starts with a path separator, assume local file path,
147+ // encode it and prepend file scheme defined in RFC 1738.
148+ if strings.HasPrefix(avatarPath, string(os.PathSeparator)) {
149+ avatarPath = url.QueryEscape(avatarPath)
150+ avatarPath = "file://" + avatarPath
151+ }
152+ }
153+
154 msgStamp := hdr.getTimestamp()
155
156 if _, ok := pushMsgMap[msg.ThreadId]; ok {
157@@ -186,12 +215,14 @@
158
159 }
160 func (p *GmailPlugin) handleOverflow(pushMsg []*plugins.PushMessage) *plugins.PushMessage {
161- // TRANSLATORS: This represents a notification summary about more unread emails
162- summary := gettext.Gettext("More unread emails available")
163 // TODO it would probably be better to grab the estimate that google returns in the message list.
164 approxUnreadMessages := len(pushMsg)
165- // TRANSLATORS: the first %d refers to approximate additional email message count
166- body := fmt.Sprintf(gettext.Gettext("You have about %d more unread messages"), approxUnreadMessages)
167+
168+ // TRANSLATORS: the %d refers to the number of new email messages.
169+ summary := fmt.Sprintf(gettext.Gettext("You have %d new messages"), approxUnreadMessages)
170+
171+ body := ""
172+
173 // fmt with label personal and no threadId
174 action := fmt.Sprintf(gmailDispatchUrl, "personal")
175 epoch := time.Now().Unix()

Subscribers

People subscribed via source and target branches