# Color in header based on section name

I'm trying to swich color in the header based on what will be typeset in the header (\rightmark or \lastrightmark), but I just can't get it work, the comparison fails everytime. I tried it first with \ifthenelse but I saw that it's obsolete, so I loaded the package etoolbox and tried it with \ifdefstring without success. I also saw that if I typeout the argument I'm passing to my command, it is not the actual section name but some commands will be built around it and the non ascii characters will be converted to LaTeX Internal Character Representation. So I tried the comparison with that what \typeout logged, but still no success. Is it somehow possible to do this? MWE:

\documentclass[twoside,a5paper]{book}

\usepackage[ngerman]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[usenames]{xcolor}
\usepackage{extramarks}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{fancyhdr}

\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\setcounter{secnumdepth}{-1}

\definecolor{testColor}{HTML}{BF4046}
\definecolor{secColor}{HTML}{46BF40}

\newcommand{\currentColor}{testColor}

\newcommand{\getCurrentColor}[1]{%
\ifthenelse{\equal{#1}{Öffentlich}}{\renewcommand{\currentColor}{secColor}}{}%
\ifdefstring{#1}{Öffentlich}{\renewcommand{\currentColor}{secColor}}{}
\ifdefstring{#1}{\foreignlanguage{ngerman}{\bbl@restore@actives\MakeUppercase {\IeC {\"O}ffentlich}}}{\renewcommand{\currentColor}{secColor}}{}
}

\ifthenelse{\equal{#1}{left}}{
\getCurrentColor{\rightmark}%
\colorbox{\currentColor}{\rightmark}
}{
\getCurrentColor{\lastrightmark}%
\colorbox{\currentColor}{\lastrightmark}
}
}

\pagestyle{fancy}

\begin{document}

\section{TestSection}
blabla
\clearpage
\section{Öffentlich}
blabla
\clearpage
\section{TestSection2}
blabla

\end{document}


the packages have added a lot of stuff to the marks to complicate the tests but you can discard all that so:

\documentclass[twoside,a5paper]{book}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{extramarks}
\usepackage[T1]{fontenc}
\usepackage[usenames]{xcolor}

\usepackage{fancyhdr}

\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\setcounter{secnumdepth}{-1}

\definecolor{testColor}{HTML}{BF4046}
\definecolor{secColor}{HTML}{46BF40}

\newcommand{\currentColor}{testColor}

\newcommand{\getCurrentColor}[1]{%
\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter
\expandafter\zz#1\nil% set \z to current section name
\ifx\z\Offentlichtest \renewcommand{\currentColor}{secColor}\fi
\ifx\z\Tonetest       \renewcommand{\currentColor}{testColor}\fi
\ifx\z\Ttwotest       \renewcommand{\currentColor}{red}\fi
}
\def\zz#1#2#3#4#5\nil{\zzz#4\nil}
\def\zzz#1#2#3#4#5\nil{\def\z{#5}}

\def\Offentlichtest{\IeC {\"O}ffentlich}
\def\Tonetest{TestSection}
\def\Ttwotest{TestSection2}

\ifx\left#1%
\getCurrentColor{\rightmark}%
\colorbox{\currentColor}{\rightmark}%
\else
\getCurrentColor{\lastrightmark}%
\colorbox{\currentColor}{\lastrightmark}%
\fi
}

\pagestyle{fancy}

\begin{document}

\section{TestSection}
blabla
\clearpage
\section{Öffentlich}
blabla
\clearpage
\section{TestSection2}
blabla

\end{document}