Wednesday, September 30, 2015

Thunderbird setup to work like Outlook

1. Categories

Coloring is done base on Thunderbird Tags. To sync tags from Zimbra to local Thunderbir just create the same name tag and color in Zimbra and Thunderbird and update remote filters to mark by tags on Zimbra only. 
      To make zimbra tags displayed in Thunderbird, just name is with the same names as in your /home/USER/.thunderbird/xxxxxx.default/prefs.js file. 
user_pref("mailnews.tags.urgentmails.color", "#FF0000");
user_pref("mailnews.tags.urgentmails.tag", "urgentmails");
2. Remove blockquoters/ Getting rid of colored quote bars...
File: create file if not exist "~/.thunderbird/XXXXXXX.default/chrome/userContent.css"
blockquote[type=cite] {
  padding-bottom: 0 !important;
  padding-top: 0 !important;
  padding-left: 0 !important;
  border-left: none !important;
  border-right: none !important;
}
3. Read status
Menu Edit/Preferences , tab Advanced/Reading & Display. Uncheck "Automatically mark message as read".
Thunderbird Tags are located at /home/USER/.thunderbird/xxxxxx.default/prefs.js , example:
user_pref("mailnews.tags.deploy.color", "#FF0000");
user_pref("mailnews.tags.deploy.tag", "deploy");
4. Set Cursor position to top after Reply
Edit->Prefernces->Advanced->General, and click on "Config Editor".
mail.identity.default.reply_on_top = 1
5. No sorting by click over column name
Adjust in all folders: mail have to sorted by date - the most recent on top.
Disable change of sorting: This is useful then you have new mail at the top on the table, and occasional click harm sorting by date.

6. Reply format like in Outlook
Install SmartTemplate4 addon.
HTML Template for new Mail:
<font face="Verdana" style="font-size:14px">Hello ,
<br><br><br><br>
Thanks,<br>
XXXXX, XXXXX.</font>

HTML for reply:
<div style="font-family:Verdana; font-size:14px">
<hr>
<div><b>From:</b> %from%</div>
<div><b>Sent:</b>%X:=sent% %A%, %B% %d%, %Y% %l%:%M%%p(3)%</div><div><b>To:</b> %to%</div>
<div><b>CC:</b> %cc%</div>
<div><b>Subject:</b> %subject%</div>
</div>
<br/>
  
<font face="Verdana" style="font-size:14px">Hello %from(name)%,
<br/><br/><br/><br/>
Thanks,<br/>
XXXXX XXXXXX.</font>

HTML Template forward:
<div style="font-family:Verdana; font-size:14px">
<hr>
<div><b>From:</b> %from%</div>
<div><b>Sent:</b> %date%</div>
<div><b>To:</b> %to%</div>
<div><b>CC:</b> %cc%</div>
<div><b>Subject:</b> %subject%</div>
</div>
<br/>
<font face="Verdana" style="font-size:14px">Hello ,
<br/><br/><br/><br/>
Thanks,<br/>
XXXXX XXXXXX.</font>
7. Spell checkers 
Menu Tools/Add-ons, search and install:
"United States English Dictionary"
"Russian spelling dictionary"

8. Calendar + Tasks
For version 3.0.8 Thunderbird (in Ubuntu 10.04) the old version of plugin is needed: to get it from Ubuntu repository or 
9. Google Calendar
Install Lightning addon first from Tool>Addons menu item. For 64 bit use this link.
10. MS Exchange Private Calendar
Addon "Exchange 2007/2010 Calendar and Tasks Provider" (I used "Version 3.2.0-Beta7" from "Other versions" for TB 17 - works fine):
https://addons.mozilla.org/en-US/thunderbird/addon/exchange-20072010-calendar-/?src=search
 Set up process:
Switch to calendar tab in Thunderbird. In the list of calendars do right click and select "New calendar", select "On the Network", select "Microsoft Exchange", and put into Location field
"https://DOMAIN\USERNAME@mail.YOURCOMPANY.com/EWS/Exchange.asmx". Please replace "rivanov" with your account name.

11. Update Inbox sub-folders during Imap sync
mail that are moved by MS exchange to subfolders by Exchange filters are not downloaded to Thunderbird automatically.
To resolve this:  Please look at attached image. There is Properties window of folder. Please check "When getting new messages .....".
Another way to automatically check for new messages in other folders: Under Tools > Options > Advanced, click the Config Editor button and setmail.server.default.check_all_folders_for_new to true



