A general theory of the micromaser is described. The model is based on treating the input atomic beam as a two-component quantum field so that the two-level atoms in the beam are ''quanta'' of this field. This approach makes it possible to formulate a general quantum Langevin description of the dynamics with the input atomic field as a source of quantum noise. The passage to a master-equation description is then effected by use of an adjoint-operator method, and by introducing a general class of statistical states for the atomic beam known as generalized shot noise. The result is a (non-Markovian) master equation for the field inside the cavity which is valid for a broad range of statistical properties of the input atomic beam. The approximate steady-state solutions to this master equation for the photon statistics of the cavity field for sub-Poissonian (antibunched) atomic beams found by other researchers are regained. The theory is then extended to treat super-Poissonian (bunched) atomic beams. An exact result is found in the limit of a strongly bunched beam in which the cavity-field state is shown to converge to a mixture of a thermal-field state and the state produced by a random beam of twice the intensity. A physical explanation of this result is also presented.