I have a package of my own loaded when a certain option is passed to a class of my own (based in turn on the memoir class). The package is devised for typesetting letters. Except for the body of the letter itself, everything is defined in the class, in the package, and in the document's preamble -- in the latter, it is in terms of key=value syntax. I have the following code in the package:
\AtBeginDocument{%%
\pagestyle{UVLetterHdrs}% Page headers
\putUVHeading% Just a macro to type some preliminary stuff
\vspace*{3\baselineskip}\par\noindent%
Salutation,\ignorespaces% A literal string (no unwanted space appears here)
\par\vspace*{\baselineskip}\noindent\ignorespaces\relax%%
}%%
% From atbeginend package
\BeforeBegin{document}{\ignorespaces\relax}% A couple of desperate attempts
\AfterBegin{document}{\ignorespaces\relax}%
Then, in the document's file, after setting the corresponding keys, I have the lines
\begin{document}
% The problem appears here but it disappears if I add "%"
% right after the environment's starting command.
Text of the letter.
\end{document}
My issue is that, while I don't have any unwanted horizontal space before the starting line Salutation,, there is a small horizontal space before Text of the letter. This space is removed if I type a comment mark % immediately after \begin{document}.
I have tried everything that has come to my mind regarding possible spurious spaces: I have ended each and every line (literally all of them) in the class and the package files with % (which is why you can see double percentage marks in the above code excerpts), and I've tried using \ignorespaces and \relaxes beyond reason, as you may see there, too. Besides, the space appears not before the "salutation" line, but right after whatever it is that follows the \begin{document}, so the problem seems to be located in that code area.
I'm sorry I cannot provide an MWE; the class and the package codes are too long for that. I understand that this is a big hindrance, but if somebody comes up at least with some idea of what may be going on, that'd be much appreciated.
EDIT:
After the comments and the answer by lockstep, I tried moving the code from \AtBeginDocument to the environment's body; that is to say, after the preamble, my document's master .tex file reads:
\begin{document}
\pagestyle{UVLetterHdrs}
\putUVHeading
\vspace*{3\baselineskip}\par\noindent
Salutation,
\par\vspace*{\baselineskip}\noindent
Text of the letter.
\end{document}
The unwanted space dissapeared and everything worked fine. I have also started the contents of this environment with the literal string Salutation, and the space appeared there. By the way, this is not an indentation space. The problem is definitely related with the \AtBeginDocument command, but I haven't been able to find out what it is about. Any suggestions would be welcome.

\AtBeginDocumentthere are two instances of\noindent, to avoid having the salutation spaced over to the right. you can precede your first sentence by\noindent, or if you want no indentation anywhere in the document, you can\setlength{\parindent}{0pt}in the preamble. in that case you should also use vertical space between paragraphs; the easiest way to do this is to use theparskippackage. – barbara beeton Aug 10 '13 at 12:150.5 emin the\normalfontand\normalsize, only maybe a bit larger. The document's\parindentis larger than that space. I appreciate your suggestion, though, given I've got no MWE to offer for guidance. I thought that maybe the indentation in my code could make for a reason, but since I've got each and every end of line commented, I understand that's not it. – Marcos Aug 10 '13 at 19:05\relaxafter\ignorespacesin several places. that's one place where you definitely do not wans\relax-- it nullifies the action of\ignorespaces. try getting rid of it, and see what you get. since you say the space is about.5em, that's close to a word space, so it's the "right size". – barbara beeton Aug 10 '13 at 19:11%mark right after\begin{document}removes the unwanted space -- though a way out, this is not a satisfying solution, of course. – Marcos Aug 10 '13 at 19:27\@afterindentfalse\@afterheadingis macro that suppress indentation. So I think @barbarabeeton is right. Have you tried\setlength{\parindent}{0pt}to see if the space had gone? – Francis Aug 10 '13 at 20:22\showoutputin the body and then compare the log file generated by the code with and without space and see if you can dig up anything. In my failed attempt the only notable thing I found is a difference of15pt, which is the length of\parindent. – Francis Aug 11 '13 at 22:40