12. Activate Quick Filter Bar
Activate it in main Menu: View - Toolbar - Quick Filter Bar
13. For advanced mail filtering at server side
There is no ability to Exchange to let Thunderbird show mail with Star or Tag - I found only one way is by Priority of mail.
To show priority column as image in Thunderbird install addon "Enhanced Priority Display", and adjust filter at OWA to change priority as required. On Thunderbird you need show priority column manually.
For example, It can be applied for error messages from Jenkins, that contains your name.

14. To apply filters to mails in sub-folders
To make filtering works for subfolders: create a new string preference "mail.server.default.applyIncomingFilters" to "true". Even if it seems odd, do NOT create a boolean setting, it has to be a STRING setting with the value "true".
But note, that you should setup your filters in a special way: the most greedy filters should be placed under the less greedy ones.
Example: 'All Git messages' filter (which is used to move GIT msgs to 'GIT' folder) is more greedy than filters for Git messages coloring, so filters for coloring should be placed upper than 'All Git messages' filter:


15. Send messages in HTML only
Go to Edit > Preferences > Composition > Send Options... > Text Format and select 'Send message in HTML anyway'

16. Open links in non default browser
It useful sometimes to separate some pages and general search tabs in different browsers, Thunderbird have ability to ask how to open links from mails with dialog "Open with".
set in Edit > Preferences> Advanced tab > "Configure Editor" (source of wizdom)
network.protocol-handler.warn-external.https = true
17. 'Colored Diff' for ease view of code changes mails at git.

18. Highlighted Java code just like in your code editor.

19. Change order of the accounts.
user_pref("mail.accountmanager.accounts"...
user_pref("mail.accountmanager.defaultaccount", "account4"); <--- First should be default

20. 24h time format
Append to the file ~/.profile follow string:
export LC_TIME=ru_RU.utf8
Restart your computer or lightdm.

Saturday, June 13, 2015

Example of Cyclomatic complexity analysis over real projects

Processed by:
1) launch of https://github.com/checkstyle/contribution/tree/master/checkstyle-tester generate HTML report

2) html2text target/site/index.html | grep "Cyclomatic Complexity is" | cut -d' ' -f7 | sort | uniq --count | sort -h -k 2

3) % is calculated as "=TRUNC(((B2)/B$47)*100)"

So amount of methods the complicated then 10 (from all method that complicated than 5) in the project is about 5%.  Below is tables for: Checkstyle , Spring Framework, Open JDK 7.

Checkstyle 6.7 Cynclomatic complexity analysis:

               CC           Count                  %
5 130 15
6 83 12
7 66 9
8 52 10
9 53 4
10 22 4
11 23 4
12 25 1
13 7 0
14 3 1
15 8 0
16 4 0
17 2 0
18 5 1
19 10 0
20 1 2
21 13 0
22 1 0
23 5 0
24 1 0
27 1 0
29 1 0
30 1 0
32 1 0
34 2 0
44 2 0
47 2 0
81 1 100

Total: 525


Spring frameworks v4.1.6.RELEASE Cyclomatic complexity analysis:
               CC           Count                 %
5 746 30
6 450 18
7 312 12
8 215 8
9 157 6
10 109 4
11 80 3
12 55 2
13 52 2
14 34 1
15 33 1
16 25 1
17 18 0
18 19 0
19 14 0
20 17 0
21 11 0
22 8 0
23 9 0
24 6 0
25 7 0
26 11 0
27 1 0
28 2 0
29 1 0
31 3 0
32 2 0
33 5 0
34 3 0
35 2 0
36 3 0
37 1 0
38 1 0
40 2 0
41 1 0
44 1 0
47 1 0
48 1 0
50 2 0
55 1 0
60 1 0
61 1 0
81 2 0
127 1 0
184 1 0

Total:2427

OpenJdk7 Cyclomatic complexity analysis: 

               CC           Count                 %
5 4650 25
6 2947 16
7 2234 12
8 1542 8
9 1161 6
10 932 5
11 706 3
12 574 3
13 505 2
14 383 2
15 332 1
16 261 1
17 230 1
18 200 1
19 183 1
20 128 0
21 119 0
22 121 0
23 102 0
24 78 0
25 58 0
26 60 0
27 57 0
28 47 0
29 30 0
30 29 0
31 27 0
32 30 0
33 22 0
34 30 0
35 11 0
36 19 0
37 27 0
38 12 0
39 17 0
40 10 0
41 16 0
42 12 0
43 11 0
44 14 0
45 6 0
46 11 0
47 14 0
48 9 0
49 7 0
50 12 0
51 11 0
52 6 0
53 6 0
54 8 0
55 6 0
56 5 0
57 2 0
58 4 0
59 1 0
60 3 0
62 6 0
63 3 0
64 4 0
66 4 0
67 6 0
68 2 0
69 1 0
70 2 0
71 1 0
72 2 0
73 3 0
74 7 0
75 4 0
76 3 0
77 3 0
78 2 0
79 1 0
80 4 0
81 1 0
82 5 0
83 1 0
85 1 0
86 2 0
87 1 0
88 3 0
93 2 0
95 3 0
96 1 0
97 1 0
100 1 0
101 1 0
103 1 0
109 1 0
110 1 0
111 1 0
121 1 0
124 1 0
125 1 0
130 2 0
140 1 0
145 1 0
149 1 0
164 1 0
186 1 0
219 1 0
256 1 0
281 1 0

