Is it okay to contact a professor for collaboration and say the goal is to publish? Say I'm in sitting in a research-type course and I like one of the ideas the lecturer talks about. I also have an idea for a nice research topic/application that I believe we can work on together.

Is it polite to just send him an email and say that I have this or that idea, and ask directly what he thinks about being able to publish it (is it a good enough idea)?

I'm a graduate student with some published papers, and overall I think that given the correct idea I could write a paper and get it published. But it still seems to me a little pretentious to just contact someone and ask directly if some idea I have is 'publishable'... on the other hand, I don't really want to work on some project that is not good enough for publication, so I would want his honest opinion regarding the prospects. 

Of course, I would accept an answer such as 'maybe, I don't have enough information', but my main question here is if it's not too rude to ask about publication directly.

Thanks
(This answer builds on @Alexandros's comment.)  As I understand it, one of the principal merits of having "physical" courses and lectures -- I mean, both the lecturer and the attendees are affiliated with the same university in the same geographic location, and they all show up in a certain room at a certain agreed upon time -- in our technologically advanced age is to facilitate "analog" interactions of all kinds between the lecturer and the attendees.  Sending a proposal via email seems to squander the advantage of your physical proximity to the lecturer.

I would suggest simply asking to talk to the lecturer in person about the project you propose.  You can ask either in person or by email, whatever seems best or quickest.  In my opinion, the fact that you are "sitting in" on the course rather than (presumably) formally enrolled in it just means that you should be understanding that the students enrolled in the course should have priority in any scheduled office hours.  Assuming you're affiliated with the university in some way, I don't see why you should feel hesitant to contact the lecturer (as I said above).  By the way, most academics are very interested to talk further about topics related to their research-level courses: more often than not, they are more interested in that than all other kinds of student interaction.

In terms of the publication issue: YMMV, but I personally would not lead with that.  My motivations for collaborating with others are: (i) learning more about a subject of interest, (ii) answering interesting questions, (iii) writing up what we learned / did in a way that will be helpful to others, and so forth.  This is nicely aligned with wanting to publish papers, but that's not what I said and that is not my precise motivation.  To me, having a student mention "publication" in the first meeting would turn me off a bit as being overly mercenary and insufficiently intellectually curious.  But that is my personal perspective and also my perspective as a pure mathematician.  Still, I think that most academics need to be grabbed by the intellectual / academic aspects of your proposal in order to proceed with it, so I would expect most of the first meeting to concentrate on those.  If you don't interest the faculty member, there might not be a second meeting.  

Conversely, if you meet several times with the faculty member to work on something, then he is interested enough to spend time on it, which is highly correlated with it being publishable.  In any event, I think there are no guarantees for this kind of thing: you never know whether something will be publishable until you do it and try to publish it, of course.