Why email part.body doesn't change?

this code doesn't work... why?
how can i add that head to that body?

head is the html text i want to add to p (a tmail object)

def injecthead(head,p)
      if p.multipart? then
        p.parts.each do |pa|
        if p.content_type=="text/html" then
          if p.body!=nil then
            if startbodytag!=nil then

              #i'm sure this code is worked but p.body doesn't change.
              #if i put altbody=p.body.insert(startbodytag+endbodytag+1,head),
              #altbody is the body i want, but if then i write p.body=altbody, p.body becames nil