public void setHeader ( String name , String value ) { // int pos = 0; // int crlfpos = 0; Pattern pattern = null ; if ( getHeaders ( name ) == null && value != null ) { // header value not found, append to end addHeader ( name , value ) ; } else { pattern = getHeaderRegex ( name ) ; Matcher matcher = pattern . matcher ( mMsgHeader ) ; if ( value == null ) { // delete header mMsgHeader = matcher . replaceAll ( "" ) ; } else { // replace header String newString = name + ": " + value + mLineDelimiter ; mMsgHeader = matcher . replaceAll ( Matcher . quoteReplacement ( newString ) ) ; } // set into hashtable replaceInternalHeaderFields ( name , value ) ; } }
Set a header name and value . If the name is not found it will be added . If the value is null the header will be removed .