President Donald Trump is clearly not a fan of Amazon. He attacked the company via Twitter five times in the last week. One of his main contentions is that Amazon is ripping off the U.S. Postal Service, but it's not clear whether it is getting the short end of the stick from the Jeff Bezos-led retailing juggernaut. In fact, Amazon may be saving the post office from financial ruin. On April 3, Trump said, "the post office is losing billions of dollars," at U.S. taxpayers' expense. It's true that the post office is losing money. It reported a $2.7 billion net loss in 2017. But the post office is not funded by U.S. tax dollars. And when you look at the revenue breakdown, you can see that shipping and packages is actually one of the few categories that brought in more money than the previous year. While overall revenue fell $1.8 billion, shipping and packages saw a $2.1 billion increase in revenue. Meanwhile, first-class mail revenue was down around $1.8 billion.

USPS 2017 Fiscal Report CNBC | Kyle Walsh

And the post office was in the red long before Amazon became such an online giant. The USPS began to lose money in the early 2000s with the internet's rise. But one of the post office's biggest revenue drainers has nothing to do with shipments, or the Internet. It's all about employee benefits. Back in 2006, Congress enacted a law that required the USPS to prefund its employee health benefits for the next 75 years. And that has cost the post office billions. In a note to clients on Tuesday, Baird Equity Research said that any large customer, including Amazon, would actually help the post office subsidize its pension costs.

A United States Postal Service (USPS) letter carrier delivers mail in Shelbyville, Kentucky. Luke Sharrett | Bloomberg | Getty Images

In October 2013, Amazon struck a five-year deal with the post office. The specific terms of the contract aren't available to the public because the post office's deals with private shippers are considered proprietary. That means there's a decent amount of information we don't know. But one thing we do know is that the post office is making a profit. In 2006, Congress ruled that the USPS couldn't set its prices lower than its costs, otherwise it would be able to unfairly charge less than its competitors like UPS and FedEx. Every year, an independent agency called the Postal Regulatory Commission makes sure the USPS' deals make economic sense. And year after year, the commission has approved the deal with Amazon. In its 2017 annual report, the USPS even said its shipping and packages business helped the "financial picture of the Postal Service." Trump is right that Amazon does technically receive a discount. Amazon ships a lot of packages, so chances are it's utilizing a bulk discount. But that's not specific to Amazon; it's available to other businesses, too.

Inventory at a warehouse Getty Images

That idea that the post office is losing big likely stems from a Citigroup report. The report alleges the USPS' pricing model is unsustainable, and that parcel rates would need to rise significantly for the agency to break even. The report was mentioned in a widely circulated Wall Street Journal commentary by shipping analyst Josh Sandbulte. The analyst argues that the post office is essentially giving Amazon a $1.46 subsidy for every box it ships. But if true, that figure would hold for all companies across the board, not just Amazon. Which is probably where Trump is coming up with the claim that the post office "will lose $1.50 on average for each package it delivers for Amazon." TWEET However, the $1.46 figure has been debated. On Tuesday, the Citigroup analyst who wrote the original report clarified that Amazon's business could be profitable for the USPS. The Postal Service does receive reimbursements for some things mandated by Congress, like free mail for the blind and overseas voting. And it borrows money from the government to pay for its employee health benefits. But most analysts seem to agree that the post office isn't losing a fortune to Amazon. The USPS declined to comment on this story. The commission did not return CNBC's request for comment.

Jeff Bezos David Ryder | Getty Images