Merge pull request #4993 from k9mail/display_headers_in_order
Display message headers in the original order
This commit is contained in:
commit
7a65210199
5 changed files with 19 additions and 38 deletions
|
@ -2,10 +2,7 @@ package com.fsck.k9.view;
|
|||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
|
@ -41,6 +38,7 @@ import com.fsck.k9.helper.Contacts;
|
|||
import com.fsck.k9.helper.MessageHelper;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Header;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import com.fsck.k9.ui.ContactBadge;
|
||||
|
@ -85,19 +83,6 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
private OnCryptoClickListener onCryptoClickListener;
|
||||
private OnMenuItemClickListener onMenuItemClickListener;
|
||||
|
||||
/**
|
||||
* Pair class is only available since API Level 5, so we need
|
||||
* this helper class unfortunately
|
||||
*/
|
||||
private static class HeaderEntry {
|
||||
public String label;
|
||||
public String value;
|
||||
|
||||
public HeaderEntry(String label, String value) {
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MessageHeader(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
@ -248,7 +233,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
Integer messageToShow = null;
|
||||
try {
|
||||
// Retrieve additional headers
|
||||
List<HeaderEntry> additionalHeaders = getAdditionalHeaders(mMessage);
|
||||
List<Header> additionalHeaders = mMessage.getHeaders();
|
||||
if (!additionalHeaders.isEmpty()) {
|
||||
// Show the additional headers that we have got.
|
||||
populateAdditionalHeadersView(additionalHeaders);
|
||||
|
@ -422,19 +407,6 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
}
|
||||
}
|
||||
|
||||
private List<HeaderEntry> getAdditionalHeaders(final Message message) {
|
||||
List<HeaderEntry> additionalHeaders = new LinkedList<>();
|
||||
|
||||
Set<String> headerNames = new LinkedHashSet<>(message.getHeaderNames());
|
||||
for (String headerName : headerNames) {
|
||||
String[] headerValues = message.getHeader(headerName);
|
||||
for (String headerValue : headerValues) {
|
||||
additionalHeaders.add(new HeaderEntry(headerName, headerValue));
|
||||
}
|
||||
}
|
||||
return additionalHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the additional headers text view with the supplied header data.
|
||||
*
|
||||
|
@ -445,20 +417,20 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
* This method is always called from within the UI thread by
|
||||
* {@link #showAdditionalHeaders()}.
|
||||
*/
|
||||
private void populateAdditionalHeadersView(final List<HeaderEntry> additionalHeaders) {
|
||||
private void populateAdditionalHeadersView(final List<Header> additionalHeaders) {
|
||||
SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
boolean first = true;
|
||||
for (HeaderEntry additionalHeader : additionalHeaders) {
|
||||
for (Header additionalHeader : additionalHeaders) {
|
||||
if (!first) {
|
||||
sb.append("\n");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
|
||||
SpannableString label = new SpannableString(additionalHeader.label + ": ");
|
||||
SpannableString label = new SpannableString(additionalHeader.getName() + ": ");
|
||||
label.setSpan(boldSpan, 0, label.length(), 0);
|
||||
sb.append(label);
|
||||
sb.append(MimeUtility.unfoldAndDecode(additionalHeader.value));
|
||||
sb.append(MimeUtility.unfoldAndDecode(additionalHeader.getValue()));
|
||||
}
|
||||
mAdditionalHeadersView.setText(sb);
|
||||
}
|
||||
|
|
3
mail/common/src/main/java/com/fsck/k9/mail/Header.kt
Normal file
3
mail/common/src/main/java/com/fsck/k9/mail/Header.kt
Normal file
|
@ -0,0 +1,3 @@
|
|||
package com.fsck.k9.mail
|
||||
|
||||
data class Header(val name: String, val value: String)
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -101,7 +102,7 @@ public abstract class Message implements Part, Body {
|
|||
@Override
|
||||
public abstract String[] getHeader(String name);
|
||||
|
||||
public abstract Set<String> getHeaderNames();
|
||||
public abstract List<Header> getHeaders();
|
||||
|
||||
@Override
|
||||
public abstract void removeHeader(String name);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.fsck.k9.mail.internet
|
||||
|
||||
import com.fsck.k9.mail.Header
|
||||
import com.fsck.k9.mail.internet.MimeHeader.Field.NameValueField
|
||||
import com.fsck.k9.mail.internet.MimeHeader.Field.RawField
|
||||
import java.io.IOException
|
||||
|
@ -13,6 +14,9 @@ class MimeHeader {
|
|||
val headerNames: Set<String>
|
||||
get() = fields.mapTo(LinkedHashSet()) { it.name }
|
||||
|
||||
val headers: List<Header>
|
||||
get() = fields.map { Header(it.name, it.value) }
|
||||
|
||||
fun clear() {
|
||||
fields.clear()
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import java.io.OutputStreamWriter;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -22,6 +22,7 @@ import com.fsck.k9.mail.Body;
|
|||
import com.fsck.k9.mail.BodyFactory;
|
||||
import com.fsck.k9.mail.BodyPart;
|
||||
import com.fsck.k9.mail.DefaultBodyFactory;
|
||||
import com.fsck.k9.mail.Header;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.MimeType;
|
||||
|
@ -432,8 +433,8 @@ public class MimeMessage extends Message {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getHeaderNames() {
|
||||
return mHeader.getHeaderNames();
|
||||
public List<Header> getHeaders() {
|
||||
return mHeader.getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue