All files / Scripts/row ArchivedRow.ts

100% Statements 16/16
83.33% Branches 5/6
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 304x 4x     4x   47x       8x 8x 7x 7x 2x 2x 2x 2x 2x 2x 2x             6x    
import { Strings } from "../Strings";
import { SummaryRow } from "./SummaryRow";
 
// Handle the "Archived-At" header per https://tools.ietf.org/html/rfc5064
export class ArchivedRow extends SummaryRow {
    constructor(header: string, label: string) {
        super(header, label);
    }
    // Return the URL for the archived message, or the encoded value if it's not a valid URL.
    override get valueUrl(): string {
        const match = this.valueInternal.match(/^\s*<([^>]+)>\s*$/);
        if (match?.[1]) {
            try {
                const url = new URL(match[1]);
                Eif (url.protocol === "http:" || url.protocol === "https:") {
                    const a = document.createElement("a");
                    a.href = url.href;
                    a.target = "_blank";
                    a.rel = "noopener noreferrer";
                    a.textContent = url.href;
                    return a.outerHTML;
                }
            } catch {
                // Fall through to encoded output.
            }
        }
 
        return Strings.htmlEncode(this.valueInternal);
    }
}