Total:18136

Understanding of Cyclomatic Complexity for measuring code quality

But does that mean a program with a high Cyclomatic Complexity (CC) has a bad quality ? For sure not !

It is just another metrics and some people think it is better to use Line numbers instead as more simple and more robust metric. Very good paper  - http://www.leshatton.org/Documents/TAIC2008-29-08-2008.pdf#17 (page 17) , see also Conclusion - page 45.

It is common when people say " ... reducing the cyclomatic complexity of the code can help reducing the number of test cases ... " - that is not always true!!
Blind following of Cyclomatic metric will lead you to code that have a lot of small methods that will be hard to maintain as encapsulation might be damaged. It is not a rare case there you should put ignore to some case where complexity is high as you defined for the rest of the project.
To keep all that logic(even a bit complicated) in one method to not let other methods use it and what is more problematic change them to their needs. Not everything should be decomposed to smaller parts.
Finally if your complicated method is "public" and you will decompose it internals for several "private" method - you will not reduce amount of tests !!! as in tests you will still check your public method with all possible values in arguments.

The main point of CC is to measure complexity to measure amount of tests, so it suppose to be used as (from wiki) :
 branch coverage \leq cyclomatic complexity \leq number of paths

from wiki:
McCabe showed that the cyclomatic complexity of any structured program with only one entrance point and one exit point is equal to the number of decision points (π) (i.e., "if" statements or conditional loops) contained in that program plus one. However, this is true only for decision points counted at the lowest, machine-level instructions. Decisions involving compound predicates like those found in high-level languages like IF cond1 AND cond2 THEN ... should be counted in terms of predicate variables involved, i.e. in this examples one should count two decision points, because at machine level it is equivalent to  IF cond1 THEN IF cond2 THEN ... 
Cyclomatic complexity may be extended to a program with multiple exit points; in this case it is equal to:
π − s + 2, 
where π is the number of decision points in the program, and s is the number of exit points

So amount of decision point is good measure of complexity ,  but as you can see in definition it could be reduced by adding more exit points. That is true for amount of test calculation  but that is not true to measure of code quality and readability.
So "multi exits/returns" could be a incentive for engineers to calm down Checkstyle or PMD . But that conflict with best practice to have one entry and one exit point in method.

Conclusion: Cyclomatic Complexity is for measuring of Tests amount and NOT about code quality. But CC could be used as quality measure with custom to project level/threshold selection. Do not be ashamed to have complexity level 15 or even more, but keep it below 20 to catch really bad designed code automatically.

I highly recommend to read https://www.cqse.eu/en/blog/mccabe-cyclomatic-complexity/ to see on code examples how weird complexity calculation could be.

Checkstyle's HTML documentation was updated for this metric: http://checkstyle.sourceforge.net/config_metrics.html#CyclomaticComplexity

I updated Chekstyle code to follow level less then 11, I can confirm that about 54 cases were real ugly and messy code and it  was good that that metrics is pointed to that code. But in non library code level 11 is too demanding but reachable, 15 is ok.

Example of Cyclomatic complexity calculation over code base of Checkstyle, Spring, OpenJDK.

Sources:
https://en.wikipedia.org/wiki/Cyclomatic_complexity (especially links to external and other ref)
http://damienlepage.com/cyclomatic-complexity/
http://www.sonarqube.org/discussing-cyclomatic-complexity/


Wednesday, June 10, 2015

Sync tags from Zimbra to Thunderbird

To Sync tags from Zimbra to Thunderbird please make sure that your tags are named exactly as it on Zimbra (manual sync).
If you rename a tag please update ~/.thunderbird/rnwdyrj0.default/prefs.js file manually.

incorrect variant (after successful renaming "work" to "todo" in Thunderbird):

user_pref("mailnews.tags.work.color", "#3333FF");
user_pref("mailnews.tags.work.tag", "todo");

incorrect variant :

user_pref("mailnews.tags.todo.color", "#3333FF");
user_pref("mailnews.tags.todo.tag", "todo");