No longer CC a user by default

Its annoying to CC a user on every change they make through the web
interface, if they performed the change then they know they did it
and don't need a carbon-copy cluttering up their inbox.

Add a user level preference setting to control whether or not we
should CC the user if we are sending an email on their behalf.
By default disable it, because this is a common complaint.

Bug: issue 311
Change-Id: I431cc0e5df34ef44114bf3e5c92c4f2d5e3f0354
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-07-13 11:25:11 -07:00
parent 8943adf8dc
commit 5a00b3161d
8 changed files with 94 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -118,6 +119,14 @@ abstract class EmailHeader {
list.add(addr);
}
void remove(java.lang.String email) {
for (Iterator<Address> i = list.iterator(); i.hasNext();) {
if (i.next().email.equals(email)) {
i.remove();
}
}
}
@Override
boolean isEmpty() {
return list.isEmpty();

View File

@@ -32,6 +32,7 @@ import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.WildProjectName;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.mail.EmailHeader.AddressList;
import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.patch.PatchListEntry;
@@ -52,6 +53,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -165,12 +167,37 @@ public abstract class OutgoingEmail {
format();
if (shouldSendMessage()) {
if (fromId != null) {
// If we are impersonating a user, make sure they receive a CC of
// this message so they can always review and audit what we sent
// on their behalf to others.
//
add(RecipientType.CC, fromId);
final Account fromUser = accountCache.get(fromId).getAccount();
if (fromUser.getGeneralPreferences().isCopySelfOnEmails()) {
// If we are impersonating a user, make sure they receive a CC of
// this message so they can always review and audit what we sent
// on their behalf to others.
//
add(RecipientType.CC, fromId);
} else if (rcptTo.remove(fromId)) {
// If they don't want a copy, but we queued one up anyway,
// drop them from the recipient lists.
//
if (rcptTo.isEmpty()) {
return;
}
final String fromEmail = fromUser.getPreferredEmail();
for (Iterator<Address> i = smtpRcptTo.iterator(); i.hasNext();) {
if (i.next().email.equals(fromEmail)) {
i.remove();
}
}
for (EmailHeader hdr : headers.values()) {
if (hdr instanceof AddressList) {
((AddressList) hdr).remove(fromEmail);
}
}
}
}
if (change != null) {
if (getChangeUrl() != null) {
openFooter();

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
private static final Class<? extends SchemaVersion> C = Schema_36.class;
private static final Class<? extends SchemaVersion> C = Schema_37.class;
public static class Module extends AbstractModule {
@Override

View File

@@ -0,0 +1,25 @@
// Copyright (C) 2010 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.schema;
import com.google.inject.Inject;
import com.google.inject.Provider;
public class Schema_37 extends SchemaVersion {
@Inject
Schema_37(Provider<Schema_36> prior) {
super(prior);
}
}