Permalink
Browse files

Reviewed MAIL module code, made improvements (readability)

  • Loading branch information...
1 parent 6b22fa6 commit 93e9e8f7cbc4426b3a9a79c0f5a20144b481325e @dizzzz dizzzz committed Jul 9, 2014
@@ -271,9 +271,9 @@ private void prefetchMessages( Folder folder, Message[] msgList ) throws Messagi
FetchProfile fp = new FetchProfile();
fp.add( FetchProfile.Item.ENVELOPE );
- for( int i = 0; i < PREFETCH_HEADERS.length; i++ ) {
- fp.add( PREFETCH_HEADERS[i] );
- }
+ for (String PREFETCH_HEADERS : PREFETCH_HEADERS) {
+ fp.add(PREFETCH_HEADERS);
+ }
folder.fetch( msgList, fp );
}
@@ -337,84 +337,82 @@ private Sequence getMessageListAsXML( Sequence[] args, Sequence contextSequence
// Recipients
builder.startElement( new QName( "recipients", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
// To Recipients
- Address[] to = message.getRecipients( Message.RecipientType.TO );
- if( to != null ) {
- for( int j = 0; j < to.length; j++ ) {
- builder.startElement( new QName( "recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "to" );
- builder.characters( to[j].toString() );
- builder.endElement();
- }
+ Address[] toAddresses = message.getRecipients( Message.RecipientType.TO );
+ if( toAddresses != null ) {
+ for (Address to : toAddresses) {
+ builder.startElement( new QName( "recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "to" );
+ builder.characters(to.toString());
+ builder.endElement();
+ }
}
// cc Recipients
- Address[] cc = message.getRecipients( Message.RecipientType.CC );
- if( cc != null ) {
- for( int j = 0; j < cc.length; j++ ) {
- builder.startElement( new QName( "recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "cc" );
- builder.characters( cc[j].toString() );
- builder.endElement();
- }
+ Address[] ccAddresses = message.getRecipients( Message.RecipientType.CC );
+ if( ccAddresses != null ) {
+ for (Address ccAddress : ccAddresses) {
+ builder.startElement( new QName( "recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "cc" );
+ builder.characters(ccAddress.toString());
+ builder.endElement();
+ }
}
// bcc Recipients
Address[] bccAddresses = message.getRecipients( Message.RecipientType.BCC );
if( bccAddresses != null ) {
for (Address bccAddress : bccAddresses) {
- builder.startElement( new QName( "recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "bcc" );
+ builder.startElement( new QName( "recipient", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "bcc" );
builder.characters(bccAddress.toString());
- builder.endElement();
- }
+ builder.endElement();
+ }
}
builder.endElement();
// Flags
Flags flags = message.getFlags();
- Flags.Flag[] sf = flags.getSystemFlags();
- String[] uf = flags.getUserFlags();
+ Flags.Flag[] systemFlags = flags.getSystemFlags();
+ String[] userFlags = flags.getUserFlags();
- if( sf.length > 0 || uf.length > 0 ) {
+ if( systemFlags.length > 0 || userFlags.length > 0 ) {
builder.startElement( new QName( "flags", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- // System Flags
- for( int f = 0; f < sf.length; f++ ) {
- if( sf[f] == Flags.Flag.ANSWERED ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "answered" );
- builder.endElement();
- } else if( sf[f] == Flags.Flag.DELETED ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "deleted" );
- builder.endElement();
- } else if( sf[f] == Flags.Flag.DRAFT ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "draft" );
- builder.endElement();
- } else if( sf[f] == Flags.Flag.FLAGGED ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "flagged" );
- builder.endElement();
- } else if( sf[f] == Flags.Flag.RECENT ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "recent" );
- builder.endElement();
- } else if( sf[f] == Flags.Flag.SEEN ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "seen" );
- builder.endElement();
- }
- }
+ for (Flags.Flag systemFlag : systemFlags) {
+ if (systemFlag == Flags.Flag.ANSWERED) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "answered" );
+ builder.endElement();
+ } else if (systemFlag == Flags.Flag.DELETED) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "deleted" );
+ builder.endElement();
+ } else if (systemFlag == Flags.Flag.DRAFT) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "draft" );
+ builder.endElement();
+ } else if (systemFlag == Flags.Flag.FLAGGED) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "flagged" );
+ builder.endElement();
+ } else if (systemFlag == Flags.Flag.RECENT) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "recent" );
+ builder.endElement();
+ } else if (systemFlag == Flags.Flag.SEEN) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "seen" );
+ builder.endElement();
+ }
+ }
- // User Flags
- for( int f = 0; f < uf.length; f++ ) {
- builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
- builder.addAttribute( new QName( "type", null, null ), "user" );
- builder.addAttribute( new QName( "value", null, null ), uf[ f ] );
- builder.endElement();
- }
+ for (String userFlag : userFlags) {
+ builder.startElement( new QName( "flag", MailModule.NAMESPACE_URI, MailModule.PREFIX ), null );
+ builder.addAttribute( new QName( "type", null, null ), "user" );
+ builder.addAttribute(new QName( "value", null, null ), userFlag);
+ builder.endElement();
+ }
builder.endElement();
}
Oops, something went wrong.

0 comments on commit 93e9e8f

Please sign in to comment.